Zhihua Che
2012-Apr-16 11:37 UTC
[libvirt-users] What does cpu_time returned by virDomainGetCPUStats mean?
hi, everyone. I find an 'interesting' thing involving virDomainGetCPUStats(). I call it for cpu usage consumed by a domain and get a array of virTypedParameter. My system is 2-core and hyperviser return 1 parameter per cpu. So the contents of the array is like this. virTypedParameter[0] { .fiedl = "cpu_time" .type = 4 .value.ul = 51640610899 } virTypedParameter[1] { .field = "cpu_time" .type = 4 .value.ul = 55302820304 } I thought this value store the run time of the cpu since last boot. But I find I was wrong because this value would increase until it wraps down and doesn't reset even the domain is restarted. So, what does this value mean? How can I get the CPU usage of the domain? I found nothing on the API reference doc page:-(. No word is related with the meaning of the returned array of virTypedParameter by virDomainGetCPUStats().
RaSca
2012-Apr-16 11:56 UTC
[libvirt-users] What does cpu_time returned by virDomainGetCPUStats mean?
Il giorno Lun 16 Apr 2012 13:37:24 CEST, Zhihua Che ha scritto: [...]> How can I get the CPU usage of the domain?[...] As Daniel told me two days ago, cpuTime shows the absolute CPU time consumed since boot. To get % CPU time, take two readings 'n' seconds apart and calculate the delta between them. -- RaSca Mia Mamma Usa Linux: Niente ? impossibile da capire, se lo spieghi bene! rasca at miamammausalinux.org http://www.miamammausalinux.org
Eric Blake
2012-Apr-16 20:11 UTC
[libvirt-users] What does cpu_time returned by virDomainGetCPUStats mean?
On 04/16/2012 05:37 AM, Zhihua Che wrote:> > I thought this value store the run time of the cpu since last boot.The intent is to store run time of the hypervisor process managing the guest (which therefore is larger than the amount of time that the guest thinks it has been running, since the hypervisor has some overhead). But the API is flexible enough that we can add more statistics, if it proves easy to collect such additional statistics.> But I find I was wrong because this value would increase until it > wraps down and doesn't reset even the domain is restarted.How are you restarting the guest? If it is by rebooting the guest _within the same qemu process_, then no, the numbers won't reset. Based on how the cpuacct cgroup works, the numbers should only wrap when you actually create a new qemu process (actually stop the guest and boot it fresh in a new qemu process, rather than rebooting the guest within the same qemu process). Perhaps we should be improving our XML to track delta usage since a given point in time, and when we detect a domain reboot, update that delta point so that the usage will again appear to be 0; allowing a delta calculation would also let us "track" CPU usage even across domain migration or managedsave/restore.> > So, what does this value mean? > > How can I get the CPU usage of the domain? > > I found nothing on the API reference doc page:-(. No word is > related with the meaning of the returned array of virTypedParameter by > virDomainGetCPUStats().I found this: http://libvirt.org/html/libvirt-libvirt.html#VIR_DOMAIN_CPU_STATS_CPUTIME "cpu usage in nanoseconds, as a ullong" and looking at libvirt.h, VIR_DOMAIN_CPU_STATS_CPUTIME maps to the "cpu_time" name of your API call. If that still isn't enough information, could you help out by submitting patches to improve our documentation? -- Eric Blake eblake at redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 620 bytes Desc: OpenPGP digital signature URL: <http://listman.redhat.com/archives/libvirt-users/attachments/20120416/dbb3de66/attachment.sig>
Apparently Analagous Threads
- What's the precision of the domain cpu stats?
- Is it possible to in live migration?
- How to dedicate a NIC for VM traffic without assigning it an IP
- What features of kernel are required to support virDomainGetCPUStats?
- [libivrt-users] What features of kernel are required to support virDomainGetCPUStats?