mirror of https://github.com/xzeldon/htop.git
Fixes in accounting of guest time when using virtualization
(thanks to Patrick Marlier)
This commit is contained in:
parent
6cfa9e0bf2
commit
af285d1d3b
|
@ -1,6 +1,8 @@
|
||||||
|
|
||||||
What's new in version 1.0.3
|
What's new in version 1.0.3
|
||||||
|
|
||||||
|
* Fixes in accounting of guest time when using virtualization
|
||||||
|
(thanks to Patrick Marlier)
|
||||||
* Performance improvements
|
* Performance improvements
|
||||||
(thanks to Jann Horn)
|
(thanks to Jann Horn)
|
||||||
* Further performance improvements due to conditional parsing
|
* Further performance improvements due to conditional parsing
|
||||||
|
|
|
@ -886,24 +886,27 @@ void ProcessList_scan(ProcessList* this) {
|
||||||
for (int i = 0; i <= cpus; i++) {
|
for (int i = 0; i <= cpus; i++) {
|
||||||
char buffer[256];
|
char buffer[256];
|
||||||
int cpuid;
|
int cpuid;
|
||||||
unsigned long long int ioWait, irq, softIrq, steal, guest;
|
unsigned long long int ioWait, irq, softIrq, steal, guest, guestnice;
|
||||||
ioWait = irq = softIrq = steal = guest = 0;
|
ioWait = irq = softIrq = steal = guest = guestnice = 0;
|
||||||
// Dependending on your kernel version,
|
// Dependending on your kernel version,
|
||||||
// 5, 7 or 8 of these fields will be set.
|
// 5, 7, 8 or 9 of these fields will be set.
|
||||||
// The rest will remain at zero.
|
// The rest will remain at zero.
|
||||||
fgets(buffer, 255, file);
|
fgets(buffer, 255, file);
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
sscanf(buffer, "cpu %llu %llu %llu %llu %llu %llu %llu %llu %llu", &usertime, &nicetime, &systemtime, &idletime, &ioWait, &irq, &softIrq, &steal, &guest);
|
sscanf(buffer, "cpu %llu %llu %llu %llu %llu %llu %llu %llu %llu %llu", &usertime, &nicetime, &systemtime, &idletime, &ioWait, &irq, &softIrq, &steal, &guest, &guestnice);
|
||||||
else {
|
else {
|
||||||
sscanf(buffer, "cpu%d %llu %llu %llu %llu %llu %llu %llu %llu %llu", &cpuid, &usertime, &nicetime, &systemtime, &idletime, &ioWait, &irq, &softIrq, &steal, &guest);
|
sscanf(buffer, "cpu%d %llu %llu %llu %llu %llu %llu %llu %llu %llu %llu", &cpuid, &usertime, &nicetime, &systemtime, &idletime, &ioWait, &irq, &softIrq, &steal, &guest, &guestnice);
|
||||||
assert(cpuid == i - 1);
|
assert(cpuid == i - 1);
|
||||||
}
|
}
|
||||||
|
// Guest time is already accounted in usertime
|
||||||
|
usertime = usertime - guest;
|
||||||
|
nicetime = nicetime - guestnice;
|
||||||
// Fields existing on kernels >= 2.6
|
// Fields existing on kernels >= 2.6
|
||||||
// (and RHEL's patched kernel 2.4...)
|
// (and RHEL's patched kernel 2.4...)
|
||||||
idlealltime = idletime + ioWait;
|
idlealltime = idletime + ioWait;
|
||||||
systemalltime = systemtime + irq + softIrq;
|
systemalltime = systemtime + irq + softIrq;
|
||||||
virtalltime = steal + guest;
|
virtalltime = guest + guestnice;
|
||||||
totaltime = usertime + nicetime + systemalltime + idlealltime + virtalltime;
|
totaltime = usertime + nicetime + systemalltime + idlealltime + steal + virtalltime;
|
||||||
CPUData* cpuData = &(this->cpus[i]);
|
CPUData* cpuData = &(this->cpus[i]);
|
||||||
assert (usertime >= cpuData->userTime);
|
assert (usertime >= cpuData->userTime);
|
||||||
assert (nicetime >= cpuData->niceTime);
|
assert (nicetime >= cpuData->niceTime);
|
||||||
|
@ -916,7 +919,7 @@ void ProcessList_scan(ProcessList* this) {
|
||||||
assert (irq >= cpuData->irqTime);
|
assert (irq >= cpuData->irqTime);
|
||||||
assert (softIrq >= cpuData->softIrqTime);
|
assert (softIrq >= cpuData->softIrqTime);
|
||||||
assert (steal >= cpuData->stealTime);
|
assert (steal >= cpuData->stealTime);
|
||||||
assert (guest >= cpuData->guestTime);
|
assert (virtalltime >= cpuData->guestTime);
|
||||||
cpuData->userPeriod = usertime - cpuData->userTime;
|
cpuData->userPeriod = usertime - cpuData->userTime;
|
||||||
cpuData->nicePeriod = nicetime - cpuData->niceTime;
|
cpuData->nicePeriod = nicetime - cpuData->niceTime;
|
||||||
cpuData->systemPeriod = systemtime - cpuData->systemTime;
|
cpuData->systemPeriod = systemtime - cpuData->systemTime;
|
||||||
|
@ -927,7 +930,7 @@ void ProcessList_scan(ProcessList* this) {
|
||||||
cpuData->irqPeriod = irq - cpuData->irqTime;
|
cpuData->irqPeriod = irq - cpuData->irqTime;
|
||||||
cpuData->softIrqPeriod = softIrq - cpuData->softIrqTime;
|
cpuData->softIrqPeriod = softIrq - cpuData->softIrqTime;
|
||||||
cpuData->stealPeriod = steal - cpuData->stealTime;
|
cpuData->stealPeriod = steal - cpuData->stealTime;
|
||||||
cpuData->guestPeriod = guest - cpuData->guestTime;
|
cpuData->guestPeriod = virtalltime - cpuData->guestTime;
|
||||||
cpuData->totalPeriod = totaltime - cpuData->totalTime;
|
cpuData->totalPeriod = totaltime - cpuData->totalTime;
|
||||||
cpuData->userTime = usertime;
|
cpuData->userTime = usertime;
|
||||||
cpuData->niceTime = nicetime;
|
cpuData->niceTime = nicetime;
|
||||||
|
@ -939,7 +942,7 @@ void ProcessList_scan(ProcessList* this) {
|
||||||
cpuData->irqTime = irq;
|
cpuData->irqTime = irq;
|
||||||
cpuData->softIrqTime = softIrq;
|
cpuData->softIrqTime = softIrq;
|
||||||
cpuData->stealTime = steal;
|
cpuData->stealTime = steal;
|
||||||
cpuData->guestTime = guest;
|
cpuData->guestTime = virtalltime;
|
||||||
cpuData->totalTime = totaltime;
|
cpuData->totalTime = totaltime;
|
||||||
}
|
}
|
||||||
double period = (double)this->cpus[0].totalPeriod / cpus; fclose(file);
|
double period = (double)this->cpus[0].totalPeriod / cpus; fclose(file);
|
||||||
|
|
Loading…
Reference in New Issue