add INIT_G()'s. No code changes.
[oweals/busybox.git] / procps / nmeter.c
index bb1e819a6fb77d49b2e800fd079afad862e20423..99995598225272e0762966ddfdbe047cb124341a 100644 (file)
@@ -1,9 +1,44 @@
 /*
-** Licensed under the GPL v2, see the file LICENSE in this tarball
-**
-** Based on nanotop.c from floppyfw project
-**
-** Contact me: vda.linux@googlemail.com */
+ * Licensed under GPLv2, see file LICENSE in this source tree.
+ *
+ * Based on nanotop.c from floppyfw project
+ *
+ * Contact me: vda.linux@googlemail.com
+ */
+
+//config:config NMETER
+//config:      bool "nmeter"
+//config:      default y
+//config:      help
+//config:        Prints selected system stats continuously, one line per update.
+
+//applet:IF_NMETER(APPLET(nmeter, BB_DIR_USR_BIN, BB_SUID_DROP))
+
+//kbuild:lib-$(CONFIG_NMETER) += nmeter.o
+
+//usage:#define nmeter_trivial_usage
+//usage:       "[-d MSEC] FORMAT_STRING"
+//usage:#define nmeter_full_usage "\n\n"
+//usage:       "Monitor system in real time"
+//usage:     "\n"
+//usage:     "\n -d MSEC       Milliseconds between updates (default:1000)"
+//usage:     "\n"
+//usage:     "\nFormat specifiers:"
+//usage:     "\n %Nc or %[cN]  CPU. N - bar size (default:10)"
+//usage:     "\n               (displays: S:system U:user N:niced D:iowait I:irq i:softirq)"
+//usage:     "\n %[nINTERFACE] Network INTERFACE"
+//usage:     "\n %m            Allocated memory"
+//usage:     "\n %[mf]         Free memory"
+//usage:     "\n %[mt]         Total memory"
+//usage:     "\n %s            Allocated swap"
+//usage:     "\n %f            Number of used file descriptors"
+//usage:     "\n %Ni           Total/specific IRQ rate"
+//usage:     "\n %x            Context switch rate"
+//usage:     "\n %p            Forks"
+//usage:     "\n %[pn]         # of processes"
+//usage:     "\n %b            Block io"
+//usage:     "\n %Nt           Time (with N decimal points)"
+//usage:     "\n %r            Print <cr> instead of <lf> at EOL"
 
 //TODO:
 // simplify code
@@ -422,7 +457,7 @@ static s_stat* init_int(const char *param)
        if (param[0] == '\0') {
                s->no = 1;
        } else {
-               int n = xatoi_u(param);
+               int n = xatoi_positive(param);
                s->no = n + 2;
        }
        return (s_stat*)s;
@@ -768,6 +803,7 @@ static void FAST_FUNC collect_info(s_stat *s)
 
 typedef s_stat* init_func(const char *param);
 
+// Deprecated %NNNd is to be removed, -d MSEC supersedes it
 static const char options[] ALIGN1 = "ncmsfixptbdr";
 static init_func *const init_functions[] = {
        init_if,
@@ -791,23 +827,28 @@ int nmeter_main(int argc UNUSED_PARAM, char **argv)
        s_stat *first = NULL;
        s_stat *last = NULL;
        s_stat *s;
+       char *opt_d;
        char *cur, *prev;
 
        INIT_G();
 
        xchdir("/proc");
 
-       if (!argv[1])
-               bb_show_usage();
-
        if (open_read_close("version", buf, sizeof(buf)-1) > 0) {
                buf[sizeof(buf)-1] = '\0';
                is26 = (strstr(buf, " 2.4.") == NULL);
        }
 
-       // Can use argv[1] directly, but this will mess up
+       if (getopt32(argv, "d:", &opt_d))
+               init_delay(opt_d);
+       argv += optind;
+
+       if (!argv[0])
+               bb_show_usage();
+
+       // Can use argv[0] directly, but this will mess up
        // parameters as seen by e.g. ps. Making a copy...
-       cur = xstrdup(argv[1]);
+       cur = xstrdup(argv[0]);
        while (1) {
                char *param, *p;
                prev = cur;