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.31 by ats, Tue Aug 10 21:08:54 2004 UTC vs.
Revision 1.37 by ats, Fri Mar 17 13:23:05 2006 UTC

# Line 121 | Line 121 | void add_stat(stat_type type, void *stat, ...) {
121                          break;
122                  partlen = strlen(part);
123                  memcpy(p, part, partlen);
124 <                p += partlen;
124 >
125 >                /* Replace spaces and dots with underscores. */
126 >                while (partlen-- > 0) {
127 >                        if (*p == ' ' || *p == '.')
128 >                                *p = '_';
129 >                        p++;
130 >                }
131 >
132                  *p++ = '.';
133          }
134          va_end(ap);
135          *--p = '\0';
136  
130        /* Replace spaces with underscores. */
131        for (p = name; *p != '\0'; p++) {
132                if (*p == ' ')
133                        *p = '_';
134        }
135
137          /* Stretch the stats array if necessary. */
138          if (num_stats >= alloc_stats) {
139                  alloc_stats += INCREMENT_STATS;
# Line 313 | Line 314 | void populate_fs() {
314                                   "fs", name, "used_inodes", NULL);
315                          add_stat(LONG_LONG, &disk[i].free_inodes,
316                                   "fs", name, "free_inodes", NULL);
317 +                        add_stat(LONG_LONG, &disk[i].avail_inodes,
318 +                                 "fs", name, "avail_inodes", NULL);
319 +                        add_stat(LONG_LONG, &disk[i].io_size,
320 +                                 "fs", name, "io_size", NULL);
321 +                        add_stat(LONG_LONG, &disk[i].block_size,
322 +                                 "fs", name, "block_size", NULL);
323 +                        add_stat(LONG_LONG, &disk[i].total_blocks,
324 +                                 "fs", name, "total_blocks", NULL);
325 +                        add_stat(LONG_LONG, &disk[i].free_blocks,
326 +                                 "fs", name, "free_blocks", NULL);
327 +                        add_stat(LONG_LONG, &disk[i].avail_blocks,
328 +                                 "fs", name, "avail_blocks", NULL);
329 +                        add_stat(LONG_LONG, &disk[i].used_blocks,
330 +                                 "fs", name, "used_blocks", NULL);
331  
332                          free(buf);
333                  }
# Line 412 | Line 427 | void populate_net() {
427                                   "net", name, "speed", NULL);
428                          add_stat(BOOL, &iface[i].up,
429                                   "net", name, "up", NULL);
430 <                        add_stat(DUPLEX, &iface[i].dup,
430 >                        add_stat(DUPLEX, &iface[i].duplex,
431                                   "net", name, "duplex", NULL);
432                  }
433          }
# Line 497 | Line 512 | void print_stat_value(const stat *s) {
512  
513          switch (s->type) {
514          case LONG_LONG:
515 + #ifdef WIN32 /* Windows printf does not understand %lld, so use %I64d instead */
516 +                printf("%I64d", *(long long *)v);
517 + #else
518                  printf("%lld", *(long long *)v);
519 + #endif
520                  break;
521          case BYTES:
522                  llv = *(long long *)v;
523                  if (bytes_scale_factor != 0) {
524                          llv /= bytes_scale_factor;
525                  }
526 + #ifdef WIN32
527 +                printf("%I64d", llv);
528 + #else
529                  printf("%lld", llv);
530 + #endif
531                  break;
532          case TIME_T:
533                  /* FIXME option for formatted time? */
# Line 629 | Line 652 | void usage() {
652                 "If no STATs are given, all will be displayed. Specify 'STAT.' to display all\n"
653                 "statistics starting with that prefix.\n"
654                 "\n");
655 <        printf("  -l     Linux sysctl-style output (default)\n"
656 <               "  -b     BSD sysctl-style output\n"
657 <               "  -m     MRTG-compatible output\n"
658 <               "  -u     Plain output (only show values)\n"
659 <               "  -n     Display cumulative stats once (default)\n"
660 <               "  -s     Display stat differences repeatedly\n"
661 <               "  -o     Display stat differences once\n"
655 >        printf("  -l         Linux sysctl-style output (default)\n"
656 >               "  -b         BSD sysctl-style output\n"
657 >               "  -m         MRTG-compatible output\n"
658 >               "  -u         Plain output (only show values)\n"
659 >               "  -n         Display cumulative stats once (default)\n"
660 >               "  -s         Display stat differences repeatedly\n"
661 >               "  -o         Display stat differences once\n"
662                 "  -t DELAY   When repeating, wait DELAY seconds between updates (default 1)\n"
663 <               "  -p     Display CPU usage differences as percentages rather than\n"
664 <               "             absolute values\n"
665 <               "  -f SCALE   Display floating-point values as integers scaled by FACTOR\n"
663 >               "  -p         Display CPU usage differences as percentages rather than\n"
664 >               "             absolute values\n"
665 >               "  -f FACTOR  Display floating-point values as integers scaled by FACTOR\n"
666                 "  -K         Display byte counts in kibibytes\n"
667                 "  -M         Display byte counts in mebibytes\n"
668                 "  -G         Display byte counts in gibibytes\n"
# Line 720 | Line 743 | int main(int argc, char **argv) {
743          /* We don't care if sg_init fails, because we can just display
744             the statistics that can be read as non-root. */
745          sg_init();
746 +        sg_snapshot();
747          if (sg_drop_privileges() != 0)
748                  die("Failed to drop setuid/setgid privileges");
749  
# Line 731 | Line 755 | int main(int argc, char **argv) {
755          case REPEAT_ONCE:
756                  get_stats();
757                  sleep(repeat_time);
758 +                sg_snapshot();
759                  get_stats();
760                  print_stats(argc, argv);
761                  break;
# Line 740 | Line 765 | int main(int argc, char **argv) {
765                          print_stats(argc, argv);
766                          printf("\n");
767                          sleep(repeat_time);
768 +                        sg_snapshot();
769                  }
770          }
771  
# Line 747 | Line 773 | int main(int argc, char **argv) {
773                  printf("\n");
774                  printf("statgrab\n");
775          }
776 +
777 +        sg_shutdown();
778  
779          return 0;
780   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines