Build fixes.

This commit is contained in:
Hisham Muhammad 2014-11-27 16:31:42 -02:00
parent 6afacee50d
commit ff4d1b466f
1 changed files with 34 additions and 34 deletions

View File

@ -572,40 +572,38 @@ static bool LinuxProcessList_processEntries(ProcessList* this, const char* dirna
} }
static inline void LinuxProcessList_scanMemoryInfo(ProcessList* this) { static inline void LinuxProcessList_scanMemoryInfo(ProcessList* this) {
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];
while (fgets(buffer, 128, file)) {
switch (buffer[0]) { switch (buffer[0]) {
case 'M': case 'M':
if (String_startsWith(buffer, "MemTotal:")) if (String_startsWith(buffer, "MemTotal:"))
sscanf(buffer, "MemTotal: %32llu kB", &this->totalMem); sscanf(buffer, "MemTotal: %32llu kB", &this->totalMem);
else if (String_startsWith(buffer, "MemFree:")) else if (String_startsWith(buffer, "MemFree:"))
sscanf(buffer, "MemFree: %32llu kB", &this->freeMem); sscanf(buffer, "MemFree: %32llu kB", &this->freeMem);
else if (String_startsWith(buffer, "MemShared:")) else if (String_startsWith(buffer, "MemShared:"))
sscanf(buffer, "MemShared: %32llu kB", &this->sharedMem); sscanf(buffer, "MemShared: %32llu kB", &this->sharedMem);
break; break;
case 'B': case 'B':
if (String_startsWith(buffer, "Buffers:")) if (String_startsWith(buffer, "Buffers:"))
sscanf(buffer, "Buffers: %32llu kB", &this->buffersMem); sscanf(buffer, "Buffers: %32llu kB", &this->buffersMem);
break; break;
case 'C': case 'C':
if (String_startsWith(buffer, "Cached:")) if (String_startsWith(buffer, "Cached:"))
sscanf(buffer, "Cached: %32llu kB", &this->cachedMem); sscanf(buffer, "Cached: %32llu kB", &this->cachedMem);
break; break;
case 'S': case 'S':
if (String_startsWith(buffer, "SwapTotal:")) if (String_startsWith(buffer, "SwapTotal:"))
sscanf(buffer, "SwapTotal: %32llu kB", &this->totalSwap); sscanf(buffer, "SwapTotal: %32llu kB", &this->totalSwap);
if (String_startsWith(buffer, "SwapFree:")) if (String_startsWith(buffer, "SwapFree:"))
sscanf(buffer, "SwapFree: %32llu kB", &swapFree); sscanf(buffer, "SwapFree: %32llu kB", &swapFree);
break; break;
}
} }
} }
@ -614,11 +612,15 @@ static inline void LinuxProcessList_scanMemoryInfo(ProcessList* this) {
fclose(file); fclose(file);
} }
static inline double LinuxProcessList_readCPUTime(ProcessList* this) { static inline double LinuxProcessList_scanCPUTime(ProcessList* this) {
unsigned long long int usertime, nicetime, systemtime, idletime;
FILE* file = fopen(PROCSTATFILE, "r"); 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;
@ -687,12 +689,10 @@ static inline double LinuxProcessList_readCPUTime(ProcessList* this) {
} }
void ProcessList_scan(ProcessList* this) { void ProcessList_scan(ProcessList* this) {
unsigned long long int usertime, nicetime, systemtime, idletime;
unsigned long long int swapFree = 0;
LinuxProcessList_scanMemoryInfo(this); LinuxProcessList_scanMemoryInfo(this);
LinuxProcessList_scanCPUTime(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++) {