diff options
author | Maksym Kryzhanovskyy <xmaks@email.cz> | 2010-11-04 08:41:57 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-11-04 08:41:57 +0100 |
commit | 6052c2b0be796bc92c870b8261f49bc1584877b9 (patch) | |
tree | 6d038ebf46782db302166225855c460817a3a4a5 | |
parent | 854738d39d121378921f8c05f268ff513904a618 (diff) | |
download | busybox-w32-6052c2b0be796bc92c870b8261f49bc1584877b9.tar.gz busybox-w32-6052c2b0be796bc92c870b8261f49bc1584877b9.tar.bz2 busybox-w32-6052c2b0be796bc92c870b8261f49bc1584877b9.zip |
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>
-rw-r--r-- | procps/powertop.c | 92 |
1 files changed, 35 insertions, 57 deletions
diff --git a/procps/powertop.c b/procps/powertop.c index 77b071ffb..4c3c3565e 100644 --- a/procps/powertop.c +++ b/procps/powertop.c | |||
@@ -169,7 +169,7 @@ static void read_cstate_counts(ullong *usage, ullong *duration) | |||
169 | if (len < 3 || len > BIG_SYSNAME_LEN) | 169 | if (len < 3 || len > BIG_SYSNAME_LEN) |
170 | continue; | 170 | continue; |
171 | 171 | ||
172 | sprintf(buf, "/proc/acpi/processor/%s/power", d->d_name); | 172 | sprintf(buf, "%s/%s/power", "/proc/acpi/processor", d->d_name); |
173 | fp = fopen_for_read(buf); | 173 | fp = fopen_for_read(buf); |
174 | if (!fp) | 174 | if (!fp) |
175 | continue; | 175 | continue; |
@@ -321,28 +321,17 @@ static void process_irq_counts(void) | |||
321 | /* 0: 143646045 153901007 IO-APIC-edge timer | 321 | /* 0: 143646045 153901007 IO-APIC-edge timer |
322 | * ^ | 322 | * ^ |
323 | */ | 323 | */ |
324 | *p = '\0'; | ||
324 | /* Deal with non-maskable interrupts -- make up fake numbers */ | 325 | /* Deal with non-maskable interrupts -- make up fake numbers */ |
325 | nr = -1; | 326 | nr = index_in_strings("NMI\0RES\nCAL\0TLB\0TRM\0THR\0SPU\0", buf); |
326 | if (buf[0] != ' ' && !isdigit(buf[0])) { | 327 | if (nr != -1) { |
327 | //TODO: optimize | 328 | nr += 20000; |
328 | if (strncmp(buf, "NMI:", 4) == 0) | ||
329 | nr = 20000; | ||
330 | if (strncmp(buf, "RES:", 4) == 0) | ||
331 | nr = 20001; | ||
332 | if (strncmp(buf, "CAL:", 4) == 0) | ||
333 | nr = 20002; | ||
334 | if (strncmp(buf, "TLB:", 4) == 0) | ||
335 | nr = 20003; | ||
336 | if (strncmp(buf, "TRM:", 4) == 0) | ||
337 | nr = 20004; | ||
338 | if (strncmp(buf, "THR:", 4) == 0) | ||
339 | nr = 20005; | ||
340 | if (strncmp(buf, "SPU:", 4) == 0) | ||
341 | nr = 20006; | ||
342 | } else { | 329 | } else { |
343 | /* bb_strtou doesn't eat leading spaces, using strtoul */ | 330 | /* bb_strtou doesn't eat leading spaces, using strtoul */ |
344 | nr = strtoul(buf, NULL, 10); | 331 | nr = strtoul(buf, NULL, 10); |
345 | } | 332 | } |
333 | *p = ':'; | ||
334 | |||
346 | if (nr == -1) | 335 | if (nr == -1) |
347 | continue; | 336 | continue; |
348 | 337 | ||
@@ -430,33 +419,31 @@ static NOINLINE int process_timer_stats(void) | |||
430 | while (fgets(buf, sizeof(buf), fp)) { | 419 | while (fgets(buf, sizeof(buf), fp)) { |
431 | const char *count, *process, *func; | 420 | const char *count, *process, *func; |
432 | char *p; | 421 | char *p; |
433 | int cnt; | 422 | int idx; |
434 | 423 | ||
435 | count = skip_whitespace(buf); | 424 | count = skip_whitespace(buf); |
425 | if (strcmp(strchrnul(count, ' '), " total events") == 0) | ||
426 | break; | ||
436 | p = strchr(count, ','); | 427 | p = strchr(count, ','); |
437 | if (!p) | 428 | if (!p) |
438 | continue; | 429 | continue; |
439 | *p++ = '\0'; | 430 | *p++ = '\0'; |
440 | if (strcmp(strchrnul(count, ' '), " total events") == 0) | 431 | if (strchr(count, 'D')) |
441 | break; | 432 | continue; /* deferred */ |
442 | p = skip_whitespace(p); /* points to pid */ | 433 | p = skip_whitespace(p); /* points to pid now */ |
443 | 434 | process = NULL; | |
444 | /* Find char ' ', then eat remaining spaces */ | 435 | get_func_name: |
445 | #define ADVANCE(p) do { \ | 436 | p = strchr(p, ' '); |
446 | (p) = strchr((p), ' '); \ | 437 | if (!p) |
447 | if (!(p)) \ | 438 | continue; |
448 | continue; \ | 439 | *p++ = '\0'; |
449 | *(p) = '\0'; \ | 440 | p = skip_whitespace(p); |
450 | (p)++; \ | 441 | if (process == NULL) { |
451 | (p) = skip_whitespace(p); \ | 442 | process = p; |
452 | } while (0) | 443 | goto get_func_name; |
453 | /* Get process name */ | 444 | } |
454 | ADVANCE(p); | ||
455 | process = p; | ||
456 | /* Get function */ | ||
457 | ADVANCE(p); | ||
458 | func = p; | 445 | func = p; |
459 | #undef ADVANCE | 446 | |
460 | //if (strcmp(process, "swapper") == 0 | 447 | //if (strcmp(process, "swapper") == 0 |
461 | // && strcmp(func, "hrtimer_start_range_ns (tick_sched_timer)\n") == 0 | 448 | // && strcmp(func, "hrtimer_start_range_ns (tick_sched_timer)\n") == 0 |
462 | //) { | 449 | //) { |
@@ -471,38 +458,29 @@ static NOINLINE int process_timer_stats(void) | |||
471 | //if (strcmp(process, "powertop") == 0) | 458 | //if (strcmp(process, "powertop") == 0) |
472 | // continue; | 459 | // continue; |
473 | 460 | ||
474 | if (strcmp(process, "insmod") == 0) | 461 | idx = index_in_strings("insmod\0modprobe\0swapper\0", process); |
475 | process = "[kernel module]"; | 462 | if (idx != -1) { |
476 | if (strcmp(process, "modprobe") == 0) | 463 | process = idx < 2 ? "[kernel module]" : "<kernel core>"; |
477 | process = "[kernel module]"; | 464 | } |
478 | if (strcmp(process, "swapper") == 0) | ||
479 | process = "<kernel core>"; | ||
480 | 465 | ||
481 | strchrnul(p, '\n')[0] = '\0'; | 466 | strchrnul(p, '\n')[0] = '\0'; |
482 | 467 | ||
483 | { | 468 | // 46D\01136\0kondemand/1\0do_dbs_timer (delayed_work_timer_fn) |
484 | char *tmp; | 469 | // ^ ^ ^ |
485 | cnt = bb_strtoull(count, &tmp, 10); | 470 | // count process func |
486 | p = tmp; | ||
487 | } | ||
488 | while (*p != '\0') { | ||
489 | if (*p++ == 'D') /* deferred */ | ||
490 | goto skip; | ||
491 | } | ||
492 | 471 | ||
493 | //if (strchr(process, '[')) | 472 | //if (strchr(process, '[')) |
494 | sprintf(line, "%15.15s : %s", process, func); | 473 | sprintf(line, "%15.15s : %s", process, func); |
495 | //else | 474 | //else |
496 | // sprintf(line, "%s", process); | 475 | // sprintf(line, "%s", process); |
497 | save_line(line, cnt); | 476 | save_line(line, bb_strtoull(count, NULL, 10)); |
498 | skip: ; | ||
499 | } | 477 | } |
500 | fclose(fp); | 478 | fclose(fp); |
501 | } | 479 | } |
502 | 480 | ||
503 | n = 0; | 481 | n = 0; |
504 | #if ENABLE_FEATURE_POWERTOP_PROCIRQ | 482 | #if ENABLE_FEATURE_POWERTOP_PROCIRQ |
505 | if (strstr(buf, "total events")) { | 483 | if (strstr(buf, " total events")) { |
506 | n = bb_strtoull(buf, NULL, 10) / G.total_cpus; | 484 | n = bb_strtoull(buf, NULL, 10) / G.total_cpus; |
507 | if (n > 0 && n < G.interrupt_0) { | 485 | if (n > 0 && n < G.interrupt_0) { |
508 | sprintf(line, " <interrupt> : %s", "extra timer interrupt"); | 486 | sprintf(line, " <interrupt> : %s", "extra timer interrupt"); |
@@ -566,7 +544,7 @@ static NOINLINE void print_intel_cstates(void) | |||
566 | if (!isdigit(d->d_name[3])) | 544 | if (!isdigit(d->d_name[3])) |
567 | continue; | 545 | continue; |
568 | 546 | ||
569 | len = sprintf(fname, "/sys/devices/system/cpu/%s/cpuidle", d->d_name); | 547 | len = sprintf(fname, "%s/%s/cpuidle", "/sys/devices/system/cpu", d->d_name); |
570 | dir = opendir(fname); | 548 | dir = opendir(fname); |
571 | if (!dir) | 549 | if (!dir) |
572 | continue; | 550 | continue; |