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