Lines 1-84
Link Here
|
1 |
--- ProcessList.c.orig 2013-04-21 03:39:12.000000000 +0800 |
1 |
--- ProcessList.c.orig 2014-10-19 02:09:17.000000000 +0800 |
2 |
+++ ProcessList.c 2013-04-21 03:41:41.000000000 +0800 |
2 |
+++ ProcessList.c 2014-10-19 02:11:07.000000000 +0800 |
3 |
@@ -25,6 +25,19 @@ |
3 |
@@ -804,8 +804,6 @@ |
4 |
#include <time.h> |
|
|
5 |
#include <assert.h> |
6 |
|
7 |
+#ifndef PAGE_SIZE |
8 |
+#define PAGE_SIZE sysconf(_SC_PAGESIZE) |
9 |
+#endif |
10 |
+ |
11 |
+#ifdef __FreeBSD__ |
12 |
+#define KB 1024 |
13 |
+#define SYSCTLBYNAME(name, var, len) sysctlbyname(name, &(var), &(len), NULL, 0) |
14 |
+#include <kvm.h> |
15 |
+#include <paths.h> |
16 |
+#include <fcntl.h> |
17 |
+#include <sys/sysctl.h> |
18 |
+#endif |
19 |
+ |
20 |
/*{ |
21 |
#include "Vector.h" |
22 |
#include "Hashtable.h" |
23 |
@@ -685,7 +698,7 @@ |
24 |
unsigned long long int lasttimes = (process->utime + process->stime); |
4 |
unsigned long long int lasttimes = (process->utime + process->stime); |
25 |
if (! ProcessList_readStatFile(process, dirname, name, command)) |
5 |
if (! ProcessList_readStatFile(process, dirname, name, command)) |
26 |
goto errorReadingProcess; |
6 |
goto errorReadingProcess; |
27 |
- Process_updateIOPriority(process); |
7 |
- if (this->flags & PROCESS_FLAG_IOPRIO) |
28 |
+// Process_updateIOPriority(process); |
8 |
- Process_updateIOPriority(process); |
29 |
float percent_cpu = (process->utime + process->stime - lasttimes) / period * 100.0; |
9 |
float percent_cpu = (process->utime + process->stime - lasttimes) / period * 100.0; |
30 |
process->percent_cpu = MAX(MIN(percent_cpu, cpus*100.0), 0.0); |
10 |
process->percent_cpu = MAX(MIN(percent_cpu, cpus*100.0), 0.0); |
31 |
if (isnan(process->percent_cpu)) process->percent_cpu = 0.0; |
11 |
if (isnan(process->percent_cpu)) process->percent_cpu = 0.0; |
32 |
@@ -764,13 +777,15 @@ |
|
|
33 |
|
34 |
void ProcessList_scan(ProcessList* this) { |
35 |
unsigned long long int usertime, nicetime, systemtime, systemalltime, idlealltime, idletime, totaltime, virtalltime; |
36 |
- unsigned long long int swapFree = 0; |
37 |
+ int cpus = this->cpuCount; |
38 |
+ FILE* file = NULL; |
39 |
|
40 |
- FILE* file = fopen(PROCMEMINFOFILE, "r"); |
41 |
+ #ifndef __FreeBSD__ |
42 |
+ unsigned long long int swapFree = 0; |
43 |
+ file = fopen(PROCMEMINFOFILE, "r"); |
44 |
if (file == NULL) { |
45 |
CRT_fatalError("Cannot open " PROCMEMINFOFILE); |
46 |
} |
47 |
- int cpus = this->cpuCount; |
48 |
{ |
49 |
char buffer[128]; |
50 |
while (fgets(buffer, 128, file)) { |
51 |
@@ -805,6 +820,33 @@ |
52 |
this->usedMem = this->totalMem - this->freeMem; |
53 |
this->usedSwap = this->totalSwap - swapFree; |
54 |
fclose(file); |
55 |
+ #endif |
56 |
+ |
57 |
+ #ifdef __FreeBSD__ |
58 |
+ kvm_t *kd = NULL; |
59 |
+ struct kvm_swap kvmswapinfo[1]; |
60 |
+ size_t len = 0; |
61 |
+ |
62 |
+ kd = kvm_open(NULL, _PATH_DEVNULL, NULL, O_RDONLY, NULL); |
63 |
+ assert(kd != NULL); |
64 |
+ kvm_getswapinfo(kd, kvmswapinfo, 1, 0); |
65 |
+ this->totalSwap = kvmswapinfo[0].ksw_total * (PAGE_SIZE / KB); |
66 |
+ this->usedSwap = kvmswapinfo[0].ksw_used * (PAGE_SIZE / KB); |
67 |
+ kvm_close(kd); |
68 |
+ len = sizeof(this->totalMem); |
69 |
+ SYSCTLBYNAME("vm.stats.vm.v_page_count", this->totalMem, len); |
70 |
+ this->totalMem *= PAGE_SIZE / KB; |
71 |
+ len = sizeof(this->cachedMem); |
72 |
+ SYSCTLBYNAME("vm.stats.vm.v_cache_count", this->cachedMem, len); |
73 |
+ this->cachedMem *= PAGE_SIZE / KB; |
74 |
+ len = sizeof(this->buffersMem); |
75 |
+ SYSCTLBYNAME("vfs.bufspace", this->buffersMem, len); |
76 |
+ this->buffersMem /= KB; |
77 |
+ len = sizeof(this->usedMem); |
78 |
+ SYSCTLBYNAME("vm.stats.vm.v_active_count", this->usedMem, len); |
79 |
+ this->usedMem = this->usedMem * PAGE_SIZE / KB + this->cachedMem + this->buffersMem; |
80 |
+ this->freeMem = this->totalMem - this->usedMem; |
81 |
+ #endif |
82 |
|
83 |
file = fopen(PROCSTATFILE, "r"); |
84 |
if (file == NULL) { |