top: fix and merge code to parse /proc/meminfo
[oweals/busybox.git] / procps / mpstat.c
index f1a0b00b8f2bc9f833064d62424ad510f7994b5c..c628d62152ad64f783e8d9cdc3b5f72526ebead7 100644 (file)
@@ -7,7 +7,7 @@
  * Licensed under GPLv2, see file LICENSE in this source tree.
  */
 
-//applet:IF_MPSTAT(APPLET(mpstat, _BB_DIR_BIN, _BB_SUID_DROP))
+//applet:IF_MPSTAT(APPLET(mpstat, BB_DIR_BIN, BB_SUID_DROP))
 
 //kbuild:lib-$(CONFIG_MPSTAT) += mpstat.o
 
@@ -18,7 +18,7 @@
 //config:        Per-processor statistics
 
 #include "libbb.h"
-#include <sys/utsname.h>       /* struct utsname */
+#include <sys/utsname.h>  /* struct utsname */
 
 //#define debug(fmt, ...) fprintf(stderr, fmt, ## __VA_ARGS__)
 #define debug(fmt, ...) ((void)0)
  * We are printing headers in the " IRQNAME/s" form, experimentally
  * anything smaller than 10 chars looks ugly for /proc/softirqs stats.
  */
-#define INTRATE_SCRWIDTH   10
+#define INTRATE_SCRWIDTH      10
 #define INTRATE_SCRWIDTH_STR "10"
 
 /* System files */
-#define SYSFS_DEVCPU      "/sys/devices/system/cpu"
 #define PROCFS_STAT       "/proc/stat"
 #define PROCFS_INTERRUPTS "/proc/interrupts"
 #define PROCFS_SOFTIRQS   "/proc/softirqs"
@@ -634,7 +633,7 @@ static void get_irqs_from_interrupts(const char *fname,
        while (irq < irqs_per_cpu) {
                /* Number of interrupts per CPU has changed */
                ic = &per_cpu_stats[current][irq];
-               ic->irq_name[0] = '\0'; /* False interrupt */
+               ic->irq_name[0] = '\0'; /* False interrupt */
                irq++;
        }
 }
@@ -776,12 +775,6 @@ static void main_loop(void)
 
 /* Initialization */
 
-/* Get number of clock ticks per sec */
-static ALWAYS_INLINE unsigned get_hz(void)
-{
-       return sysconf(_SC_CLK_TCK);
-}
-
 static void alloc_struct(int cpus)
 {
        int i;
@@ -820,7 +813,7 @@ static int get_irqcpu_nr(const char *f, int max_irqs)
        unsigned irq;
 
        fp = fopen_for_read(f);
-       if (!fp)                /* No interrupts file */
+       if (!fp)  /* No interrupts file */
                return 0;
 
        linelen = INTERRUPTS_LINE + 16 * G.cpu_nr;
@@ -845,7 +838,6 @@ static int get_irqcpu_nr(const char *f, int max_irqs)
 //usage:       "[-A] [-I SUM|CPU|ALL|SCPU] [-u] [-P num|ALL] [INTERVAL [COUNT]]"
 //usage:#define mpstat_full_usage "\n\n"
 //usage:       "Per-processor statistics\n"
-//usage:     "\nOptions:"
 //usage:     "\n       -A                      Same as -I ALL -u -P ALL"
 //usage:     "\n       -I SUM|CPU|ALL|SCPU     Report interrupt statistics"
 //usage:     "\n       -P num|ALL              Processor to monitor"
@@ -858,10 +850,10 @@ int mpstat_main(int UNUSED_PARAM argc, char **argv)
        char *opt_set_cpu;
        int i, opt;
        enum {
-               OPT_ALL    = 1 << 0,    /* -A */
-               OPT_INTS   = 1 << 1,    /* -I */
-               OPT_SETCPU = 1 << 2,    /* -P */
-               OPT_UTIL   = 1 << 3,    /* -u */
+               OPT_ALL    = 1 << 0, /* -A */
+               OPT_INTS   = 1 << 1, /* -I */
+               OPT_SETCPU = 1 << 2, /* -P */
+               OPT_UTIL   = 1 << 3, /* -u */
        };
 
        /* Dont buffer data if redirected to a pipe */
@@ -875,7 +867,7 @@ int mpstat_main(int UNUSED_PARAM argc, char **argv)
        G.cpu_nr = get_cpu_count();
 
        /* Get number of clock ticks per sec */
-       G.hz = get_hz();
+       G.hz = bb_clk_tck();
 
        /* Calculate number of interrupts per processor */
        G.irqcpu_nr = get_irqcpu_nr(PROCFS_INTERRUPTS, NR_IRQS) + NR_IRQCPU_PREALLOC;