powertop: code shrink

function                                             old     new   delta
read_cstate_counts                                   355     360      +5
print_intel_cstates                                  494     499      +5
process_timer_stats                                  554     480     -74
process_irq_counts                                   765     530    -235
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/2 up/down: 10/-309)          Total: -299 bytes

Signed-off-by: Maksym Kryzhanovskyy <xmaks@email.cz>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Maksym Kryzhanovskyy 2010-11-04 08:41:57 +01:00 committed by Denys Vlasenko
parent 854738d39d
commit 6052c2b0be

View File

@ -169,7 +169,7 @@ static void read_cstate_counts(ullong *usage, ullong *duration)
if (len < 3 || len > BIG_SYSNAME_LEN) if (len < 3 || len > BIG_SYSNAME_LEN)
continue; continue;
sprintf(buf, "/proc/acpi/processor/%s/power", d->d_name); sprintf(buf, "%s/%s/power", "/proc/acpi/processor", d->d_name);
fp = fopen_for_read(buf); fp = fopen_for_read(buf);
if (!fp) if (!fp)
continue; continue;
@ -321,28 +321,17 @@ static void process_irq_counts(void)
/* 0: 143646045 153901007 IO-APIC-edge timer /* 0: 143646045 153901007 IO-APIC-edge timer
* ^ * ^
*/ */
*p = '\0';
/* Deal with non-maskable interrupts -- make up fake numbers */ /* Deal with non-maskable interrupts -- make up fake numbers */
nr = -1; nr = index_in_strings("NMI\0RES\nCAL\0TLB\0TRM\0THR\0SPU\0", buf);
if (buf[0] != ' ' && !isdigit(buf[0])) { if (nr != -1) {
//TODO: optimize nr += 20000;
if (strncmp(buf, "NMI:", 4) == 0)
nr = 20000;
if (strncmp(buf, "RES:", 4) == 0)
nr = 20001;
if (strncmp(buf, "CAL:", 4) == 0)
nr = 20002;
if (strncmp(buf, "TLB:", 4) == 0)
nr = 20003;
if (strncmp(buf, "TRM:", 4) == 0)
nr = 20004;
if (strncmp(buf, "THR:", 4) == 0)
nr = 20005;
if (strncmp(buf, "SPU:", 4) == 0)
nr = 20006;
} else { } else {
/* bb_strtou doesn't eat leading spaces, using strtoul */ /* bb_strtou doesn't eat leading spaces, using strtoul */
nr = strtoul(buf, NULL, 10); nr = strtoul(buf, NULL, 10);
} }
*p = ':';
if (nr == -1) if (nr == -1)
continue; continue;
@ -430,33 +419,31 @@ static NOINLINE int process_timer_stats(void)
while (fgets(buf, sizeof(buf), fp)) { while (fgets(buf, sizeof(buf), fp)) {
const char *count, *process, *func; const char *count, *process, *func;
char *p; char *p;
int cnt; int idx;
count = skip_whitespace(buf); count = skip_whitespace(buf);
if (strcmp(strchrnul(count, ' '), " total events") == 0)
break;
p = strchr(count, ','); p = strchr(count, ',');
if (!p) if (!p)
continue; continue;
*p++ = '\0'; *p++ = '\0';
if (strcmp(strchrnul(count, ' '), " total events") == 0) if (strchr(count, 'D'))
break; continue; /* deferred */
p = skip_whitespace(p); /* points to pid */ p = skip_whitespace(p); /* points to pid now */
process = NULL;
/* Find char ' ', then eat remaining spaces */ get_func_name:
#define ADVANCE(p) do { \ p = strchr(p, ' ');
(p) = strchr((p), ' '); \ if (!p)
if (!(p)) \ continue;
continue; \ *p++ = '\0';
*(p) = '\0'; \ p = skip_whitespace(p);
(p)++; \ if (process == NULL) {
(p) = skip_whitespace(p); \ process = p;
} while (0) goto get_func_name;
/* Get process name */ }
ADVANCE(p);
process = p;
/* Get function */
ADVANCE(p);
func = p; func = p;
#undef ADVANCE
//if (strcmp(process, "swapper") == 0 //if (strcmp(process, "swapper") == 0
// && strcmp(func, "hrtimer_start_range_ns (tick_sched_timer)\n") == 0 // && strcmp(func, "hrtimer_start_range_ns (tick_sched_timer)\n") == 0
//) { //) {
@ -471,38 +458,29 @@ static NOINLINE int process_timer_stats(void)
//if (strcmp(process, "powertop") == 0) //if (strcmp(process, "powertop") == 0)
// continue; // continue;
if (strcmp(process, "insmod") == 0) idx = index_in_strings("insmod\0modprobe\0swapper\0", process);
process = "[kernel module]"; if (idx != -1) {
if (strcmp(process, "modprobe") == 0) process = idx < 2 ? "[kernel module]" : "<kernel core>";
process = "[kernel module]"; }
if (strcmp(process, "swapper") == 0)
process = "<kernel core>";
strchrnul(p, '\n')[0] = '\0'; strchrnul(p, '\n')[0] = '\0';
{ // 46D\01136\0kondemand/1\0do_dbs_timer (delayed_work_timer_fn)
char *tmp; // ^ ^ ^
cnt = bb_strtoull(count, &tmp, 10); // count process func
p = tmp;
}
while (*p != '\0') {
if (*p++ == 'D') /* deferred */
goto skip;
}
//if (strchr(process, '[')) //if (strchr(process, '['))
sprintf(line, "%15.15s : %s", process, func); sprintf(line, "%15.15s : %s", process, func);
//else //else
// sprintf(line, "%s", process); // sprintf(line, "%s", process);
save_line(line, cnt); save_line(line, bb_strtoull(count, NULL, 10));
skip: ;
} }
fclose(fp); fclose(fp);
} }
n = 0; n = 0;
#if ENABLE_FEATURE_POWERTOP_PROCIRQ #if ENABLE_FEATURE_POWERTOP_PROCIRQ
if (strstr(buf, "total events")) { if (strstr(buf, " total events")) {
n = bb_strtoull(buf, NULL, 10) / G.total_cpus; n = bb_strtoull(buf, NULL, 10) / G.total_cpus;
if (n > 0 && n < G.interrupt_0) { if (n > 0 && n < G.interrupt_0) {
sprintf(line, " <interrupt> : %s", "extra timer interrupt"); sprintf(line, " <interrupt> : %s", "extra timer interrupt");
@ -566,7 +544,7 @@ static NOINLINE void print_intel_cstates(void)
if (!isdigit(d->d_name[3])) if (!isdigit(d->d_name[3]))
continue; continue;
len = sprintf(fname, "/sys/devices/system/cpu/%s/cpuidle", d->d_name); len = sprintf(fname, "%s/%s/cpuidle", "/sys/devices/system/cpu", d->d_name);
dir = opendir(fname); dir = opendir(fname);
if (!dir) if (!dir)
continue; continue;