Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf stat: Use common printout function to avoid duplicated code

Instead of every caller deciding whether to call abs or nsec printout
do it all in a single central function. No functional changes.

Signed-off-by: Andi Kleen <ak@linux.intel.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Link: http://lkml.kernel.org/r/1446515428-7450-3-git-send-email-andi@firstfloor.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Andi Kleen and committed by
Arnaldo Carvalho de Melo
eedfcb4b 4579ecc8

+20 -37
+20 -37
tools/perf/builtin-stat.c
··· 493 493 double msecs = avg / 1e6; 494 494 const char *fmt_v, *fmt_n; 495 495 char name[25]; 496 - int cpu = cpu_map__id_to_cpu(id); 497 496 498 497 fmt_v = csv_output ? "%.6f%s" : "%18.6f%s"; 499 498 fmt_n = csv_output ? "%s" : "%-25s"; ··· 513 514 514 515 if (evsel->cgrp) 515 516 fprintf(output, "%s%s", csv_sep, evsel->cgrp->name); 516 - 517 - if (csv_output || stat_config.interval) 518 - return; 519 - 520 - perf_stat__print_shadow_stats(output, evsel, avg, cpu, 521 - stat_config.aggr_mode); 522 517 } 523 518 524 519 static void abs_printout(int id, int nr, struct perf_evsel *evsel, double avg) ··· 520 527 FILE *output = stat_config.output; 521 528 double sc = evsel->scale; 522 529 const char *fmt; 523 - int cpu = cpu_map__id_to_cpu(id); 524 530 525 531 if (csv_output) { 526 532 fmt = sc != 1.0 ? "%.2f%s" : "%.0f%s"; ··· 532 540 533 541 aggr_printout(evsel, id, nr); 534 542 535 - if (stat_config.aggr_mode == AGGR_GLOBAL) 536 - cpu = 0; 537 - 538 543 fprintf(output, fmt, avg, csv_sep); 539 544 540 545 if (evsel->unit) ··· 543 554 544 555 if (evsel->cgrp) 545 556 fprintf(output, "%s%s", csv_sep, evsel->cgrp->name); 557 + } 546 558 547 - if (csv_output || stat_config.interval) 548 - return; 559 + static void printout(int id, int nr, struct perf_evsel *counter, double uval) 560 + { 561 + int cpu = cpu_map__id_to_cpu(id); 549 562 550 - perf_stat__print_shadow_stats(output, evsel, avg, cpu, 551 - stat_config.aggr_mode); 563 + if (stat_config.aggr_mode == AGGR_GLOBAL) 564 + cpu = 0; 565 + 566 + if (nsec_counter(counter)) 567 + nsec_printout(id, nr, counter, uval); 568 + else 569 + abs_printout(id, nr, counter, uval); 570 + 571 + if (!csv_output && !stat_config.interval) 572 + perf_stat__print_shadow_stats(stat_config.output, counter, 573 + uval, cpu, 574 + stat_config.aggr_mode); 552 575 } 553 576 554 577 static void print_aggr(char *prefix) ··· 616 615 continue; 617 616 } 618 617 uval = val * counter->scale; 619 - 620 - if (nsec_counter(counter)) 621 - nsec_printout(id, nr, counter, uval); 622 - else 623 - abs_printout(id, nr, counter, uval); 624 - 618 + printout(id, nr, counter, uval); 625 619 if (!csv_output) 626 620 print_noise(counter, 1.0); 627 621 ··· 647 651 fprintf(output, "%s", prefix); 648 652 649 653 uval = val * counter->scale; 650 - 651 - if (nsec_counter(counter)) 652 - nsec_printout(thread, 0, counter, uval); 653 - else 654 - abs_printout(thread, 0, counter, uval); 654 + printout(thread, 0, counter, uval); 655 655 656 656 if (!csv_output) 657 657 print_noise(counter, 1.0); ··· 697 705 } 698 706 699 707 uval = avg * counter->scale; 700 - 701 - if (nsec_counter(counter)) 702 - nsec_printout(-1, 0, counter, uval); 703 - else 704 - abs_printout(-1, 0, counter, uval); 708 + printout(-1, 0, counter, uval); 705 709 706 710 print_noise(counter, avg); 707 711 ··· 750 762 } 751 763 752 764 uval = val * counter->scale; 753 - 754 - if (nsec_counter(counter)) 755 - nsec_printout(cpu, 0, counter, uval); 756 - else 757 - abs_printout(cpu, 0, counter, uval); 758 - 765 + printout(cpu, 0, counter, uval); 759 766 if (!csv_output) 760 767 print_noise(counter, 1.0); 761 768 print_running(run, ena);