Lines 1-87
Link Here
|
1 |
--- ./ProcessList.c.orig 2010-11-26 18:50:25.000000000 +0200 |
|
|
2 |
+++ ./ProcessList.c 2011-08-11 13:07:08.000000000 +0300 |
3 |
@@ -32,6 +32,19 @@ |
4 |
#include "debug.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 |
|
22 |
#ifndef PROCDIR |
23 |
@@ -665,15 +678,24 @@ |
24 |
|
25 |
void ProcessList_scan(ProcessList* this) { |
26 |
unsigned long long int usertime, nicetime, systemtime, systemalltime, idlealltime, idletime, totaltime, virtalltime; |
27 |
+ #ifndef __FreeBSD__ |
28 |
unsigned long long int swapFree = 0; |
29 |
+ #endif |
30 |
+ int cpus = this->cpuCount; |
31 |
+ FILE* file = NULL; |
32 |
|
33 |
- FILE* file = fopen(PROCMEMINFOFILE, "r"); |
34 |
+ #ifdef __FreeBSD__ |
35 |
+ kvm_t *kd = NULL; |
36 |
+ struct kvm_swap kvmswapinfo[1]; |
37 |
+ size_t len = 0; |
38 |
+ #endif |
39 |
+ |
40 |
+ #ifndef __FreeBSD__ |
41 |
+ file = fopen(PROCMEMINFOFILE, "r"); |
42 |
assert(file != NULL); |
43 |
- int cpus = this->cpuCount; |
44 |
{ |
45 |
char buffer[128]; |
46 |
while (fgets(buffer, 128, file)) { |
47 |
- |
48 |
switch (buffer[0]) { |
49 |
case 'M': |
50 |
if (String_startsWith(buffer, "MemTotal:")) |
51 |
@@ -700,10 +722,35 @@ |
52 |
} |
53 |
} |
54 |
} |
55 |
+ fclose(file); |
56 |
+ #endif |
57 |
|
58 |
+ #ifdef __FreeBSD__ |
59 |
+ len = sizeof(this->totalMem); |
60 |
+ SYSCTLBYNAME("vm.stats.vm.v_page_count", this->totalMem, len); |
61 |
+ this->totalMem *= PAGE_SIZE / KB; |
62 |
+ len = sizeof(this->cachedMem); |
63 |
+ SYSCTLBYNAME("vm.stats.vm.v_cache_count", this->cachedMem, len); |
64 |
+ this->cachedMem *= PAGE_SIZE / KB; |
65 |
+ len = sizeof(this->buffersMem); |
66 |
+ SYSCTLBYNAME("vfs.bufspace", this->buffersMem, len); |
67 |
+ this->buffersMem /= KB; |
68 |
+ len = sizeof(this->usedMem); |
69 |
+ SYSCTLBYNAME("vm.stats.vm.v_active_count", this->usedMem, len); |
70 |
+ this->usedMem = this->usedMem * PAGE_SIZE / KB + this->cachedMem + this->buffersMem; |
71 |
+ this->freeMem = this->totalMem - this->usedMem; |
72 |
+ kd = kvm_open(NULL, _PATH_DEVNULL, NULL, O_RDONLY, NULL); |
73 |
+ assert(kd != NULL); |
74 |
+ kvm_getswapinfo(kd, kvmswapinfo, 1, 0); |
75 |
+ this->totalSwap = kvmswapinfo[0].ksw_total * PAGE_SIZE / KB; |
76 |
+ this->usedSwap = kvmswapinfo[0].ksw_used * PAGE_SIZE / KB; |
77 |
+ kvm_close(kd); |
78 |
+ #endif |
79 |
+ |
80 |
+ #ifndef __FreeBSD__ |
81 |
this->usedMem = this->totalMem - this->freeMem; |
82 |
this->usedSwap = this->totalSwap - swapFree; |
83 |
- fclose(file); |
84 |
+ #endif |
85 |
|
86 |
file = fopen(PROCSTATFILE, "r"); |
87 |
assert(file != NULL); |