summaryrefslogtreecommitdiffstats
path: root/linux/LinuxProcessList.c
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2014-11-27 16:28:32 -0200
committerHisham Muhammad <hisham@gobolinux.org>2014-11-27 16:28:32 -0200
commit6afacee50d9039e21a9dc40df360f718075da875 (patch)
tree7fcf51dc8806329a6713c13bf5a7e11dca8def0d /linux/LinuxProcessList.c
parenta75161f8628d04a77bb85ff68a25aa0985b9e15d (diff)
A little refactoring
Diffstat (limited to 'linux/LinuxProcessList.c')
-rw-r--r--linux/LinuxProcessList.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c
index 7bad637d..2b0f3f0c 100644
--- a/linux/LinuxProcessList.c
+++ b/linux/LinuxProcessList.c
@@ -571,10 +571,7 @@ static bool LinuxProcessList_processEntries(ProcessList* this, const char* dirna
return true;
}
-void ProcessList_scan(ProcessList* this) {
- unsigned long long int usertime, nicetime, systemtime, idletime;
- unsigned long long int swapFree = 0;
-
+static inline void LinuxProcessList_scanMemoryInfo(ProcessList* this) {
FILE* file = fopen(PROCMEMINFOFILE, "r");
if (file == NULL) {
CRT_fatalError("Cannot open " PROCMEMINFOFILE);
@@ -615,8 +612,10 @@ void ProcessList_scan(ProcessList* this) {
this->usedMem = this->totalMem - this->freeMem;
this->usedSwap = this->totalSwap - swapFree;
fclose(file);
+}
- file = fopen(PROCSTATFILE, "r");
+static inline double LinuxProcessList_readCPUTime(ProcessList* this) {
+ FILE* file = fopen(PROCSTATFILE, "r");
if (file == NULL) {
CRT_fatalError("Cannot open " PROCSTATFILE);
}
@@ -684,6 +683,16 @@ void ProcessList_scan(ProcessList* this) {
cpuData->totalTime = totaltime;
}
double period = (double)this->cpus[0].totalPeriod / cpus; fclose(file);
+ return period;
+}
+
+void ProcessList_scan(ProcessList* this) {
+ unsigned long long int usertime, nicetime, systemtime, idletime;
+ unsigned long long int swapFree = 0;
+
+ LinuxProcessList_scanMemoryInfo(this);
+
+ LinuxProcessList_scanCPUTime(this);
// mark all process as "dirty"
for (int i = 0; i < Vector_size(this->processes); i++) {