ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/libstatgrab/src/statgrab/statgrab.c
(Generate patch)

Comparing projects/libstatgrab/src/statgrab/statgrab.c (file contents):
Revision 1.26 by tdb, Wed Apr 7 15:50:26 2004 UTC vs.
Revision 1.29 by ats, Tue Aug 10 18:50:37 2004 UTC

# Line 71 | Line 71 | repeat_mode_type repeat_mode = REPEAT_NONE;
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) {
# Line 352 | Line 353 | void populate_proc() {
353   }
354  
355   void populate_net() {
356 <        int n, i;
356 >        int num_io, num_iface, i;
357          sg_network_io_stats *io;
358          sg_network_iface_stats *iface;
359  
360 <        io = use_diffs ? sg_get_network_io_stats_diff(&n)
361 <                       : sg_get_network_io_stats(&n);
360 >        io = use_diffs ? sg_get_network_io_stats_diff(&num_io)
361 >                       : sg_get_network_io_stats(&num_io);
362          if (io != NULL) {
363 <                for (i = 0; i < n; i++) {
363 >                for (i = 0; i < num_io; i++) {
364                          const char *name = io[i].interface_name;
365          
366                          add_stat(STRING, &io[i].interface_name,
# Line 383 | Line 384 | void populate_net() {
384                  }
385          }
386  
387 <        iface = sg_get_network_iface_stats(&n);
387 >        iface = sg_get_network_iface_stats(&num_iface);
388          if (iface != NULL) {
389 <                for (i = 0; i < n; i++) {
389 >                for (i = 0; i < num_iface; i++) {
390                          const char *name = iface[i].interface_name;
391 +                        int had_io = 0, j;
392  
393 +                        /* If there wasn't a corresponding io stat,
394 +                           add interface_name from here. */
395 +                        if (io != NULL) {
396 +                                for (j = 0; j < num_io; j++) {
397 +                                        if (strcmp(io[j].interface_name,
398 +                                                   name) == 0) {
399 +                                                had_io = 1;
400 +                                                break;
401 +                                        }
402 +                                }
403 +                        }
404 +                        if (!had_io) {
405 +                                add_stat(STRING, &iface[i].interface_name,
406 +                                        "net", name, "interface_name", NULL);
407 +                        }
408 +
409                          add_stat(INT, &iface[i].speed,
410                                   "net", name, "speed", NULL);
411                          add_stat(BOOL, &iface[i].up,
# Line 471 | Line 489 | void get_stats() {
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) {
# Line 483 | Line 502 | void print_stat_value(const stat *s) {
502                  printf("%ld", l);
503                  break;
504          case FLOAT:
486                printf("%f", *(float *)v);
487                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? */
# Line 603 | Line 629 | void usage() {
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);
# Line 612 | Line 639 | void usage() {
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) {
# Line 643 | Line 670 | int main(int argc, char **argv) {
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();
678                  }
# Line 665 | Line 695 | int main(int argc, char **argv) {
695  
696          select_interesting(argc - optind, &argv[optind]);
697  
698 <        /* We don't care if statgrab_init fails, because we can just display
698 >        /* We don't care if sg_init fails, because we can just display
699             the statistics that can be read as non-root. */
700          sg_init();
701          if (sg_drop_privileges() != 0)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines