Commit 8a2e235a authored by Hisham Muhammad's avatar Hisham Muhammad
Browse files

Merge branch 'master' into freebsd

parents 8915b293 ff4d1b46
...@@ -571,55 +571,56 @@ static bool LinuxProcessList_processEntries(ProcessList* this, const char* dirna ...@@ -571,55 +571,56 @@ static bool LinuxProcessList_processEntries(ProcessList* this, const char* dirna
return true; return true;
} }
void ProcessList_scan(ProcessList* this) { static inline void LinuxProcessList_scanMemoryInfo(ProcessList* this) {
unsigned long long int usertime, nicetime, systemtime, idletime;
unsigned long long int swapFree = 0; unsigned long long int swapFree = 0;
FILE* file = fopen(PROCMEMINFOFILE, "r"); FILE* file = fopen(PROCMEMINFOFILE, "r");
if (file == NULL) { if (file == NULL) {
CRT_fatalError("Cannot open " PROCMEMINFOFILE); CRT_fatalError("Cannot open " PROCMEMINFOFILE);
} }
int cpus = this->cpuCount; char buffer[128];
assert(cpus > 0); while (fgets(buffer, 128, file)) {
{
char buffer[128]; switch (buffer[0]) {
while (fgets(buffer, 128, file)) { case 'M':
if (String_startsWith(buffer, "MemTotal:"))
switch (buffer[0]) { sscanf(buffer, "MemTotal: %32llu kB", &this->totalMem);
case 'M': else if (String_startsWith(buffer, "MemFree:"))
if (String_startsWith(buffer, "MemTotal:")) sscanf(buffer, "MemFree: %32llu kB", &this->freeMem);
sscanf(buffer, "MemTotal: %32llu kB", &this->totalMem); else if (String_startsWith(buffer, "MemShared:"))
else if (String_startsWith(buffer, "MemFree:")) sscanf(buffer, "MemShared: %32llu kB", &this->sharedMem);
sscanf(buffer, "MemFree: %32llu kB", &this->freeMem); break;
else if (String_startsWith(buffer, "MemShared:")) case 'B':
sscanf(buffer, "MemShared: %32llu kB", &this->sharedMem); if (String_startsWith(buffer, "Buffers:"))
break; sscanf(buffer, "Buffers: %32llu kB", &this->buffersMem);
case 'B': break;
if (String_startsWith(buffer, "Buffers:")) case 'C':
sscanf(buffer, "Buffers: %32llu kB", &this->buffersMem); if (String_startsWith(buffer, "Cached:"))
break; sscanf(buffer, "Cached: %32llu kB", &this->cachedMem);
case 'C': break;
if (String_startsWith(buffer, "Cached:")) case 'S':
sscanf(buffer, "Cached: %32llu kB", &this->cachedMem); if (String_startsWith(buffer, "SwapTotal:"))
break; sscanf(buffer, "SwapTotal: %32llu kB", &this->totalSwap);
case 'S': if (String_startsWith(buffer, "SwapFree:"))
if (String_startsWith(buffer, "SwapTotal:")) sscanf(buffer, "SwapFree: %32llu kB", &swapFree);
sscanf(buffer, "SwapTotal: %32llu kB", &this->totalSwap); break;
if (String_startsWith(buffer, "SwapFree:"))
sscanf(buffer, "SwapFree: %32llu kB", &swapFree);
break;
}
} }
} }
this->usedMem = this->totalMem - this->freeMem; this->usedMem = this->totalMem - this->freeMem;
this->usedSwap = this->totalSwap - swapFree; this->usedSwap = this->totalSwap - swapFree;
fclose(file); fclose(file);
}
file = fopen(PROCSTATFILE, "r"); static inline double LinuxProcessList_scanCPUTime(ProcessList* this) {
unsigned long long int usertime, nicetime, systemtime, idletime;
FILE* file = fopen(PROCSTATFILE, "r");
if (file == NULL) { if (file == NULL) {
CRT_fatalError("Cannot open " PROCSTATFILE); CRT_fatalError("Cannot open " PROCSTATFILE);
} }
int cpus = this->cpuCount;
assert(cpus > 0);
for (int i = 0; i <= cpus; i++) { for (int i = 0; i <= cpus; i++) {
char buffer[256]; char buffer[256];
int cpuid; int cpuid;
...@@ -684,6 +685,14 @@ void ProcessList_scan(ProcessList* this) { ...@@ -684,6 +685,14 @@ void ProcessList_scan(ProcessList* this) {
cpuData->totalTime = totaltime; 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;
}
void ProcessList_scan(ProcessList* this) {
LinuxProcessList_scanMemoryInfo(this);
double period = LinuxProcessList_scanCPUTime(this);
// mark all process as "dirty" // mark all process as "dirty"
for (int i = 0; i < Vector_size(this->processes); i++) { for (int i = 0; i < Vector_size(this->processes); i++) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment