Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
htop
Commits
b37d4f17
Commit
b37d4f17
authored
Aug 30, 2015
by
Patrick Marlier
Browse files
Fix a case where the usertime calculation can overflow (see issue #202)
parent
1d805b36
Changes
1
Show whitespace changes
Inline
Side-by-side
linux/LinuxProcessList.c
View file @
b37d4f17
...
...
@@ -695,8 +695,6 @@ static inline double LinuxProcessList_scanCPUTime(LinuxProcessList* this) {
unsigned
long
long
int
virtalltime
=
guest
+
guestnice
;
unsigned
long
long
int
totaltime
=
usertime
+
nicetime
+
systemalltime
+
idlealltime
+
steal
+
virtalltime
;
CPUData
*
cpuData
=
&
(
this
->
cpus
[
i
]);
assert
(
usertime
>=
cpuData
->
userTime
);
assert
(
nicetime
>=
cpuData
->
niceTime
);
assert
(
systemtime
>=
cpuData
->
systemTime
);
assert
(
idletime
>=
cpuData
->
idleTime
);
assert
(
totaltime
>=
cpuData
->
totalTime
);
...
...
@@ -707,8 +705,11 @@ static inline double LinuxProcessList_scanCPUTime(LinuxProcessList* this) {
assert
(
softIrq
>=
cpuData
->
softIrqTime
);
assert
(
steal
>=
cpuData
->
stealTime
);
assert
(
virtalltime
>=
cpuData
->
guestTime
);
cpuData
->
userPeriod
=
usertime
-
cpuData
->
userTime
;
cpuData
->
nicePeriod
=
nicetime
-
cpuData
->
niceTime
;
// 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
// integer overflow.
cpuData
->
userPeriod
=
(
usertime
>
cpuData
->
userTime
)
?
usertime
-
cpuData
->
userTime
:
0
;
cpuData
->
nicePeriod
=
(
nicetime
>
cpuData
->
niceTime
)
?
nicetime
-
cpuData
->
niceTime
:
0
;
cpuData
->
systemPeriod
=
systemtime
-
cpuData
->
systemTime
;
cpuData
->
systemAllPeriod
=
systemalltime
-
cpuData
->
systemAllTime
;
cpuData
->
idleAllPeriod
=
idlealltime
-
cpuData
->
idleAllTime
;
...
...
@@ -732,7 +733,8 @@ static inline double LinuxProcessList_scanCPUTime(LinuxProcessList* this) {
cpuData
->
guestTime
=
virtalltime
;
cpuData
->
totalTime
=
totaltime
;
}
double
period
=
(
double
)
this
->
cpus
[
0
].
totalPeriod
/
cpus
;
fclose
(
file
);
double
period
=
(
double
)
this
->
cpus
[
0
].
totalPeriod
/
cpus
;
fclose
(
file
);
return
period
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment