hush: fix a bug in argv restoration after sourcing a file
[oweals/busybox.git] / procps / powertop.c
index da7f052589331f36e7e974beb8906a62f2e9b266..ce85f4191e0f605dfd67e1f00f072956201a4b92 100644 (file)
@@ -9,7 +9,7 @@
  * Licensed under GPLv2, see file LICENSE in this source tree.
  */
 
-//applet:IF_POWERTOP(APPLET(powertop, _BB_DIR_BIN, _BB_SUID_DROP))
+//applet:IF_POWERTOP(APPLET(powertop, BB_DIR_USR_SBIN, BB_SUID_DROP))
 
 //kbuild:lib-$(CONFIG_POWERTOP) += powertop.o
 
@@ -360,7 +360,7 @@ static void process_irq_counts(void)
                }
 
                name = p;
-               strchrnul(name, '\n')[0] = '\0';
+               chomp(p);
                /* Save description of the interrupt */
                if (nr >= 20000)
                        sprintf(irq_desc, "   <kernel IPI> : %s", name);
@@ -393,12 +393,11 @@ static NOINLINE int process_timer_stats(void)
        char buf[128];
        char line[15 + 3 + 128];
        int n;
-       ullong totalticks;
        FILE *fp;
 
        buf[0] = '\0';
-       totalticks = 0;
 
+       n = 0;
        fp = NULL;
        if (!G.cant_enable_timer_stats)
                fp = fopen_for_read("/proc/timer_stats");
@@ -418,14 +417,24 @@ static NOINLINE int process_timer_stats(void)
                        const char *count, *process, *func;
                        char *p;
                        int idx;
+                       unsigned cnt;
 
                        count = skip_whitespace(buf);
                        p = strchr(count, ',');
                        if (!p)
                                continue;
                        *p++ = '\0';
-                       if (strcmp(skip_non_whitespace(count), " total events") == 0)
+                       cnt = bb_strtou(count, NULL, 10);
+                       if (strcmp(skip_non_whitespace(count), " total events") == 0) {
+#if ENABLE_FEATURE_POWERTOP_PROCIRQ
+                               n = cnt / G.total_cpus;
+                               if (n > 0 && n < G.interrupt_0) {
+                                       sprintf(line, "    <interrupt> : %s", "extra timer interrupt");
+                                       save_line(line, G.interrupt_0 - n);
+                               }
+#endif
                                break;
+                       }
                        if (strchr(count, 'D'))
                                continue; /* deferred */
                        p = skip_whitespace(p); /* points to pid now */
@@ -449,9 +458,9 @@ static NOINLINE int process_timer_stats(void)
                        //      func = "Load balancing tick";
                        //}
 
-                       if (strncmp(func, "tick_nohz_", 10) == 0)
+                       if (is_prefixed_with(func, "tick_nohz_"))
                                continue;
-                       if (strncmp(func, "tick_setup_sched_timer", 20) == 0)
+                       if (is_prefixed_with(func, "tick_setup_sched_timer"))
                                continue;
                        //if (strcmp(process, "powertop") == 0)
                        //      continue;
@@ -461,7 +470,7 @@ static NOINLINE int process_timer_stats(void)
                                process = idx < 2 ? "[kernel module]" : "<kernel core>";
                        }
 
-                       strchrnul(p, '\n')[0] = '\0';
+                       chomp(p);
 
                        // 46D\01136\0kondemand/1\0do_dbs_timer (delayed_work_timer_fn)
                        // ^          ^            ^
@@ -471,21 +480,11 @@ static NOINLINE int process_timer_stats(void)
                                sprintf(line, "%15.15s : %s", process, func);
                        //else
                        //      sprintf(line, "%s", process);
-                       save_line(line, bb_strtoull(count, NULL, 10));
+                       save_line(line, cnt);
                }
                fclose(fp);
        }
 
-       n = 0;
-#if ENABLE_FEATURE_POWERTOP_PROCIRQ
-       if (strstr(buf, " total events")) {
-               n = bb_strtoull(buf, NULL, 10) / G.total_cpus;
-               if (n > 0 && n < G.interrupt_0) {
-                       sprintf(line, "    <interrupt> : %s", "extra timer interrupt");
-                       save_line(line, G.interrupt_0 - n);
-               }
-       }
-#endif
        return n;
 }
 
@@ -494,7 +493,7 @@ static NOINLINE int process_timer_stats(void)
  * Get information about CPU using CPUID opcode.
  */
 static void cpuid(unsigned int *eax, unsigned int *ebx, unsigned int *ecx,
-                                 unsigned int *edx)
+                               unsigned int *edx)
 {
        /* EAX value specifies what information to return */
        __asm__(
@@ -592,7 +591,7 @@ static NOINLINE void print_intel_cstates(void)
        if (!edx || !(ecx & 1))
                return;
 
-       printf("Your CPU supports the following C-states: ");
+       printf("Your %s the following C-states: ", "CPU supports");
        i = 0;
        while (edx) {
                if (edx & 7)
@@ -603,7 +602,7 @@ static NOINLINE void print_intel_cstates(void)
        bb_putchar('\n');
 
        /* Print BIOS C-States */
-       printf("Your BIOS reports the following C-states: ");
+       printf("Your %s the following C-states: ", "BIOS reports");
        for (i = 0; i < ARRAY_SIZE(bios_table); i++)
                if (bios_table[i])
                        printf("C%u ", i);
@@ -628,7 +627,6 @@ static void show_timerstats(void)
                int i, n = 0;
                char strbuf6[6];
 
-               strbuf6[5] = '\0';
                puts("\nTop causes for wakeups:");
                for (i = 0; i < G.lines_cnt; i++) {
                        if ((G.lines[i].count > 0 /*|| G.lines[i].disk_count > 0*/)
@@ -640,7 +638,7 @@ static void show_timerstats(void)
                                /*char c = ' ';
                                if (G.lines[i].disk_count)
                                        c = 'D';*/
-                               smart_ulltoa5(G.lines[i].count, strbuf6, " KMGTPEZY");
+                               smart_ulltoa5(G.lines[i].count, strbuf6, " KMGTPEZY")[0] = '\0';
                                printf(/*" %5.1f%% (%s)%c  %s\n"*/
                                        " %5.1f%% (%s)   %s\n",
                                        G.lines[i].count * 100.0 / G.lines_cumulative_count,
@@ -651,7 +649,7 @@ static void show_timerstats(void)
        } else {
                bb_putchar('\n');
                bb_error_msg("no stats available; run as root or"
-                               " enable the cpufreq_stats module");
+                               " enable the timer_stats module");
        }
 }
 
@@ -676,7 +674,7 @@ static void show_timerstats(void)
 //usage:#define powertop_trivial_usage
 //usage:       ""
 //usage:#define powertop_full_usage "\n\n"
-//usage:       "Analyze power consumption on Intel-based laptops\n"
+//usage:       "Analyze power consumption on Intel-based laptops"
 
 int powertop_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int powertop_main(int UNUSED_PARAM argc, char UNUSED_PARAM **argv)
@@ -706,7 +704,7 @@ int powertop_main(int UNUSED_PARAM argc, char UNUSED_PARAM **argv)
        /* Get number of CPUs */
        G.total_cpus = get_cpu_count();
 
-       printf("Collecting data for "DEFAULT_SLEEP_STR" seconds\n");
+       puts("Collecting data for "DEFAULT_SLEEP_STR" seconds");
 
 #if ENABLE_FEATURE_USE_TERMIOS
        tcgetattr(0, (void *)&G.init_settings);