[libvirt-users] virsh dominfo does not show correct cpuTime

changqian zuo zuochangqian at gmail.com
Fri Jul 24 05:51:03 UTC 2015


Hi,

I am doing some domain resource monitoring work. I use

  cat /dev/urandom | md5sum

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:

CPU time: 8410960000000
CPU util: 99.8410609331%
CPU time: 8411970000000
CPU util: 100.843672381%
CPU time: 8412380000000
CPU util: 40.9336949531%
CPU time: 8412440000000
CPU util: 5.9899303915%
*CPU time: 8412440000000*
*CPU util: 0.0%*
CPU time: 8412490000000
CPU util: 4.99165856007%
*CPU time: 8412490000000*
*CPU util: 0.0%*
*CPU time: 8412490000000*
*CPU util: 0.0%*
CPU time: 8412570000000
CPU util: 7.987195515%
*CPU time: 8412570000000*
*CPU util: 0.0%*
CPU time: 8412590000000
CPU util: 1.99668576091%
CPU time: 8412670000000
CPU util: 7.98700539474%
CPU time: 8412720000000
CPU util: 4.99167281754%
CPU time: 8412780000000
CPU util: 5.98888552548%

Looking at those 0.0% lines. Strange, though the guest is running, cpuTime
does not increase. How can this happen? Any one helps? Thanks.

Host information:

- CentOS Linux release 7.0.1406 (Core)
- libvirt 1.2.8
- qemu-kvm-rhev 2.1.2

----- python script to capture cpu domain usage ----
import libvirt
import time

conn = libvirt.openReadOnly("qemu:///system")
dom = conn.lookupByName('cpu-test')
last_time = time.time()
last_cpu_time = dom.info()[4]

while True:
  time.sleep(1)
  this_time = time.time()
  dom_info = dom.info()

  print "CPU time: %s" % dom_info[4]
  print "CPU util: %s%%" % ((dom_info[4] - last_cpu_time) / ((this_time -
last_time) * 10000000))

  last_cpu_time = dom_info[4]
  last_time = this_time
----------------------------- end -----------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/libvirt-users/attachments/20150724/ee876754/attachment.htm>


More information about the libvirt-users mailing list