︙ | | | ︙ | |
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#if defined(HAVE_LIBSTATGRAB) && !defined(HAVE_LIBSTATGRAB_H)
#undef HAVE_LIBSTATGRAB
#endif
#ifndef HAVE_LIBSTATGRAB
#include <linux/kernel.h>
#include <sys/sysinfo.h>
#ifndef PROC_MEMINFO
#define PROC_MEMINFO "/proc/meminfo"
#endif
|
>
>
|
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#if defined(HAVE_LIBSTATGRAB) && !defined(HAVE_LIBSTATGRAB_H)
#undef HAVE_LIBSTATGRAB
#endif
#include <assert.h>
#include <stdint.h>
#ifndef HAVE_LIBSTATGRAB
#include <linux/kernel.h>
#include <sys/sysinfo.h>
#ifndef PROC_MEMINFO
#define PROC_MEMINFO "/proc/meminfo"
#endif
|
︙ | | | ︙ | |
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
|
#define HEADERLEN 14
#define VERSION "0.9.2"
extern char *optarg;
extern int optind, opterr, optopt;
struct freecolor_meminfo {
unsigned long totalram; /* Total usable main memory size */
unsigned long freeram; /* Available memory size */
unsigned long sharedram; /* Amount of shared memory */
unsigned long bufferram; /* Memory used by buffers */
unsigned long cachedram; /* Memory used for I/O cache */
unsigned long totalswap; /* Total swap space size */
unsigned long freeswap; /* swap space still available */
};
void bargraph(float percent, float secondper, char marks[BARLEN + HEADERLEN + 1], int usefull) {
char percentone[BARLEN + 1], percenttwo[BARLEN + 1], remain[BARLEN + 1];
unsigned int numberofmarks, numofmarkstwo, remainnum;
numberofmarks=(int) ((float) (BARLEN * (percent / 100)));
if (!usefull) {
numofmarkstwo = (int) ((float) (BARLEN * (secondper / 100)));
} else {
numofmarkstwo = (BARLEN - numberofmarks);
}
remainnum = BARLEN - (numberofmarks + numofmarkstwo);
memset(percentone, '#', numberofmarks);
memset(percenttwo, '%', numofmarkstwo);
memset(remain, '.', remainnum);
percentone[numberofmarks] = 0;
percenttwo[numofmarkstwo] = 0;
|
|
|
|
|
|
|
|
|
|
>
>
|
>
>
>
>
>
|
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
|
#define HEADERLEN 14
#define VERSION "0.9.2"
extern char *optarg;
extern int optind, opterr, optopt;
struct freecolor_meminfo {
uint64_t totalram; /* Total usable main memory size */
uint64_t freeram; /* Available memory size */
uint64_t sharedram; /* Amount of shared memory */
uint64_t bufferram; /* Memory used by buffers */
uint64_t cachedram; /* Memory used for I/O cache */
uint64_t totalswap; /* Total swap space size */
uint64_t freeswap; /* swap space still available */
};
void bargraph(double percent, double secondper, char marks[BARLEN + HEADERLEN + 1], int usefull) {
char percentone[BARLEN + 1], percenttwo[BARLEN + 1], remain[BARLEN + 1];
unsigned int numberofmarks, numofmarkstwo, remainnum;
numberofmarks=(int) ((double) (BARLEN * (percent / 100)));
assert(numberofmarks <= BARLEN);
if (!usefull) {
numofmarkstwo = (int) ((double) (BARLEN * (secondper / 100)));
} else {
numofmarkstwo = (BARLEN - numberofmarks);
}
assert(numofmarkstwo <= BARLEN);
remainnum = BARLEN - (numberofmarks + numofmarkstwo);
assert(remainnum <= BARLEN);
memset(percentone, '#', numberofmarks);
memset(percenttwo, '%', numofmarkstwo);
memset(remain, '.', remainnum);
percentone[numberofmarks] = 0;
percenttwo[numofmarkstwo] = 0;
|
︙ | | | ︙ | |
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
fclose(fd);
return(results);
}
int get_all_meminfo(struct freecolor_meminfo *retval) {
struct sysinfo sinfo;
unsigned long meminfo_cached;
meminfo_cached = get_meminfo("Cached:");
sysinfo(&sinfo);
retval->totalram = sinfo.totalram;
retval->freeram = sinfo.freeram;
retval->sharedram = sinfo.sharedram;
retval->bufferram = sinfo.bufferram;
retval->totalswap = sinfo.totalswap;
retval->freeswap = sinfo.freeswap;
retval->cachedram = meminfo_cached;
return(0);
}
#else
int get_all_meminfo(struct freecolor_meminfo *retval) {
|
|
>
>
>
>
>
>
>
|
|
|
|
|
|
|
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
fclose(fd);
return(results);
}
int get_all_meminfo(struct freecolor_meminfo *retval) {
struct sysinfo sinfo;
uint64_t meminfo_cached;
uint64_t multiplier;
meminfo_cached = get_meminfo("Cached:");
sysinfo(&sinfo);
#ifdef HAVE_SYSINFO_MEM_UNIT
multiplier = sinfo.mem_unit;
#else
multiplier = 1;
#endif
retval->totalram = sinfo.totalram * multiplier;
retval->freeram = sinfo.freeram * multiplier;
retval->sharedram = sinfo.sharedram * multiplier;
retval->bufferram = sinfo.bufferram * multiplier;
retval->totalswap = sinfo.totalswap * multiplier;
retval->freeswap = sinfo.freeswap * multiplier;
retval->cachedram = meminfo_cached;
return(0);
}
#else
int get_all_meminfo(struct freecolor_meminfo *retval) {
|
︙ | | | ︙ | |
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
|
return(0);
}
#endif
int main(int argc, char **argv) {
struct freecolor_meminfo sinfo;
unsigned long cachedbuffer, divisor;
float percentram, percentswap, percentbuffer, percentused, percentfree;
float ramfree, ramtotal, swapfree, swaptotal, doloop, totaltotal;
char realbarchart[BARLEN +HEADERLEN + 1], swapbarchart[BARLEN + HEADERLEN + 1], totalbarchart[BARLEN + HEADERLEN + 1];
int i, dototals, doold, linestoup;
int gam_ret;
/* Set defaults */
divisor = 1024;
doold = 0;
|
|
|
|
|
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
return(0);
}
#endif
int main(int argc, char **argv) {
struct freecolor_meminfo sinfo;
uint64_t cachedbuffer, divisor;
double percentram, percentswap, percentbuffer, percentused, percentfree;
double ramfree, ramtotal, swapfree, swaptotal, doloop, totaltotal;
char realbarchart[BARLEN +HEADERLEN + 1], swapbarchart[BARLEN + HEADERLEN + 1], totalbarchart[BARLEN + HEADERLEN + 1];
int i, dototals, doold, linestoup;
int gam_ret;
/* Set defaults */
divisor = 1024;
doold = 0;
|
︙ | | | ︙ | |
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
|
ramfree = sinfo.freeram;
swapfree = sinfo.freeswap;
swaptotal = sinfo.totalswap;
totaltotal = sinfo.totalram + sinfo.totalswap;
cachedbuffer = sinfo.bufferram + sinfo.cachedram;
percentram = (float) ((ramfree / ramtotal) * 100);
percentbuffer = (float) ((cachedbuffer / ramtotal) * 100);
percentfree = (float) (((sinfo.freeram + sinfo.freeswap + cachedbuffer) / totaltotal) * 100);
percentused = (int) (100 - ((int) percentfree));
if (swaptotal!=0) {
percentswap = (float) (( swapfree / swaptotal) * 100);
} else {
percentswap = 0;
}
bargraph(percentswap, 0, swapbarchart, 0);
bargraph(percentram, percentbuffer, realbarchart, 0);
bargraph((int) percentfree,(int) percentused, totalbarchart,1);
if (!doold) {
printf("Physical : \033[1;30m[\033[1;32m%s\033[1;30m]\033[1;37m %i\033[0;31m%%\033[0m\t(%lu/%lu)\n",
realbarchart,
(int) (percentram + percentbuffer),
(unsigned long) (ramfree + cachedbuffer) / divisor,
(unsigned long) ramtotal/divisor
);
printf("Swap : \033[1;30m[\033[1;32m%s\033[1;30m]\033[1;37m %i\033[0;31m%%\033[0m\t(%lu/%lu)\n",
swapbarchart,
(int) percentswap,
(unsigned long) swapfree / divisor,
(unsigned long) swaptotal/divisor
);
if (dototals) {
printf("Total : \033[1;30m[\033[1;32m%s\033[1;30m]\033[1;37m \033[0m(%lu=%lu+%lu)\n",
totalbarchart,
(unsigned long) (sinfo.totalram + sinfo.totalswap) / divisor,
(unsigned long) ((sinfo.freeram + sinfo.freeswap) / divisor),
(unsigned long) ((totaltotal - ((sinfo.freeram + sinfo.freeswap + cachedbuffer))) / divisor)
);
}
} else {
printf(" total used free shared buffers cached\n");
printf("Mem: %12lu %10lu %10lu %10lu %10lu %10lu\n",
|
|
|
|
|
|
|
|
|
|
|
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
|
ramfree = sinfo.freeram;
swapfree = sinfo.freeswap;
swaptotal = sinfo.totalswap;
totaltotal = sinfo.totalram + sinfo.totalswap;
cachedbuffer = sinfo.bufferram + sinfo.cachedram;
percentram = (double) ((ramfree / ramtotal) * 100);
percentbuffer = (double) ((cachedbuffer / ramtotal) * 100);
percentfree = (double) (((sinfo.freeram + sinfo.freeswap + cachedbuffer) / totaltotal) * 100);
percentused = (int) (100 - ((int) percentfree));
if (swaptotal!=0) {
percentswap = (double) (( swapfree / swaptotal) * 100);
} else {
percentswap = 0;
}
bargraph(percentswap, 0, swapbarchart, 0);
bargraph(percentram, percentbuffer, realbarchart, 0);
bargraph((int) percentfree,(int) percentused, totalbarchart,1);
if (!doold) {
printf("Physical : \033[1;30m[\033[1;32m%s\033[1;30m]\033[1;37m %i\033[0;31m%%\033[0m\t(%lu/%lu)\n",
realbarchart,
(int) (percentram + percentbuffer),
(unsigned long) ((ramfree + cachedbuffer) / divisor),
(unsigned long) (ramtotal / divisor)
);
printf("Swap : \033[1;30m[\033[1;32m%s\033[1;30m]\033[1;37m %i\033[0;31m%%\033[0m\t(%lu/%lu)\n",
swapbarchart,
(int) percentswap,
(unsigned long) (swapfree / divisor),
(unsigned long) (swaptotal/divisor)
);
if (dototals) {
printf("Total : \033[1;30m[\033[1;32m%s\033[1;30m]\033[1;37m \033[0m(%lu=%lu+%lu)\n",
totalbarchart,
(unsigned long) ((sinfo.totalram + sinfo.totalswap) / divisor),
(unsigned long) ((sinfo.freeram + sinfo.freeswap) / divisor),
(unsigned long) ((totaltotal - ((sinfo.freeram + sinfo.freeswap + cachedbuffer))) / divisor)
);
}
} else {
printf(" total used free shared buffers cached\n");
printf("Mem: %12lu %10lu %10lu %10lu %10lu %10lu\n",
|
︙ | | | ︙ | |
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
|
(unsigned long) ((sinfo.totalswap - sinfo.freeswap) / divisor),
(unsigned long) (sinfo.freeswap / divisor)
);
if (dototals) {
printf("Total: %11lu = (%8lu (used) + %8lu (free))\n",
(unsigned long) (totaltotal / divisor),
(((long) totaltotal) - ((sinfo.freeram+sinfo.freeswap))) / divisor,
(sinfo.freeram+sinfo.freeswap+((unsigned long) cachedbuffer)) / divisor
);
}
}
if (doloop==0) {
break;
}
|
|
|
|
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
|
(unsigned long) ((sinfo.totalswap - sinfo.freeswap) / divisor),
(unsigned long) (sinfo.freeswap / divisor)
);
if (dototals) {
printf("Total: %11lu = (%8lu (used) + %8lu (free))\n",
(unsigned long) (totaltotal / divisor),
(unsigned long) ((((long) totaltotal) - ((sinfo.freeram+sinfo.freeswap))) / divisor),
(unsigned long) ((sinfo.freeram+sinfo.freeswap+((unsigned long) cachedbuffer)) / divisor)
);
}
}
if (doloop==0) {
break;
}
|
︙ | | | ︙ | |