-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmemory.c
102 lines (88 loc) · 2.38 KB
/
memory.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include "mrbig.h"
#define WIDTH 15
#if defined (_M_IA64)
#define CPU "Itanium"
#elif defined (_M_IX86)
#define CPU "x86"
#elif defined (_M_X64)
#define CPU "x64"
#else
#define CPU "unknown"
#endif
/* memory
green Thu Nov 13 13:35:25 CET 2008 - Memory OK
Memory Used Total Percentage
&green Physical 1730M 2011M 86%
&green Actual 762M 2011M 37%
&green Swap 0M 2047M 0%
*/
static void append_limits(char *a, size_t n)
{
snprcat(a, n, "\nLimits:\n");
snprcat(a, n, "Yellow RAM: %d\n", memyellow);
snprcat(a, n, "Red RAM: %d\n", memred);
}
void memory(void)
{
char b[5000];
int n = sizeof b;
char r[1000];
char *color = "green";
MEMORYSTATUSEX statex;
DWORD memusage;
double pused, ptotal, sused, stotal;
int ppct, spct;
if (debug > 1) mrlog("memory(%p, %d)", b, n);
if (get_option("no_memory", 0)) {
mrsend(mrmachine, "memory", "clear", "option no_memory\n");
return;
}
r[0] = '\0';
statex.dwLength = sizeof statex;
//GlobalMemoryStatus(&stat);
GlobalMemoryStatusEx(&statex);
#if 0
memusage = 100-stat.dwAvailPhys/(stat.dwTotalPhys/100);
#else
memusage = statex.dwMemoryLoad;
#endif
if (memusage > memred) {
color = "red";
} else if (memusage > memyellow && !strcmp(color, "green")) {
color = "yellow";
}
ptotal = statex.ullTotalPhys;
pused = ptotal-statex.ullAvailPhys;
stotal = statex.ullTotalPageFile;
sused = stotal-statex.ullAvailPageFile;
ppct = 100*pused/ptotal;
spct = 100*sused/stotal;
b[0] = '\0';
snprcat(b, n,
"%s\n\n"
" Memory Used Total Percentage\n"
"&%s Physical %.0fM %.0fM %d%%\n"
"&%s Swap %.0fM %.0fM %d%%\n",
now,
color, pused/1024/1024, ptotal/1024/1024, ppct,
"green", sused/1024/1024, stotal/1024/1024, spct);
#if 0
#if 0
WIDTH, (double)stat.dwTotalPhys,
WIDTH, (double)stat.dwAvailPhys,
WIDTH, (double)stat.dwTotalPageFile,
WIDTH, (double)stat.dwAvailPageFile,
WIDTH, (double)stat.dwTotalVirtual,
WIDTH, (double)stat.dwAvailVirtual,
#else
WIDTH, (double)statex.ullTotalPhys,
WIDTH, (double)statex.ullAvailPhys,
WIDTH, (double)statex.ullTotalPageFile,
WIDTH, (double)statex.ullAvailPageFile,
WIDTH, (double)statex.ullTotalVirtual,
WIDTH, (double)statex.ullAvailVirtual,
#endif
#endif
append_limits(b, n);
mrsend(mrmachine, "memory", color, b);
}