virt-top: correct "virt-top -1" command via cpuacct cgroup
Old "virt-top -1" is not correct, its output is generated by guess:
use average usage for pinned physical CPUs.
example(old "virt-top -1"):
PHYCPU %CPU rhel6 Windows
0 0.6 0.1= 0.5=
1 0.6 0.1= 0.5=#
2 0.6 0.1= 0.5=
3 0.6 0.1=# 0.5=
The output almost makes no sense(all the value are just average, not real).
This is new implement, it use cpuacct cgroup to gain *real* physical usages
via cpuacct cgroup by virDomainGetCPUStats() API.
new result:
PHYCPU %CPU rhel6 Windows
0 1.3 0.3 1.0
1 2.3 0.3 2.0
2 2.2 0.5 1.7
3 2.5 0.4 2.1
PHYCPU %CPU rhel6 Windows
0 1.7 0.4 1.3
1 3.6 1.0 2.7
2 1.6 0.4 1.2
3 4.8 3.1 1.7
Note: average flag(=) is dropped, there is not average value in here.
Note: running flag(#) is dropped, because if the value is not empty,
it means the guest was once running in the physical CPU in this period
between updates.
Changed from V3:
use new virDomainGetCPUStats() libvirt-API.
add a new function find_usages_from_stats() to gain cpu usages.
Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>