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
2c4d7304
Commit
2c4d7304
authored
Oct 04, 2006
by
Hisham Muhammad
Browse files
Allocate per-processor values in a contiguous chunk of memory
parent
538d29b3
Changes
2
Show whitespace changes
Inline
Side-by-side
ProcessList.c
View file @
2c4d7304
...
@@ -52,6 +52,10 @@ in the source distribution for its full text.
...
@@ -52,6 +52,10 @@ in the source distribution for its full text.
#define MAX_READ 2048
#define MAX_READ 2048
#endif
#endif
#ifndef PER_PROCESSOR_FIELDS
#define PER_PROCESSOR_FIELDS 20
#endif
}*/
}*/
/*{
/*{
...
@@ -71,6 +75,7 @@ typedef struct ProcessList_ {
...
@@ -71,6 +75,7 @@ typedef struct ProcessList_ {
int totalTasks;
int totalTasks;
int runningTasks;
int runningTasks;
// Must match number of PER_PROCESSOR_FIELDS constant
unsigned long long int* totalTime;
unsigned long long int* totalTime;
unsigned long long int* userTime;
unsigned long long int* userTime;
unsigned long long int* systemTime;
unsigned long long int* systemTime;
...
@@ -112,6 +117,7 @@ typedef struct ProcessList_ {
...
@@ -112,6 +117,7 @@ typedef struct ProcessList_ {
bool treeView;
bool treeView;
bool highlightBaseName;
bool highlightBaseName;
bool highlightMegabytes;
bool highlightMegabytes;
bool expandSystemTime;
#ifdef DEBUG
#ifdef DEBUG
FILE* traceFile;
FILE* traceFile;
#endif
#endif
...
@@ -183,6 +189,16 @@ static inline int ProcessList_xread(ProcessList* this, vxscanf fn, void* buffer,
...
@@ -183,6 +189,16 @@ static inline int ProcessList_xread(ProcessList* this, vxscanf fn, void* buffer,
#endif
#endif
static
inline
void
ProcessList_allocatePerProcessorBuffers
(
ProcessList
*
this
,
int
procs
)
{
unsigned
long
long
int
**
bufferPtr
=
&
(
this
->
totalTime
);
unsigned
long
long
int
*
buffer
=
calloc
(
procs
*
PER_PROCESSOR_FIELDS
,
sizeof
(
unsigned
long
long
int
));
for
(
int
i
=
0
;
i
<
PER_PROCESSOR_FIELDS
;
i
++
)
{
*
bufferPtr
=
buffer
;
bufferPtr
++
;
buffer
+=
procs
;
}
}
ProcessList
*
ProcessList_new
(
UsersTable
*
usersTable
)
{
ProcessList
*
ProcessList_new
(
UsersTable
*
usersTable
)
{
ProcessList
*
this
;
ProcessList
*
this
;
this
=
malloc
(
sizeof
(
ProcessList
));
this
=
malloc
(
sizeof
(
ProcessList
));
...
@@ -208,29 +224,9 @@ ProcessList* ProcessList_new(UsersTable* usersTable) {
...
@@ -208,29 +224,9 @@ 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
*
FIELDS
,
sizeof
(
long
long
int
));
this
->
userTime
=
ProcessList_allocatePerProcessorBuffers
(
this
,
procs
);
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
->
systemAllTime
=
calloc
(
procs
,
sizeof
(
long
long
int
));
this
->
niceTime
=
calloc
(
procs
,
sizeof
(
long
long
int
));
this
->
idleTime
=
calloc
(
procs
,
sizeof
(
long
long
int
));
this
->
ioWaitTime
=
calloc
(
procs
,
sizeof
(
long
long
int
));
this
->
irqTime
=
calloc
(
procs
,
sizeof
(
long
long
int
));
this
->
softIrqTime
=
calloc
(
procs
,
sizeof
(
long
long
int
));
this
->
stealTime
=
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
->
systemAllPeriod
=
calloc
(
procs
,
sizeof
(
long
long
int
));
this
->
nicePeriod
=
calloc
(
procs
,
sizeof
(
long
long
int
));
this
->
idlePeriod
=
calloc
(
procs
,
sizeof
(
long
long
int
));
this
->
ioWaitPeriod
=
calloc
(
procs
,
sizeof
(
long
long
int
));
this
->
irqPeriod
=
calloc
(
procs
,
sizeof
(
long
long
int
));
this
->
softIrqPeriod
=
calloc
(
procs
,
sizeof
(
long
long
int
));
this
->
stealPeriod
=
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
;
...
@@ -262,26 +258,9 @@ void ProcessList_delete(ProcessList* this) {
...
@@ -262,26 +258,9 @@ void ProcessList_delete(ProcessList* this) {
Vector_delete
(
this
->
processes2
);
Vector_delete
(
this
->
processes2
);
Process_delete
((
Object
*
)
this
->
prototype
);
Process_delete
((
Object
*
)
this
->
prototype
);
// Free first entry only;
// other fields are offsets of the same buffer
free
(
this
->
totalTime
);
free
(
this
->
totalTime
);
free
(
this
->
userTime
);
free
(
this
->
systemTime
);
free
(
this
->
systemAllTime
);
free
(
this
->
niceTime
);
free
(
this
->
idleTime
);
free
(
this
->
ioWaitTime
);
free
(
this
->
irqTime
);
free
(
this
->
softIrqTime
);
free
(
this
->
stealTime
);
free
(
this
->
totalPeriod
);
free
(
this
->
userPeriod
);
free
(
this
->
systemPeriod
);
free
(
this
->
systemAllPeriod
);
free
(
this
->
nicePeriod
);
free
(
this
->
idlePeriod
);
free
(
this
->
ioWaitPeriod
);
free
(
this
->
irqPeriod
);
free
(
this
->
softIrqPeriod
);
free
(
this
->
stealPeriod
);
#ifdef DEBUG
#ifdef DEBUG
fclose
(
this
->
traceFile
);
fclose
(
this
->
traceFile
);
...
@@ -699,9 +678,9 @@ void ProcessList_scan(ProcessList* this) {
...
@@ -699,9 +678,9 @@ void ProcessList_scan(ProcessList* this) {
assert
(
totaltime
>=
this
->
totalTime
[
i
]);
assert
(
totaltime
>=
this
->
totalTime
[
i
]);
assert
(
systemalltime
>=
this
->
systemAllTime
[
i
]);
assert
(
systemalltime
>=
this
->
systemAllTime
[
i
]);
assert
(
ioWait
>=
this
->
ioWaitTime
[
i
]);
assert
(
ioWait
>=
this
->
ioWaitTime
[
i
]);
assert
(
irq
Time
>=
this
->
irqTime
[
i
]);
assert
(
irq
>=
this
->
irqTime
[
i
]);
assert
(
softIrq
Time
>=
this
->
softIrqTime
[
i
]);
assert
(
softIrq
>=
this
->
softIrqTime
[
i
]);
assert
(
steal
Time
>=
this
->
stealTime
[
i
]);
assert
(
steal
>=
this
->
stealTime
[
i
]);
this
->
userPeriod
[
i
]
=
usertime
-
this
->
userTime
[
i
];
this
->
userPeriod
[
i
]
=
usertime
-
this
->
userTime
[
i
];
this
->
nicePeriod
[
i
]
=
nicetime
-
this
->
niceTime
[
i
];
this
->
nicePeriod
[
i
]
=
nicetime
-
this
->
niceTime
[
i
];
this
->
systemPeriod
[
i
]
=
systemtime
-
this
->
systemTime
[
i
];
this
->
systemPeriod
[
i
]
=
systemtime
-
this
->
systemTime
[
i
];
...
...
ProcessList.h
View file @
2c4d7304
...
@@ -54,6 +54,10 @@ in the source distribution for its full text.
...
@@ -54,6 +54,10 @@ in the source distribution for its full text.
#define MAX_READ 2048
#define MAX_READ 2048
#endif
#endif
#ifndef PER_PROCESSOR_FIELDS
#define PER_PROCESSOR_FIELDS 20
#endif
#ifdef DEBUG
#ifdef DEBUG
...
@@ -71,6 +75,7 @@ typedef struct ProcessList_ {
...
@@ -71,6 +75,7 @@ typedef struct ProcessList_ {
int
totalTasks
;
int
totalTasks
;
int
runningTasks
;
int
runningTasks
;
// Must match number of PER_PROCESSOR_FIELDS constant
unsigned
long
long
int
*
totalTime
;
unsigned
long
long
int
*
totalTime
;
unsigned
long
long
int
*
userTime
;
unsigned
long
long
int
*
userTime
;
unsigned
long
long
int
*
systemTime
;
unsigned
long
long
int
*
systemTime
;
...
...
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