mirror of https://github.com/xzeldon/htop.git
Reduce scope of variables.
This commit is contained in:
parent
9428010121
commit
5e4f1e46cc
|
@ -661,7 +661,6 @@ static inline void LinuxProcessList_scanMemoryInfo(ProcessList* this) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline double LinuxProcessList_scanCPUTime(LinuxProcessList* this) {
|
static inline double LinuxProcessList_scanCPUTime(LinuxProcessList* this) {
|
||||||
unsigned long long int usertime, nicetime, systemtime, idletime;
|
|
||||||
|
|
||||||
FILE* file = fopen(PROCSTATFILE, "r");
|
FILE* file = fopen(PROCSTATFILE, "r");
|
||||||
if (file == NULL) {
|
if (file == NULL) {
|
||||||
|
@ -671,9 +670,8 @@ static inline double LinuxProcessList_scanCPUTime(LinuxProcessList* this) {
|
||||||
assert(cpus > 0);
|
assert(cpus > 0);
|
||||||
for (int i = 0; i <= cpus; i++) {
|
for (int i = 0; i <= cpus; i++) {
|
||||||
char buffer[256];
|
char buffer[256];
|
||||||
int cpuid;
|
unsigned long long int usertime, nicetime, systemtime, idletime;
|
||||||
unsigned long long int ioWait, irq, softIrq, steal, guest, guestnice;
|
unsigned long long int ioWait, irq, softIrq, steal, guest, guestnice;
|
||||||
unsigned long long int systemalltime, idlealltime, totaltime, virtalltime;
|
|
||||||
ioWait = irq = softIrq = steal = guest = guestnice = 0;
|
ioWait = irq = softIrq = steal = guest = guestnice = 0;
|
||||||
// Depending on your kernel version,
|
// Depending on your kernel version,
|
||||||
// 5, 7, 8 or 9 of these fields will be set.
|
// 5, 7, 8 or 9 of these fields will be set.
|
||||||
|
@ -683,6 +681,7 @@ static inline double LinuxProcessList_scanCPUTime(LinuxProcessList* this) {
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
sscanf(buffer, "cpu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu", &usertime, &nicetime, &systemtime, &idletime, &ioWait, &irq, &softIrq, &steal, &guest, &guestnice);
|
sscanf(buffer, "cpu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu", &usertime, &nicetime, &systemtime, &idletime, &ioWait, &irq, &softIrq, &steal, &guest, &guestnice);
|
||||||
else {
|
else {
|
||||||
|
int cpuid;
|
||||||
sscanf(buffer, "cpu%4d %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu", &cpuid, &usertime, &nicetime, &systemtime, &idletime, &ioWait, &irq, &softIrq, &steal, &guest, &guestnice);
|
sscanf(buffer, "cpu%4d %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu", &cpuid, &usertime, &nicetime, &systemtime, &idletime, &ioWait, &irq, &softIrq, &steal, &guest, &guestnice);
|
||||||
assert(cpuid == i - 1);
|
assert(cpuid == i - 1);
|
||||||
}
|
}
|
||||||
|
@ -691,10 +690,10 @@ static inline double LinuxProcessList_scanCPUTime(LinuxProcessList* this) {
|
||||||
nicetime = nicetime - guestnice;
|
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;
|
unsigned long long int idlealltime = idletime + ioWait;
|
||||||
systemalltime = systemtime + irq + softIrq;
|
unsigned long long int systemalltime = systemtime + irq + softIrq;
|
||||||
virtalltime = guest + guestnice;
|
unsigned long long int virtalltime = guest + guestnice;
|
||||||
totaltime = usertime + nicetime + systemalltime + idlealltime + steal + virtalltime;
|
unsigned long long int 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);
|
||||||
|
|
Loading…
Reference in New Issue