Changeset 3232 in MondoRescue for branches/3.2/mindi-busybox/procps/nmeter.c


Ignore:
Timestamp:
Jan 1, 2014, 12:47:38 AM (10 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.21.1
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.2/mindi-busybox/procps/nmeter.c

    r2725 r3232  
    66 * Contact me: vda.linux@googlemail.com
    77 */
     8
     9//config:config NMETER
     10//config:   bool "nmeter"
     11//config:   default y
     12//config:   help
     13//config:     Prints selected system stats continuously, one line per update.
     14
     15//applet:IF_NMETER(APPLET(nmeter, BB_DIR_USR_BIN, BB_SUID_DROP))
     16
     17//kbuild:lib-$(CONFIG_NMETER) += nmeter.o
     18
     19//usage:#define nmeter_trivial_usage
     20//usage:       "[-d MSEC] FORMAT_STRING"
     21//usage:#define nmeter_full_usage "\n\n"
     22//usage:       "Monitor system in real time"
     23//usage:     "\n"
     24//usage:     "\n -d MSEC    Milliseconds between updates (default:1000)"
     25//usage:     "\n"
     26//usage:     "\nFormat specifiers:"
     27//usage:     "\n %Nc or %[cN]   CPU. N - bar size (default:10)"
     28//usage:     "\n        (displays: S:system U:user N:niced D:iowait I:irq i:softirq)"
     29//usage:     "\n %[nINTERFACE]  Network INTERFACE"
     30//usage:     "\n %m     Allocated memory"
     31//usage:     "\n %[mf]      Free memory"
     32//usage:     "\n %[mt]      Total memory"
     33//usage:     "\n %s     Allocated swap"
     34//usage:     "\n %f     Number of used file descriptors"
     35//usage:     "\n %Ni        Total/specific IRQ rate"
     36//usage:     "\n %x     Context switch rate"
     37//usage:     "\n %p     Forks"
     38//usage:     "\n %[pn]      # of processes"
     39//usage:     "\n %b     Block io"
     40//usage:     "\n %Nt        Time (with N decimal points)"
     41//usage:     "\n %r     Print <cr> instead of <lf> at EOL"
    842
    943//TODO:
     
    238272
    239273// Parses /proc/diskstats
    240 //   1  2 3   4  5        6(rd)  7      8     9     10(wr) 11     12 13     14
     274//   1  2 3   4     5     6(rd)  7      8     9     10(wr) 11     12 13     14
    241275//   3  0 hda 51292 14441 841783 926052 25717 79650 843256 3029804 0 148459 3956933
    242276//   3  1 hda1 0 0 0 0 <- ignore if only 4 fields
     277// Linux 3.0 (maybe earlier) started printing full stats for hda1 too.
     278// Had to add code which skips such devices.
    243279static int rdval_diskstats(const char* p, ullong *vec)
    244280{
    245     ullong rd = rd; // for compiler
    246     int indexline = 0;
     281    char devname[32];
     282    unsigned devname_len = 0;
     283    int value_idx = 0;
     284
    247285    vec[0] = 0;
    248286    vec[1] = 0;
    249287    while (1) {
    250         indexline++;
    251         while (*p == ' ' || *p == '\t') p++;
    252         if (*p == '\0') break;
     288        value_idx++;
     289        while (*p == ' ' || *p == '\t')
     290            p++;
     291        if (*p == '\0')
     292            break;
    253293        if (*p == '\n') {
    254             indexline = 0;
     294            value_idx = 0;
    255295            p++;
    256296            continue;
    257297        }
    258         if (indexline == 6) {
    259             rd = strtoull(p, NULL, 10);
    260         } else if (indexline == 10) {
    261             vec[0] += rd;  // TODO: *sectorsize (don't know how to find out sectorsize)
     298        if (value_idx == 3) {
     299            char *end = strchrnul(p, ' ');
     300            /* If this a hda1-like device (same prefix as last one + digit)? */
     301            if (devname_len && strncmp(devname, p, devname_len) == 0 && isdigit(p[devname_len])) {
     302                p = end;
     303                goto skip_line; /* skip entire line */
     304            }
     305            /* It is not. Remember the name for future checks */
     306            devname_len = end - p;
     307            if (devname_len > sizeof(devname)-1)
     308                devname_len = sizeof(devname)-1;
     309            strncpy(devname, p, devname_len);
     310            /* devname[devname_len] = '\0'; - not really needed */
     311            p = end;
     312        } else
     313        if (value_idx == 6) {
     314            // TODO: *sectorsize (don't know how to find out sectorsize)
     315            vec[0] += strtoull(p, NULL, 10);
     316        } else
     317        if (value_idx == 10) {
     318            // TODO: *sectorsize (don't know how to find out sectorsize)
    262319            vec[1] += strtoull(p, NULL, 10);
    263             while (*p != '\n' && *p != '\0') p++;
     320 skip_line:
     321            while (*p != '\n' && *p != '\0')
     322                p++;
    264323            continue;
    265324        }
    266         while (*p > ' ') p++; // skip over value
     325        while ((unsigned char)(*p) > ' ') // skip over value
     326            p++;
    267327    }
    268328    return 0;
     
    770830typedef s_stat* init_func(const char *param);
    771831
     832// Deprecated %NNNd is to be removed, -d MSEC supersedes it
    772833static const char options[] ALIGN1 = "ncmsfixptbdr";
    773834static init_func *const init_functions[] = {
     
    793854    s_stat *last = NULL;
    794855    s_stat *s;
     856    char *opt_d;
    795857    char *cur, *prev;
    796858
     
    798860
    799861    xchdir("/proc");
    800 
    801     if (!argv[1])
    802         bb_show_usage();
    803862
    804863    if (open_read_close("version", buf, sizeof(buf)-1) > 0) {
     
    807866    }
    808867
    809     // Can use argv[1] directly, but this will mess up
     868    if (getopt32(argv, "d:", &opt_d))
     869        init_delay(opt_d);
     870    argv += optind;
     871
     872    if (!argv[0])
     873        bb_show_usage();
     874
     875    // Can use argv[0] directly, but this will mess up
    810876    // parameters as seen by e.g. ps. Making a copy...
    811     cur = xstrdup(argv[1]);
     877    cur = xstrdup(argv[0]);
    812878    while (1) {
    813879        char *param, *p;
Note: See TracChangeset for help on using the changeset viewer.