oga's tools
Revision | e9ffd7fe1f9e7b52310aeacf1fd585175d971795 (tree) |
---|---|
Time | 2024-05-01 00:14:05 |
Author | hyperoga <hyperoga@gmai...> |
Commiter | hyperoga |
V1.03 support ext meminfo file
@@ -4,6 +4,7 @@ | ||
4 | 4 | * 2001/12/09 V1.00 based xmem V0.33 by oga. |
5 | 5 | * 2005/09/11 V1.01 support Linux 2.6.x |
6 | 6 | * 2022/05/22 V1.02 add description to usage |
7 | + * 2024/02/05 V1.03 support ext meminfo file | |
7 | 8 | */ |
8 | 9 | |
9 | 10 | #include <stdio.h> |
@@ -13,7 +14,7 @@ | ||
13 | 14 | #include <unistd.h> |
14 | 15 | #include <errno.h> |
15 | 16 | |
16 | -#define VER "Ver 1.02" | |
17 | +#define VER "Ver 1.03" | |
17 | 18 | #define S_MEM "Memory" |
18 | 19 | #define S_SWAP "Swap" |
19 | 20 |
@@ -23,7 +24,8 @@ | ||
23 | 24 | #define dprintf if (vf) printf |
24 | 25 | |
25 | 26 | /* globals */ |
26 | -int vf = 0; /* verbose flag */ | |
27 | +int vf = 0; /* verbose flag */ | |
28 | +char *meminfo = "/proc/meminfo"; /* meminfo file V1.03-A */ | |
27 | 29 | |
28 | 30 | #ifdef COMMENT |
29 | 31 | (MB)0 10 20 30 40 50 60 70 |
@@ -163,8 +165,9 @@ void get_memdata(mem_t *mem) | ||
163 | 165 | char buf[1024]; |
164 | 166 | char *pt; |
165 | 167 | |
166 | - if (!(fp = fopen("/proc/meminfo","r"))) { | |
167 | - perror("fopen /proc/meminfo"); | |
168 | + if (!(fp = fopen(meminfo, "r"))) { /* V1.03-C */ | |
169 | + sprintf(buf, "fopen %s", meminfo); /* V1.03-C */ | |
170 | + perror(buf); /* V1.03-C */ | |
168 | 171 | exit(1); |
169 | 172 | } |
170 | 173 | fgets(buf,sizeof(buf),fp); /* skip header */ |
@@ -458,13 +461,18 @@ int main(int a, char *b[]) | ||
458 | 461 | |
459 | 462 | for (i = 1; i<a ; i++) { |
460 | 463 | if (!strncmp(b[i],"-h",2)) { |
461 | - printf("usage : cmem [-update <time>]\n"); | |
464 | + printf("usage : cmem [-update <time>] [-memfile <meminfo_file>]\n"); | |
462 | 465 | printf(" # : used\n"); |
463 | 466 | printf(" * : cached\n"); |
464 | 467 | printf(" = : buffers\n"); |
465 | 468 | printf(" . : free\n"); |
466 | 469 | exit(1); |
467 | 470 | } |
471 | + /* V1.03-A start */ | |
472 | + if (!strncmp(b[i],"-m",2) && a > i) { | |
473 | + meminfo = b[++i]; /* meminfo file*/ | |
474 | + } | |
475 | + /* V1.03-A end */ | |
468 | 476 | if (!strncmp(b[i],"-u",2) && a > i) { |
469 | 477 | wait = atoi(b[++i]); /* update time */ |
470 | 478 | } |
@@ -539,9 +547,9 @@ int main(int a, char *b[]) | ||
539 | 547 | for (i = 1; i<8; i++) { |
540 | 548 | if (UNIT >= 20 && i == 7) { |
541 | 549 | /* max 79char */ |
542 | - printf(" %-3d", i*UNIT); | |
550 | + printf(" %-4d", i*UNIT); | |
543 | 551 | } else { |
544 | - printf(" %-3d", i*UNIT); | |
552 | + printf(" %-4d", i*UNIT); | |
545 | 553 | } |
546 | 554 | } |
547 | 555 | printf("\n"); |