On 05.07.2014 19:44, Restituto Marcus Arevalo wrote:
Hi,
Does anyone know where I could view the source code of
virt-manager? Because I'm trying to learn how the virt-manager gets the
CPU usage of a VM(the graph it displays). I'm trying to make a program
using java that gets the CPU usage of a VM in KVM. Anybody have
suggestions on where I could start? Thanks
The virt-manager source code can be found here:
https://git.fedorahosted.org/git/virt-manager.git
To check it out use:
git clone
git://git.fedorahosted.org/git/virt-manager.git virt-manager.git
The CPU usage of a domain is queried using virDomainGetInfo. The CPU
usage is then calculated as (in a crippled C):
while (1) {
time1 = now();
virDomainGetInfo(dom, &info);
cpu1 = info.cpuTime;
sleep(500); // sleep some time
time2 = now();
virDomainGetInfo(dom, &info);
cpu2 = info.cpuTime;
cpuUsagePercent = (cpu2 - cpu1) / (time2 - time1) * 100;
}
Michal