71 |
|
int repeat_time = 1; |
72 |
|
int use_cpu_percent = 0; |
73 |
|
int use_diffs = 0; |
74 |
+ |
long float_scale_factor = 0; |
75 |
|
|
76 |
|
/* Exit with an error message. */ |
77 |
|
void die(const char *s) { |
489 |
|
/* Print the value of a stat. */ |
490 |
|
void print_stat_value(const stat *s) { |
491 |
|
void *v = s->stat; |
492 |
+ |
double fv; |
493 |
|
long l; |
494 |
|
|
495 |
|
switch (s->type) { |
502 |
|
printf("%ld", l); |
503 |
|
break; |
504 |
|
case FLOAT: |
503 |
– |
printf("%f", *(float *)v); |
504 |
– |
break; |
505 |
|
case DOUBLE: |
506 |
< |
printf("%f", *(double *)v); |
506 |
> |
if (s->type == FLOAT) { |
507 |
> |
fv = *(float *)v; |
508 |
> |
} else { |
509 |
> |
fv = *(double *)v; |
510 |
> |
} |
511 |
> |
if (float_scale_factor != 0) { |
512 |
> |
printf("%ld", (long)(float_scale_factor * fv)); |
513 |
> |
} else { |
514 |
> |
printf("%f", fv); |
515 |
> |
} |
516 |
|
break; |
517 |
|
case STRING: |
518 |
|
/* FIXME escaping? */ |
629 |
|
" -t DELAY When repeating, wait DELAY seconds between updates (default 1)\n" |
630 |
|
" -p Display CPU usage differences as percentages rather than\n" |
631 |
|
" absolute values\n" |
632 |
+ |
" -f SCALE Display floating-point values as integers scaled by FACTOR\n" |
633 |
|
"\n"); |
634 |
|
printf("Version %s - report bugs to <%s>.\n", |
635 |
|
PACKAGE_VERSION, PACKAGE_BUGREPORT); |
639 |
|
int main(int argc, char **argv) { |
640 |
|
opterr = 0; |
641 |
|
while (1) { |
642 |
< |
int c = getopt(argc, argv, "lbmunsot:p"); |
642 |
> |
int c = getopt(argc, argv, "lbmunsot:pf:"); |
643 |
|
if (c == -1) |
644 |
|
break; |
645 |
|
switch (c) { |
669 |
|
break; |
670 |
|
case 'p': |
671 |
|
use_cpu_percent = 1; |
672 |
+ |
break; |
673 |
+ |
case 'f': |
674 |
+ |
float_scale_factor = atol(optarg); |
675 |
|
break; |
676 |
|
default: |
677 |
|
usage(); |