mirror of https://github.com/xzeldon/htop.git
Replaces WRAP_SUBTRACT with saturatingSub inline function to reduce code duplication.
This commit is contained in:
parent
2f5b3ef733
commit
3770769ed1
2
Macros.h
2
Macros.h
|
@ -69,7 +69,7 @@
|
||||||
#define IGNORE_WCASTQUAL_END
|
#define IGNORE_WCASTQUAL_END
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* This subtraction is used by NetBSD / OpenBSD for calculation of CPU usage items. */
|
/* This subtraction is used by Linux / NetBSD / OpenBSD for calculation of CPU usage items. */
|
||||||
static inline unsigned long long saturatingSub(unsigned long long a, unsigned long long b) {
|
static inline unsigned long long saturatingSub(unsigned long long a, unsigned long long b) {
|
||||||
return a > b ? a - b : 0;
|
return a > b ? a - b : 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1811,20 +1811,18 @@ static inline double LinuxProcessList_scanCPUTime(ProcessList* super) {
|
||||||
// Since we do a subtraction (usertime - guest) and cputime64_to_clock_t()
|
// Since we do a subtraction (usertime - guest) and cputime64_to_clock_t()
|
||||||
// used in /proc/stat rounds down numbers, it can lead to a case where the
|
// used in /proc/stat rounds down numbers, it can lead to a case where the
|
||||||
// integer overflow.
|
// integer overflow.
|
||||||
#define WRAP_SUBTRACT(a,b) (((a) > (b)) ? (a) - (b) : 0)
|
cpuData->userPeriod = saturatingSub(usertime, cpuData->userTime);
|
||||||
cpuData->userPeriod = WRAP_SUBTRACT(usertime, cpuData->userTime);
|
cpuData->nicePeriod = saturatingSub(nicetime, cpuData->niceTime);
|
||||||
cpuData->nicePeriod = WRAP_SUBTRACT(nicetime, cpuData->niceTime);
|
cpuData->systemPeriod = saturatingSub(systemtime, cpuData->systemTime);
|
||||||
cpuData->systemPeriod = WRAP_SUBTRACT(systemtime, cpuData->systemTime);
|
cpuData->systemAllPeriod = saturatingSub(systemalltime, cpuData->systemAllTime);
|
||||||
cpuData->systemAllPeriod = WRAP_SUBTRACT(systemalltime, cpuData->systemAllTime);
|
cpuData->idleAllPeriod = saturatingSub(idlealltime, cpuData->idleAllTime);
|
||||||
cpuData->idleAllPeriod = WRAP_SUBTRACT(idlealltime, cpuData->idleAllTime);
|
cpuData->idlePeriod = saturatingSub(idletime, cpuData->idleTime);
|
||||||
cpuData->idlePeriod = WRAP_SUBTRACT(idletime, cpuData->idleTime);
|
cpuData->ioWaitPeriod = saturatingSub(ioWait, cpuData->ioWaitTime);
|
||||||
cpuData->ioWaitPeriod = WRAP_SUBTRACT(ioWait, cpuData->ioWaitTime);
|
cpuData->irqPeriod = saturatingSub(irq, cpuData->irqTime);
|
||||||
cpuData->irqPeriod = WRAP_SUBTRACT(irq, cpuData->irqTime);
|
cpuData->softIrqPeriod = saturatingSub(softIrq, cpuData->softIrqTime);
|
||||||
cpuData->softIrqPeriod = WRAP_SUBTRACT(softIrq, cpuData->softIrqTime);
|
cpuData->stealPeriod = saturatingSub(steal, cpuData->stealTime);
|
||||||
cpuData->stealPeriod = WRAP_SUBTRACT(steal, cpuData->stealTime);
|
cpuData->guestPeriod = saturatingSub(virtalltime, cpuData->guestTime);
|
||||||
cpuData->guestPeriod = WRAP_SUBTRACT(virtalltime, cpuData->guestTime);
|
cpuData->totalPeriod = saturatingSub(totaltime, cpuData->totalTime);
|
||||||
cpuData->totalPeriod = WRAP_SUBTRACT(totaltime, cpuData->totalTime);
|
|
||||||
#undef WRAP_SUBTRACT
|
|
||||||
cpuData->userTime = usertime;
|
cpuData->userTime = usertime;
|
||||||
cpuData->niceTime = nicetime;
|
cpuData->niceTime = nicetime;
|
||||||
cpuData->systemTime = systemtime;
|
cpuData->systemTime = systemtime;
|
||||||
|
|
Loading…
Reference in New Issue