diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-06-10 18:04:54 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-06-10 18:04:54 +0000 |
commit | b1e5addfedf9de4bf5dfa910756747b2b4c1f2bd (patch) | |
tree | 7ae41a8cc5b53a8d3e771b71e00a6ae64ce5127d /procps | |
parent | 5a65447e3090908b4bad645c84e37298ca7a7449 (diff) | |
download | busybox-w32-b1e5addfedf9de4bf5dfa910756747b2b4c1f2bd.tar.gz busybox-w32-b1e5addfedf9de4bf5dfa910756747b2b4c1f2bd.tar.bz2 busybox-w32-b1e5addfedf9de4bf5dfa910756747b2b4c1f2bd.zip |
top: improve global CPU percentage (smaller & faster code)
Diffstat (limited to 'procps')
-rw-r--r-- | procps/Config.in | 4 | ||||
-rw-r--r-- | procps/top.c | 20 |
2 files changed, 16 insertions, 8 deletions
diff --git a/procps/Config.in b/procps/Config.in index cd46a3448..fba9e4074 100644 --- a/procps/Config.in +++ b/procps/Config.in | |||
@@ -109,11 +109,11 @@ config FEATURE_TOP_CPU_USAGE_PERCENTAGE | |||
109 | Make top display CPU usage for each process. | 109 | Make top display CPU usage for each process. |
110 | 110 | ||
111 | config FEATURE_TOP_CPU_GLOBAL_PERCENTS | 111 | config FEATURE_TOP_CPU_GLOBAL_PERCENTS |
112 | bool "Show CPU global usage percentage (adds 1k byte)" | 112 | bool "Show CPU global usage percentage (adds 0.5k byte)" |
113 | default y | 113 | default y |
114 | depends on FEATURE_TOP_CPU_USAGE_PERCENTAGE | 114 | depends on FEATURE_TOP_CPU_USAGE_PERCENTAGE |
115 | help | 115 | help |
116 | Makes top display "CPU: n.n% us n.n% sy n.n% ni..." line. | 116 | Makes top display "CPU: NN% usr NN% sys..." line. |
117 | 117 | ||
118 | config UPTIME | 118 | config UPTIME |
119 | bool "uptime" | 119 | bool "uptime" |
diff --git a/procps/top.c b/procps/top.c index 6d8dfd880..564e94343 100644 --- a/procps/top.c +++ b/procps/top.c | |||
@@ -292,8 +292,15 @@ static unsigned long display_generic(int scr_width) | |||
292 | /* | 292 | /* |
293 | * xxx% = (jif.xxx - prev_jif.xxx) / (jif.total - prev_jif.total) * 100% | 293 | * xxx% = (jif.xxx - prev_jif.xxx) / (jif.total - prev_jif.total) * 100% |
294 | */ | 294 | */ |
295 | #define CALC_STAT(xxx) div_t xxx = div(1000 * (jif.xxx - prev_jif.xxx) / total_diff, 10) | 295 | /* using (unsigned) cast to make multiplication cheaper: */ |
296 | #define SHOW_STAT(xxx) xxx.quot, '0'+xxx.rem | 296 | #define CALC_STAT(xxx) unsigned xxx = 100 * (unsigned)(jif.xxx - prev_jif.xxx) / total_diff |
297 | #define SHOW_STAT(xxx) xxx | ||
298 | #define FMT "%3u%%" | ||
299 | // We can display fractional percents, but at least in glibc div() is a _function_ | ||
300 | // and generated code is really awful and big (+0.5k more code): | ||
301 | //#define CALC_STAT(xxx) div_t xxx = div(1000 * (unsigned)(jif.xxx - prev_jif.xxx) / total_diff, 10) | ||
302 | //#define SHOW_STAT(xxx) xxx.quot, '0'+xxx.rem | ||
303 | //#define FMT "%3u.%c%%" | ||
297 | unsigned total_diff = (jif.total - prev_jif.total ? : 1); | 304 | unsigned total_diff = (jif.total - prev_jif.total ? : 1); |
298 | CALC_STAT(usr); | 305 | CALC_STAT(usr); |
299 | CALC_STAT(sys); | 306 | CALC_STAT(sys); |
@@ -305,10 +312,10 @@ static unsigned long display_generic(int scr_width) | |||
305 | //CALC_STAT(steal); | 312 | //CALC_STAT(steal); |
306 | 313 | ||
307 | snprintf(scrbuf, scr_width, | 314 | snprintf(scrbuf, scr_width, |
308 | /* %3u.%c in practice almost never displays "100.0" | 315 | /* %3u in practice almost never displays "100" |
309 | * and thus has implicit leading space: " 99.6" */ | 316 | * and thus has implicit leading space: " 99" */ |
310 | "CPU:%3u.%c%% us%3u.%c%% sy%3u.%c%% ni%3u.%c%% id%3u.%c%% wa%3u.%c%% hi%3u.%c%% si", | 317 | "CPU:"FMT" usr"FMT" sys"FMT" nice"FMT" idle"FMT" wait"FMT" irq"FMT" softirq", |
311 | // %3u.%c%%st", - what is this 'steal' thing? | 318 | // FMT" steal", - what is this 'steal' thing? |
312 | // I doubt anyone needs to know it | 319 | // I doubt anyone needs to know it |
313 | SHOW_STAT(usr), SHOW_STAT(sys), SHOW_STAT(nic), SHOW_STAT(idle), | 320 | SHOW_STAT(usr), SHOW_STAT(sys), SHOW_STAT(nic), SHOW_STAT(idle), |
314 | SHOW_STAT(iowait), SHOW_STAT(irq), SHOW_STAT(softirq) | 321 | SHOW_STAT(iowait), SHOW_STAT(irq), SHOW_STAT(softirq) |
@@ -317,6 +324,7 @@ static unsigned long display_generic(int scr_width) | |||
317 | puts(scrbuf); | 324 | puts(scrbuf); |
318 | #undef SHOW_STAT | 325 | #undef SHOW_STAT |
319 | #undef CALC_STAT | 326 | #undef CALC_STAT |
327 | #undef FMT | ||
320 | } | 328 | } |
321 | 329 | ||
322 | snprintf(scrbuf, scr_width, "Load average: %s", buf); | 330 | snprintf(scrbuf, scr_width, "Load average: %s", buf); |