33 |
|
|
34 |
|
typedef enum { |
35 |
|
LONG_LONG = 0, |
36 |
+ |
BYTES, |
37 |
|
TIME_T, |
38 |
|
FLOAT, |
39 |
|
DOUBLE, |
73 |
|
int use_cpu_percent = 0; |
74 |
|
int use_diffs = 0; |
75 |
|
long float_scale_factor = 0; |
76 |
+ |
long long bytes_scale_factor = 0; |
77 |
|
|
78 |
|
/* Exit with an error message. */ |
79 |
|
void die(const char *s) { |
217 |
|
sg_mem_stats *mem = sg_get_mem_stats(); |
218 |
|
|
219 |
|
if (mem != NULL) { |
220 |
< |
add_stat(LONG_LONG, &mem->total, "mem", "total", NULL); |
221 |
< |
add_stat(LONG_LONG, &mem->free, "mem", "free", NULL); |
222 |
< |
add_stat(LONG_LONG, &mem->used, "mem", "used", NULL); |
223 |
< |
add_stat(LONG_LONG, &mem->cache, "mem", "cache", NULL); |
220 |
> |
add_stat(BYTES, &mem->total, "mem", "total", NULL); |
221 |
> |
add_stat(BYTES, &mem->free, "mem", "free", NULL); |
222 |
> |
add_stat(BYTES, &mem->used, "mem", "used", NULL); |
223 |
> |
add_stat(BYTES, &mem->cache, "mem", "cache", NULL); |
224 |
|
} |
225 |
|
} |
226 |
|
|
247 |
|
sg_swap_stats *swap = sg_get_swap_stats(); |
248 |
|
|
249 |
|
if (swap != NULL) { |
250 |
< |
add_stat(LONG_LONG, &swap->total, "swap", "total", NULL); |
251 |
< |
add_stat(LONG_LONG, &swap->used, "swap", "used", NULL); |
252 |
< |
add_stat(LONG_LONG, &swap->free, "swap", "free", NULL); |
250 |
> |
add_stat(BYTES, &swap->total, "swap", "total", NULL); |
251 |
> |
add_stat(BYTES, &swap->used, "swap", "used", NULL); |
252 |
> |
add_stat(BYTES, &swap->free, "swap", "free", NULL); |
253 |
|
} |
254 |
|
} |
255 |
|
|
301 |
|
"fs", name, "fs_type", NULL); |
302 |
|
add_stat(STRING, &disk[i].mnt_point, |
303 |
|
"fs", name, "mnt_point", NULL); |
304 |
< |
add_stat(LONG_LONG, &disk[i].size, |
304 |
> |
add_stat(BYTES, &disk[i].size, |
305 |
|
"fs", name, "size", NULL); |
306 |
< |
add_stat(LONG_LONG, &disk[i].used, |
306 |
> |
add_stat(BYTES, &disk[i].used, |
307 |
|
"fs", name, "used", NULL); |
308 |
< |
add_stat(LONG_LONG, &disk[i].avail, |
308 |
> |
add_stat(BYTES, &disk[i].avail, |
309 |
|
"fs", name, "avail", NULL); |
310 |
|
add_stat(LONG_LONG, &disk[i].total_inodes, |
311 |
|
"fs", name, "total_inodes", NULL); |
331 |
|
|
332 |
|
add_stat(STRING, &diskio[i].disk_name, |
333 |
|
"disk", name, "disk_name", NULL); |
334 |
< |
add_stat(LONG_LONG, &diskio[i].read_bytes, |
334 |
> |
add_stat(BYTES, &diskio[i].read_bytes, |
335 |
|
"disk", name, "read_bytes", NULL); |
336 |
< |
add_stat(LONG_LONG, &diskio[i].write_bytes, |
336 |
> |
add_stat(BYTES, &diskio[i].write_bytes, |
337 |
|
"disk", name, "write_bytes", NULL); |
338 |
|
add_stat(TIME_T, &diskio[i].systime, |
339 |
|
"disk", name, "systime", NULL); |
367 |
|
|
368 |
|
add_stat(STRING, &io[i].interface_name, |
369 |
|
"net", name, "interface_name", NULL); |
370 |
< |
add_stat(LONG_LONG, &io[i].tx, |
370 |
> |
add_stat(BYTES, &io[i].tx, |
371 |
|
"net", name, "tx", NULL); |
372 |
< |
add_stat(LONG_LONG, &io[i].rx, |
372 |
> |
add_stat(BYTES, &io[i].rx, |
373 |
|
"net", name, "rx", NULL); |
374 |
|
add_stat(LONG_LONG, &io[i].ipackets, |
375 |
|
"net", name, "ipackets", NULL); |
492 |
|
void print_stat_value(const stat *s) { |
493 |
|
void *v = s->stat; |
494 |
|
double fv; |
495 |
< |
long l; |
495 |
> |
long lv; |
496 |
> |
long long llv; |
497 |
|
|
498 |
|
switch (s->type) { |
499 |
|
case LONG_LONG: |
500 |
|
printf("%lld", *(long long *)v); |
501 |
|
break; |
502 |
+ |
case BYTES: |
503 |
+ |
llv = *(long long *)v; |
504 |
+ |
if (bytes_scale_factor != 0) { |
505 |
+ |
llv /= bytes_scale_factor; |
506 |
+ |
} |
507 |
+ |
printf("%lld", llv); |
508 |
+ |
break; |
509 |
|
case TIME_T: |
510 |
|
/* FIXME option for formatted time? */ |
511 |
< |
l = *(time_t *)v; |
512 |
< |
printf("%ld", l); |
511 |
> |
lv = *(time_t *)v; |
512 |
> |
printf("%ld", lv); |
513 |
|
break; |
514 |
|
case FLOAT: |
515 |
|
case DOUBLE: |
640 |
|
" -p Display CPU usage differences as percentages rather than\n" |
641 |
|
" absolute values\n" |
642 |
|
" -f SCALE Display floating-point values as integers scaled by FACTOR\n" |
643 |
+ |
" -K Display byte counts in kibibytes\n" |
644 |
+ |
" -M Display byte counts in mibibytes\n" |
645 |
+ |
" -G Display byte counts in gibibytes\n" |
646 |
|
"\n"); |
647 |
|
printf("Version %s - report bugs to <%s>.\n", |
648 |
|
PACKAGE_VERSION, PACKAGE_BUGREPORT); |
652 |
|
int main(int argc, char **argv) { |
653 |
|
opterr = 0; |
654 |
|
while (1) { |
655 |
< |
int c = getopt(argc, argv, "lbmunsot:pf:"); |
655 |
> |
int c = getopt(argc, argv, "lbmunsot:pf:KMG"); |
656 |
|
if (c == -1) |
657 |
|
break; |
658 |
|
switch (c) { |
685 |
|
break; |
686 |
|
case 'f': |
687 |
|
float_scale_factor = atol(optarg); |
688 |
+ |
break; |
689 |
+ |
case 'K': |
690 |
+ |
bytes_scale_factor = 1024; |
691 |
+ |
break; |
692 |
+ |
case 'M': |
693 |
+ |
bytes_scale_factor = 1024 * 1024; |
694 |
+ |
break; |
695 |
+ |
case 'G': |
696 |
+ |
bytes_scale_factor = 1024 * 1024 * 1024; |
697 |
|
break; |
698 |
|
default: |
699 |
|
usage(); |