mirror of https://github.com/xzeldon/htop.git
Allocate per-processor values in a contiguous chunk of memory
This commit is contained in:
parent
538d29b3f6
commit
2c4d730403
|
@ -52,6 +52,10 @@ in the source distribution for its full text.
|
|||
#define MAX_READ 2048
|
||||
#endif
|
||||
|
||||
#ifndef PER_PROCESSOR_FIELDS
|
||||
#define PER_PROCESSOR_FIELDS 20
|
||||
#endif
|
||||
|
||||
}*/
|
||||
|
||||
/*{
|
||||
|
@ -71,6 +75,7 @@ typedef struct ProcessList_ {
|
|||
int totalTasks;
|
||||
int runningTasks;
|
||||
|
||||
// Must match number of PER_PROCESSOR_FIELDS constant
|
||||
unsigned long long int* totalTime;
|
||||
unsigned long long int* userTime;
|
||||
unsigned long long int* systemTime;
|
||||
|
@ -112,6 +117,7 @@ typedef struct ProcessList_ {
|
|||
bool treeView;
|
||||
bool highlightBaseName;
|
||||
bool highlightMegabytes;
|
||||
bool expandSystemTime;
|
||||
#ifdef DEBUG
|
||||
FILE* traceFile;
|
||||
#endif
|
||||
|
@ -183,6 +189,16 @@ static inline int ProcessList_xread(ProcessList* this, vxscanf fn, void* buffer,
|
|||
|
||||
#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* this;
|
||||
this = malloc(sizeof(ProcessList));
|
||||
|
@ -208,29 +224,9 @@ ProcessList* ProcessList_new(UsersTable* usersTable) {
|
|||
} while (String_startsWith(buffer, "cpu"));
|
||||
fclose(status);
|
||||
this->processorCount = procs - 1;
|
||||
this->totalTime = calloc(procs * FIELDS, sizeof(long long int));
|
||||
this->userTime =
|
||||
|
||||
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));
|
||||
ProcessList_allocatePerProcessorBuffers(this, procs);
|
||||
|
||||
for (int i = 0; i < procs; i++) {
|
||||
this->totalTime[i] = 1;
|
||||
this->totalPeriod[i] = 1;
|
||||
|
@ -262,26 +258,9 @@ void ProcessList_delete(ProcessList* this) {
|
|||
Vector_delete(this->processes2);
|
||||
Process_delete((Object*)this->prototype);
|
||||
|
||||
// Free first entry only;
|
||||
// other fields are offsets of the same buffer
|
||||
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
|
||||
fclose(this->traceFile);
|
||||
|
@ -699,9 +678,9 @@ void ProcessList_scan(ProcessList* this) {
|
|||
assert (totaltime >= this->totalTime[i]);
|
||||
assert (systemalltime >= this->systemAllTime[i]);
|
||||
assert (ioWait >= this->ioWaitTime[i]);
|
||||
assert (irqTime >= this->irqTime[i]);
|
||||
assert (softIrqTime >= this->softIrqTime[i]);
|
||||
assert (stealTime >= this->stealTime[i]);
|
||||
assert (irq >= this->irqTime[i]);
|
||||
assert (softIrq >= this->softIrqTime[i]);
|
||||
assert (steal >= this->stealTime[i]);
|
||||
this->userPeriod[i] = usertime - this->userTime[i];
|
||||
this->nicePeriod[i] = nicetime - this->niceTime[i];
|
||||
this->systemPeriod[i] = systemtime - this->systemTime[i];
|
||||
|
|
|
@ -54,6 +54,10 @@ in the source distribution for its full text.
|
|||
#define MAX_READ 2048
|
||||
#endif
|
||||
|
||||
#ifndef PER_PROCESSOR_FIELDS
|
||||
#define PER_PROCESSOR_FIELDS 20
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef DEBUG
|
||||
|
@ -71,6 +75,7 @@ typedef struct ProcessList_ {
|
|||
int totalTasks;
|
||||
int runningTasks;
|
||||
|
||||
// Must match number of PER_PROCESSOR_FIELDS constant
|
||||
unsigned long long int* totalTime;
|
||||
unsigned long long int* userTime;
|
||||
unsigned long long int* systemTime;
|
||||
|
|
Loading…
Reference in New Issue