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
8c643f5f
Commit
8c643f5f
authored
Jun 05, 2006
by
Hisham Muhammad
Browse files
Use long long types to avoid overflow
parent
d0325cfe
Changes
4
Hide whitespace changes
Inline
Side-by-side
ChangeLog
View file @
8c643f5f
What's new in version 0.6.3
* Use 64-bit values when storing processor times to
avoid overflow.
* Internal change: rename TypedVector to Vector and
ListBox (and related classes) to Panel.
...
...
ProcessList.c
View file @
8c643f5f
...
...
@@ -66,26 +66,26 @@ typedef struct ProcessList_ {
int totalTasks;
int runningTasks;
long int* totalTime;
long int* userTime;
long int* systemTime;
long int* idleTime;
long int* niceTime;
long int* totalPeriod;
long int* userPeriod;
long int* systemPeriod;
long int* idlePeriod;
long int* nicePeriod;
long int totalMem;
long int usedMem;
long int freeMem;
long int sharedMem;
long int buffersMem;
long int cachedMem;
long int totalSwap;
long int usedSwap;
long int freeSwap;
unsigned long
long int* totalTime;
unsigned long
long int* userTime;
unsigned long
long int* systemTime;
unsigned long
long int* idleTime;
unsigned long
long int* niceTime;
unsigned long
long int* totalPeriod;
unsigned long
long int* userPeriod;
unsigned long
long int* systemPeriod;
unsigned long
long int* idlePeriod;
unsigned long
long int* nicePeriod;
unsigned long
long int totalMem;
unsigned long
long int usedMem;
unsigned long
long int freeMem;
unsigned long
long int sharedMem;
unsigned long
long int buffersMem;
unsigned long
long int cachedMem;
unsigned long
long int totalSwap;
unsigned long
long int usedSwap;
unsigned long
long int freeSwap;
ProcessField* fields;
ProcessField sortKey;
...
...
@@ -130,7 +130,10 @@ static inline int ProcessList_xread(ProcessList* this, vxscanf fn, void* buffer,
va_start
(
ap
,
format
);
while
(
*
format
)
{
char
ch
=
*
format
;
char
*
c
;
int
*
d
;
long
int
*
ld
;
unsigned
long
int
*
lu
;
char
**
s
;
char
*
c
;
int
*
d
;
long
int
*
ld
;
unsigned
long
int
*
lu
;
long
long
int
*
lld
;
unsigned
long
long
int
*
llu
;
char
**
s
;
if
(
ch
!=
'%'
)
{
fprintf
(
this
->
traceFile
,
"%c"
,
ch
);
format
++
;
...
...
@@ -146,6 +149,12 @@ static inline int ProcessList_xread(ProcessList* this, vxscanf fn, void* buffer,
switch
(
*
format
)
{
case
'd'
:
ld
=
va_arg
(
ap
,
long
int
*
);
fprintf
(
this
->
traceFile
,
"%ld"
,
*
ld
);
break
;
case
'u'
:
lu
=
va_arg
(
ap
,
unsigned
long
int
*
);
fprintf
(
this
->
traceFile
,
"%lu"
,
*
lu
);
break
;
case
'l'
:
format
++
;
switch
(
*
format
)
{
case
'd'
:
lld
=
va_arg
(
ap
,
long
long
int
*
);
fprintf
(
this
->
traceFile
,
"%lld"
,
*
lld
);
break
;
case
'u'
:
llu
=
va_arg
(
ap
,
unsigned
long
long
int
*
);
fprintf
(
this
->
traceFile
,
"%llu"
,
*
llu
);
break
;
}
}
}
format
++
;
...
...
@@ -190,16 +199,16 @@ ProcessList* ProcessList_new(UsersTable* usersTable) {
}
while
(
String_startsWith
(
buffer
,
"cpu"
));
fclose
(
status
);
this
->
processorCount
=
procs
-
1
;
this
->
totalTime
=
calloc
(
procs
,
sizeof
(
long
int
));
this
->
userTime
=
calloc
(
procs
,
sizeof
(
long
int
));
this
->
systemTime
=
calloc
(
procs
,
sizeof
(
long
int
));
this
->
niceTime
=
calloc
(
procs
,
sizeof
(
long
int
));
this
->
idleTime
=
calloc
(
procs
,
sizeof
(
long
int
));
this
->
totalPeriod
=
calloc
(
procs
,
sizeof
(
long
int
));
this
->
userPeriod
=
calloc
(
procs
,
sizeof
(
long
int
));
this
->
systemPeriod
=
calloc
(
procs
,
sizeof
(
long
int
));
this
->
nicePeriod
=
calloc
(
procs
,
sizeof
(
long
int
));
this
->
idlePeriod
=
calloc
(
procs
,
sizeof
(
long
int
));
this
->
totalTime
=
calloc
(
procs
,
sizeof
(
long
long
int
));
this
->
userTime
=
calloc
(
procs
,
sizeof
(
long
long
int
));
this
->
systemTime
=
calloc
(
procs
,
sizeof
(
long
long
int
));
this
->
niceTime
=
calloc
(
procs
,
sizeof
(
long
long
int
));
this
->
idleTime
=
calloc
(
procs
,
sizeof
(
long
long
int
));
this
->
totalPeriod
=
calloc
(
procs
,
sizeof
(
long
long
int
));
this
->
userPeriod
=
calloc
(
procs
,
sizeof
(
long
long
int
));
this
->
systemPeriod
=
calloc
(
procs
,
sizeof
(
long
long
int
));
this
->
nicePeriod
=
calloc
(
procs
,
sizeof
(
long
long
int
));
this
->
idlePeriod
=
calloc
(
procs
,
sizeof
(
long
long
int
));
for
(
int
i
=
0
;
i
<
procs
;
i
++
)
{
this
->
totalTime
[
i
]
=
1
;
this
->
totalPeriod
[
i
]
=
1
;
...
...
@@ -560,8 +569,8 @@ void ProcessList_processEntries(ProcessList* this, char* dirname, int parent, fl
}
void
ProcessList_scan
(
ProcessList
*
this
)
{
long
int
usertime
,
nicetime
,
systemtime
,
idletime
,
totaltime
;
long
int
swapFree
;
unsigned
long
long
int
usertime
,
nicetime
,
systemtime
,
idletime
,
totaltime
;
unsigned
long
long
int
swapFree
;
FILE
*
status
;
char
buffer
[
128
];
...
...
@@ -573,25 +582,25 @@ void ProcessList_scan(ProcessList* this) {
switch
(
buffer
[
0
])
{
case
'M'
:
if
(
String_startsWith
(
buffer
,
"MemTotal:"
))
ProcessList_read
(
this
,
buffer
,
"MemTotal: %l
d
kB"
,
&
this
->
totalMem
);
ProcessList_read
(
this
,
buffer
,
"MemTotal: %l
lu
kB"
,
&
this
->
totalMem
);
else
if
(
String_startsWith
(
buffer
,
"MemFree:"
))
ProcessList_read
(
this
,
buffer
,
"MemFree: %l
d
kB"
,
&
this
->
freeMem
);
ProcessList_read
(
this
,
buffer
,
"MemFree: %l
lu
kB"
,
&
this
->
freeMem
);
else
if
(
String_startsWith
(
buffer
,
"MemShared:"
))
ProcessList_read
(
this
,
buffer
,
"MemShared: %l
d
kB"
,
&
this
->
sharedMem
);
ProcessList_read
(
this
,
buffer
,
"MemShared: %l
lu
kB"
,
&
this
->
sharedMem
);
break
;
case
'B'
:
if
(
String_startsWith
(
buffer
,
"Buffers:"
))
ProcessList_read
(
this
,
buffer
,
"Buffers: %l
d
kB"
,
&
this
->
buffersMem
);
ProcessList_read
(
this
,
buffer
,
"Buffers: %l
lu
kB"
,
&
this
->
buffersMem
);
break
;
case
'C'
:
if
(
String_startsWith
(
buffer
,
"Cached:"
))
ProcessList_read
(
this
,
buffer
,
"Cached: %l
d
kB"
,
&
this
->
cachedMem
);
ProcessList_read
(
this
,
buffer
,
"Cached: %l
lu
kB"
,
&
this
->
cachedMem
);
break
;
case
'S'
:
if
(
String_startsWith
(
buffer
,
"SwapTotal:"
))
ProcessList_read
(
this
,
buffer
,
"SwapTotal: %l
d
kB"
,
&
this
->
totalSwap
);
ProcessList_read
(
this
,
buffer
,
"SwapTotal: %l
lu
kB"
,
&
this
->
totalSwap
);
if
(
String_startsWith
(
buffer
,
"SwapFree:"
))
ProcessList_read
(
this
,
buffer
,
"SwapFree: %l
d
kB"
,
&
swapFree
);
ProcessList_read
(
this
,
buffer
,
"SwapFree: %l
lu
kB"
,
&
swapFree
);
break
;
}
}
...
...
@@ -606,16 +615,16 @@ void ProcessList_scan(ProcessList* this) {
for
(
int
i
=
0
;
i
<=
this
->
processorCount
;
i
++
)
{
char
buffer
[
256
];
int
cpuid
;
long
int
ioWait
,
irq
,
softIrq
,
steal
;
unsigned
long
long
int
ioWait
,
irq
,
softIrq
,
steal
;
ioWait
=
irq
=
softIrq
=
steal
=
0
;
// Dependending on your kernel version,
// 5, 7 or 8 of these fields will be set.
// The rest will remain at zero.
fgets
(
buffer
,
255
,
status
);
if
(
i
==
0
)
ProcessList_read
(
this
,
buffer
,
"cpu %l
d
%l
d
%l
d
%l
d
%l
d
%l
d
%l
d
%l
d
"
,
&
usertime
,
&
nicetime
,
&
systemtime
,
&
idletime
,
&
ioWait
,
&
irq
,
&
softIrq
,
&
steal
);
ProcessList_read
(
this
,
buffer
,
"cpu %l
lu
%l
lu
%l
lu
%l
lu
%l
lu
%l
lu
%l
lu
%l
lu
"
,
&
usertime
,
&
nicetime
,
&
systemtime
,
&
idletime
,
&
ioWait
,
&
irq
,
&
softIrq
,
&
steal
);
else
{
ProcessList_read
(
this
,
buffer
,
"cpu%d %l
d
%l
d
%l
d
%l
d
%l
d
%l
d
%l
d
%l
d
"
,
&
cpuid
,
&
usertime
,
&
nicetime
,
&
systemtime
,
&
idletime
,
&
ioWait
,
&
irq
,
&
softIrq
,
&
steal
);
ProcessList_read
(
this
,
buffer
,
"cpu%d %l
lu
%l
lu
%l
lu
%l
lu
%l
lu
%l
lu
%l
lu
%l
lu
"
,
&
cpuid
,
&
usertime
,
&
nicetime
,
&
systemtime
,
&
idletime
,
&
ioWait
,
&
irq
,
&
softIrq
,
&
steal
);
assert
(
cpuid
==
i
-
1
);
}
// Fields existing on kernels >= 2.6
...
...
ProcessList.h
View file @
8c643f5f
...
...
@@ -66,26 +66,26 @@ typedef struct ProcessList_ {
int
totalTasks
;
int
runningTasks
;
long
int
*
totalTime
;
long
int
*
userTime
;
long
int
*
systemTime
;
long
int
*
idleTime
;
long
int
*
niceTime
;
long
int
*
totalPeriod
;
long
int
*
userPeriod
;
long
int
*
systemPeriod
;
long
int
*
idlePeriod
;
long
int
*
nicePeriod
;
long
int
totalMem
;
long
int
usedMem
;
long
int
freeMem
;
long
int
sharedMem
;
long
int
buffersMem
;
long
int
cachedMem
;
long
int
totalSwap
;
long
int
usedSwap
;
long
int
freeSwap
;
unsigned
long
long
int
*
totalTime
;
unsigned
long
long
int
*
userTime
;
unsigned
long
long
int
*
systemTime
;
unsigned
long
long
int
*
idleTime
;
unsigned
long
long
int
*
niceTime
;
unsigned
long
long
int
*
totalPeriod
;
unsigned
long
long
int
*
userPeriod
;
unsigned
long
long
int
*
systemPeriod
;
unsigned
long
long
int
*
idlePeriod
;
unsigned
long
long
int
*
nicePeriod
;
unsigned
long
long
int
totalMem
;
unsigned
long
long
int
usedMem
;
unsigned
long
long
int
freeMem
;
unsigned
long
long
int
sharedMem
;
unsigned
long
long
int
buffersMem
;
unsigned
long
long
int
cachedMem
;
unsigned
long
long
int
totalSwap
;
unsigned
long
long
int
usedSwap
;
unsigned
long
long
int
freeSwap
;
ProcessField
*
fields
;
ProcessField
sortKey
;
...
...
@@ -151,6 +151,4 @@ void ProcessList_processEntries(ProcessList* this, char* dirname, int parent, fl
void
ProcessList_scan
(
ProcessList
*
this
);
void
ProcessList_dontCrash
(
int
signal
);
#endif
scripts/MakeHeader.py
100644 → 100755
View file @
8c643f5f
File mode changed from 100644 to 100755
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