Merge branch 'master' into freebsd

This commit is contained in:
Hisham Muhammad 2014-11-27 16:32:32 -02:00
commit 8a2e235a48
1 changed files with 42 additions and 33 deletions

View File

@ -571,17 +571,13 @@ 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;
assert(cpus > 0);
{
char buffer[128]; char buffer[128];
while (fgets(buffer, 128, file)) { while (fgets(buffer, 128, file)) {
@ -610,16 +606,21 @@ void ProcessList_scan(ProcessList* this) {
break; 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) {
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++) {