aboutsummaryrefslogtreecommitdiff
path: root/procps
diff options
context:
space:
mode:
Diffstat (limited to 'procps')
-rw-r--r--procps/free.c77
-rw-r--r--procps/mpstat.c10
-rw-r--r--procps/powertop.c10
-rw-r--r--procps/pwdx.c4
4 files changed, 56 insertions, 45 deletions
diff --git a/procps/free.c b/procps/free.c
index 47f2fc3b2..0d023f740 100644
--- a/procps/free.c
+++ b/procps/free.c
@@ -44,11 +44,28 @@ static unsigned long long scale(unsigned long d)
44 return ((unsigned long long)d * G.mem_unit) >> G_unit_steps; 44 return ((unsigned long long)d * G.mem_unit) >> G_unit_steps;
45} 45}
46 46
47static unsigned long parse_cached_kb(void)
48{
49 char buf[60]; /* actual lines we expect are ~30 chars or less */
50 FILE *fp;
51 unsigned long cached = 0;
52
53 fp = xfopen_for_read("/proc/meminfo");
54 while (fgets(buf, sizeof(buf), fp) != NULL) {
55 if (sscanf(buf, "Cached: %lu %*s\n", &cached) == 1)
56 break;
57 }
58 if (ENABLE_FEATURE_CLEAN_UP)
59 fclose(fp);
60
61 return cached;
62}
47 63
48int free_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 64int free_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
49int free_main(int argc UNUSED_PARAM, char **argv IF_NOT_DESKTOP(UNUSED_PARAM)) 65int free_main(int argc UNUSED_PARAM, char **argv IF_NOT_DESKTOP(UNUSED_PARAM))
50{ 66{
51 struct sysinfo info; 67 struct sysinfo info;
68 unsigned long long cached;
52 69
53 INIT_G(); 70 INIT_G();
54 71
@@ -73,49 +90,47 @@ int free_main(int argc UNUSED_PARAM, char **argv IF_NOT_DESKTOP(UNUSED_PARAM))
73 } 90 }
74 } 91 }
75#endif 92#endif
76 93 printf(" %11s%11s%11s%11s%11s%11s\n"
77 sysinfo(&info); 94 "Mem: ",
78
79 /* Kernels prior to 2.4.x will return info.mem_unit==0, so cope... */
80 G.mem_unit = (info.mem_unit ? info.mem_unit : 1);
81
82 printf(" %13s%13s%13s%13s%13s\n",
83 "total", 95 "total",
84 "used", 96 "used",
85 "free", 97 "free",
86 "shared", "buffers" /* swap and total don't have these columns */ 98 "shared", "buffers", "cached" /* swap and total don't have these columns */
87 /* procps version 3.2.8 also shows "cached" column, but
88 * sysinfo() does not provide this value, need to parse
89 * /proc/meminfo instead and get "Cached: NNN kB" from there.
90 */
91 ); 99 );
92 100
93#define FIELDS_5 "%13llu%13llu%13llu%13llu%13llu\n" 101 sysinfo(&info);
94#define FIELDS_3 (FIELDS_5 + 2*6) 102 /* Kernels prior to 2.4.x will return info.mem_unit==0, so cope... */
95#define FIELDS_2 (FIELDS_5 + 3*6) 103 G.mem_unit = (info.mem_unit ? info.mem_unit : 1);
104 /* Extract cached from /proc/meminfo and convert to mem_units */
105 cached = ((unsigned long long) parse_cached_kb() * 1024) / G.mem_unit;
106
107#define FIELDS_6 "%11llu%11llu%11llu%11llu%11llu%11llu\n"
108#define FIELDS_3 (FIELDS_6 + 3*6)
109#define FIELDS_2 (FIELDS_6 + 4*6)
96 110
97 printf("Mem: "); 111 printf(FIELDS_6,
98 printf(FIELDS_5, 112 scale(info.totalram), //total
99 scale(info.totalram), 113 scale(info.totalram - info.freeram), //used
100 scale(info.totalram - info.freeram), 114 scale(info.freeram), //free
101 scale(info.freeram), 115 scale(info.sharedram), //shared
102 scale(info.sharedram), 116 scale(info.bufferram), //buffers
103 scale(info.bufferram) 117 scale(cached) //cached
104 ); 118 );
105 /* Show alternate, more meaningful busy/free numbers by counting 119 /* Show alternate, more meaningful busy/free numbers by counting
106 * buffer cache as free memory (make it "-/+ buffers/cache" 120 * buffer cache as free memory. */
107 * if/when we add support for "cached" column): */ 121 printf("-/+ buffers/cache:");
108 printf("-/+ buffers: "); 122 cached += info.freeram;
123 cached += info.bufferram;
109 printf(FIELDS_2, 124 printf(FIELDS_2,
110 scale(info.totalram - info.freeram - info.bufferram), 125 scale(info.totalram - cached), //used
111 scale(info.freeram + info.bufferram) 126 scale(cached) //free
112 ); 127 );
113#if BB_MMU 128#if BB_MMU
114 printf("Swap:"); 129 printf("Swap: ");
115 printf(FIELDS_3, 130 printf(FIELDS_3,
116 scale(info.totalswap), 131 scale(info.totalswap), //total
117 scale(info.totalswap - info.freeswap), 132 scale(info.totalswap - info.freeswap), //used
118 scale(info.freeswap) 133 scale(info.freeswap) //free
119 ); 134 );
120#endif 135#endif
121 return EXIT_SUCCESS; 136 return EXIT_SUCCESS;
diff --git a/procps/mpstat.c b/procps/mpstat.c
index c628d6215..6028903fa 100644
--- a/procps/mpstat.c
+++ b/procps/mpstat.c
@@ -522,13 +522,11 @@ static void get_irqs_from_stat(struct stats_irq *irq)
522 FILE *fp; 522 FILE *fp;
523 char buf[1024]; 523 char buf[1024];
524 524
525 fp = fopen_for_read(PROCFS_STAT); 525 fp = xfopen_for_read(PROCFS_STAT);
526 if (!fp)
527 return;
528 526
529 while (fgets(buf, sizeof(buf), fp)) { 527 while (fgets(buf, sizeof(buf), fp)) {
530 //bb_error_msg("/proc/stat:'%s'", buf); 528 //bb_error_msg("/proc/stat:'%s'", buf);
531 if (strncmp(buf, "intr ", 5) == 0) { 529 if (is_prefixed_with(buf, "intr ")) {
532 /* Read total number of IRQs since system boot */ 530 /* Read total number of IRQs since system boot */
533 sscanf(buf + 5, "%"FMT_DATA"u", &irq->irq_nr); 531 sscanf(buf + 5, "%"FMT_DATA"u", &irq->irq_nr);
534 } 532 }
@@ -644,9 +642,7 @@ static void get_uptime(data_t *uptime)
644 char buf[sizeof(long)*3 * 2 + 4]; /* enough for long.long */ 642 char buf[sizeof(long)*3 * 2 + 4]; /* enough for long.long */
645 unsigned long uptime_sec, decimal; 643 unsigned long uptime_sec, decimal;
646 644
647 fp = fopen_for_read(PROCFS_UPTIME); 645 fp = xfopen_for_read(PROCFS_UPTIME);
648 if (!fp)
649 return;
650 if (fgets(buf, sizeof(buf), fp)) { 646 if (fgets(buf, sizeof(buf), fp)) {
651 if (sscanf(buf, "%lu.%lu", &uptime_sec, &decimal) == 2) { 647 if (sscanf(buf, "%lu.%lu", &uptime_sec, &decimal) == 2) {
652 *uptime = (data_t)uptime_sec * G.hz + decimal * G.hz / 100; 648 *uptime = (data_t)uptime_sec * G.hz + decimal * G.hz / 100;
diff --git a/procps/powertop.c b/procps/powertop.c
index e3c29d1c3..1de5d329e 100644
--- a/procps/powertop.c
+++ b/procps/powertop.c
@@ -360,7 +360,7 @@ static void process_irq_counts(void)
360 } 360 }
361 361
362 name = p; 362 name = p;
363 strchrnul(name, '\n')[0] = '\0'; 363 chomp(p);
364 /* Save description of the interrupt */ 364 /* Save description of the interrupt */
365 if (nr >= 20000) 365 if (nr >= 20000)
366 sprintf(irq_desc, " <kernel IPI> : %s", name); 366 sprintf(irq_desc, " <kernel IPI> : %s", name);
@@ -458,9 +458,9 @@ static NOINLINE int process_timer_stats(void)
458 // func = "Load balancing tick"; 458 // func = "Load balancing tick";
459 //} 459 //}
460 460
461 if (strncmp(func, "tick_nohz_", 10) == 0) 461 if (is_prefixed_with(func, "tick_nohz_"))
462 continue; 462 continue;
463 if (strncmp(func, "tick_setup_sched_timer", 20) == 0) 463 if (is_prefixed_with(func, "tick_setup_sched_timer"))
464 continue; 464 continue;
465 //if (strcmp(process, "powertop") == 0) 465 //if (strcmp(process, "powertop") == 0)
466 // continue; 466 // continue;
@@ -470,7 +470,7 @@ static NOINLINE int process_timer_stats(void)
470 process = idx < 2 ? "[kernel module]" : "<kernel core>"; 470 process = idx < 2 ? "[kernel module]" : "<kernel core>";
471 } 471 }
472 472
473 strchrnul(p, '\n')[0] = '\0'; 473 chomp(p);
474 474
475 // 46D\01136\0kondemand/1\0do_dbs_timer (delayed_work_timer_fn) 475 // 46D\01136\0kondemand/1\0do_dbs_timer (delayed_work_timer_fn)
476 // ^ ^ ^ 476 // ^ ^ ^
@@ -674,7 +674,7 @@ static void show_timerstats(void)
674//usage:#define powertop_trivial_usage 674//usage:#define powertop_trivial_usage
675//usage: "" 675//usage: ""
676//usage:#define powertop_full_usage "\n\n" 676//usage:#define powertop_full_usage "\n\n"
677//usage: "Analyze power consumption on Intel-based laptops\n" 677//usage: "Analyze power consumption on Intel-based laptops"
678 678
679int powertop_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 679int powertop_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
680int powertop_main(int UNUSED_PARAM argc, char UNUSED_PARAM **argv) 680int powertop_main(int UNUSED_PARAM argc, char UNUSED_PARAM **argv)
diff --git a/procps/pwdx.c b/procps/pwdx.c
index 781810488..4e34149ed 100644
--- a/procps/pwdx.c
+++ b/procps/pwdx.c
@@ -21,7 +21,7 @@
21//usage:#define pwdx_trivial_usage 21//usage:#define pwdx_trivial_usage
22//usage: "PID..." 22//usage: "PID..."
23//usage:#define pwdx_full_usage "\n\n" 23//usage:#define pwdx_full_usage "\n\n"
24//usage: "Show current directory for PIDs\n" 24//usage: "Show current directory for PIDs"
25 25
26#include "libbb.h" 26#include "libbb.h"
27 27
@@ -41,7 +41,7 @@ int pwdx_main(int argc UNUSED_PARAM, char **argv)
41 // Allowed on the command line: 41 // Allowed on the command line:
42 // /proc/NUM 42 // /proc/NUM
43 // NUM 43 // NUM
44 if (strncmp(arg, "/proc/", 6) == 0) 44 if (is_prefixed_with(arg, "/proc/"))
45 arg += 6; 45 arg += 6;
46 46
47 pid = bb_strtou(arg, NULL, 10); 47 pid = bb_strtou(arg, NULL, 10);