<div dir="ltr">I was getting vCPU use time outside of guest with libvirt-python API, and them calculate utilization with (cpuTime2 - cpuTime1) / (t2 - t1). I was not doing this inside the guest os.</div><div class="gmail_extra"><br><div class="gmail_quote">2015-07-24 15:09 GMT+08:00 2020human <span dir="ltr"><<a href="mailto:human2020@qq.com" target="_blank">human2020@qq.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>You <span style="line-height:1.5">calculate</span><span style="line-height:1.5"> is vCPU use time not </span><span style="line-height:1.5">utilization。</span></div><div><span style="line-height:1.5"><br></span></div><div>use_time/total_cpu_time  is <span style="line-height:1.5">utilization。</span></div><div><span style="color:rgb(72,72,72);font-size:12px;line-height:normal;white-space:pre-wrap;background-color:rgb(250,250,250)"><br></span></div><div><span style="color:rgb(72,72,72);font-size:12px;line-height:normal;white-space:pre-wrap;background-color:rgb(250,250,250)">total_cpu_time=`cat /proc/stat |sed -n '1p'|awk '{ print sum=$2+$3+$4+$5+$6+$7+$8+$9+$10}'`</span></div><div><span style="line-height:1.5"><br></span></div><div><div><br></div><div style="font-size:12px;font-family:Arial Narrow;padding:2px 0 2px 0">------------------ 原始邮件 ------------------</div><div style="font-size:12px;background:#efefef;padding:8px"><div><b>发件人:</b> "changqian zuo";<<a href="mailto:zuochangqian@gmail.com" target="_blank">zuochangqian@gmail.com</a>>;</div><div><b>发送时间:</b> 2015年7月24日(星期五) 中午1:51</div><div><b>收件人:</b> "libvirt-users"<<a href="mailto:libvirt-users@redhat.com" target="_blank">libvirt-users@redhat.com</a>>; </div><div></div><div><b>主题:</b> [libvirt-users] virsh dominfo does not show correct cpuTime</div></div><div><div class="h5"><div><br></div><div dir="ltr">Hi,<div><br></div><div>I am doing some domain resource monitoring work. I use</div><div><br></div><div>  cat /dev/urandom | md5sum</div><div><br></div><div>to simulate vCPU load and write a script to calculate vCPU utilization. It seems all good at the beginning. After I abort the ``cat ... md5sum`` command in domain, I see some strange data as below:</div><div><br></div><div><div>CPU time: 8410960000000</div><div>CPU util: 99.8410609331%</div><div>CPU time: 8411970000000</div><div>CPU util: 100.843672381%</div><div>CPU time: 8412380000000</div><div>CPU util: 40.9336949531%</div><div>CPU time: 8412440000000</div><div>CPU util: 5.9899303915%</div><div><b>CPU time: 8412440000000</b></div><div><b>CPU util: 0.0%</b></div><div>CPU time: 8412490000000</div><div>CPU util: 4.99165856007%</div><div><b>CPU time: 8412490000000</b></div><div><b>CPU util: 0.0%</b></div><div><b>CPU time: 8412490000000</b></div><div><b>CPU util: 0.0%</b></div><div>CPU time: 8412570000000</div><div>CPU util: 7.987195515%</div><div><b>CPU time: 8412570000000</b></div><div><b>CPU util: 0.0%</b></div><div>CPU time: 8412590000000</div><div>CPU util: 1.99668576091%</div><div>CPU time: 8412670000000</div><div>CPU util: 7.98700539474%</div><div>CPU time: 8412720000000</div><div>CPU util: 4.99167281754%</div><div>CPU time: 8412780000000</div><div>CPU util: 5.98888552548%</div></div><div><br></div><div>Looking at those 0.0% lines. Strange, though the guest is running, cpuTime does not increase. How can this happen? Any one helps? Thanks.</div><div><br></div><div>Host information:</div><div><br></div><div>- CentOS Linux release 7.0.1406 (Core)<br></div><div>- libvirt 1.2.8</div><div>- qemu-kvm-rhev 2.1.2</div><div><br></div><div>----- python script to capture cpu domain usage ----</div><div><div>import libvirt</div><div>import time</div><div><br></div><div>conn = libvirt.openReadOnly("qemu:///system")</div><div>dom = conn.lookupByName('cpu-test')</div><div>last_time = time.time()</div><div>last_cpu_time = <a href="http://dom.info" target="_blank">dom.info</a>()[4]</div><div><br></div><div>while True:</div><div>  time.sleep(1)</div><div>  this_time = time.time()</div><div>  dom_info = <a href="http://dom.info" target="_blank">dom.info</a>()</div><div><br></div><div>  print "CPU time: %s" % dom_info[4]</div><div>  print "CPU util: %s%%" % ((dom_info[4] - last_cpu_time) / ((this_time - last_time) * 10000000))</div><div><br></div><div>  last_cpu_time = dom_info[4]</div><div>  last_time = this_time</div></div><div>----------------------------- end -----------------------------</div><div><br></div><div><br></div></div></div></div></div></blockquote></div><br></div>