Skip to content

Commit eedfcb4

Browse files
Andi Kleenacmel
authored andcommitted
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>
1 parent 4579ecc commit eedfcb4

1 file changed

Lines changed: 20 additions & 37 deletions

File tree

‎tools/perf/builtin-stat.c‎

Lines changed: 20 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,6 @@ static void nsec_printout(int id, int nr, struct perf_evsel *evsel, double avg)
493493
double msecs = avg / 1e6;
494494
const char *fmt_v, *fmt_n;
495495
char name[25];
496-
int cpu = cpu_map__id_to_cpu(id);
497496

498497
fmt_v = csv_output ? "%.6f%s" : "%18.6f%s";
499498
fmt_n = csv_output ? "%s" : "%-25s";
@@ -514,20 +513,13 @@ static void nsec_printout(int id, int nr, struct perf_evsel *evsel, double avg)
514513

515514
if (evsel->cgrp)
516515
fprintf(output, "%s%s", csv_sep, evsel->cgrp->name);
517-
518-
if (csv_output || stat_config.interval)
519-
return;
520-
521-
perf_stat__print_shadow_stats(output, evsel, avg, cpu,
522-
stat_config.aggr_mode);
523516
}
524517

525518
static void abs_printout(int id, int nr, struct perf_evsel *evsel, double avg)
526519
{
527520
FILE *output = stat_config.output;
528521
double sc = evsel->scale;
529522
const char *fmt;
530-
int cpu = cpu_map__id_to_cpu(id);
531523

532524
if (csv_output) {
533525
fmt = sc != 1.0 ? "%.2f%s" : "%.0f%s";
@@ -540,9 +532,6 @@ static void abs_printout(int id, int nr, struct perf_evsel *evsel, double avg)
540532

541533
aggr_printout(evsel, id, nr);
542534

543-
if (stat_config.aggr_mode == AGGR_GLOBAL)
544-
cpu = 0;
545-
546535
fprintf(output, fmt, avg, csv_sep);
547536

548537
if (evsel->unit)
@@ -554,12 +543,24 @@ static void abs_printout(int id, int nr, struct perf_evsel *evsel, double avg)
554543

555544
if (evsel->cgrp)
556545
fprintf(output, "%s%s", csv_sep, evsel->cgrp->name);
546+
}
557547

558-
if (csv_output || stat_config.interval)
559-
return;
548+
static void printout(int id, int nr, struct perf_evsel *counter, double uval)
549+
{
550+
int cpu = cpu_map__id_to_cpu(id);
551+
552+
if (stat_config.aggr_mode == AGGR_GLOBAL)
553+
cpu = 0;
554+
555+
if (nsec_counter(counter))
556+
nsec_printout(id, nr, counter, uval);
557+
else
558+
abs_printout(id, nr, counter, uval);
560559

561-
perf_stat__print_shadow_stats(output, evsel, avg, cpu,
562-
stat_config.aggr_mode);
560+
if (!csv_output && !stat_config.interval)
561+
perf_stat__print_shadow_stats(stat_config.output, counter,
562+
uval, cpu,
563+
stat_config.aggr_mode);
563564
}
564565

565566
static void print_aggr(char *prefix)
@@ -615,12 +616,7 @@ static void print_aggr(char *prefix)
615616
continue;
616617
}
617618
uval = val * counter->scale;
618-
619-
if (nsec_counter(counter))
620-
nsec_printout(id, nr, counter, uval);
621-
else
622-
abs_printout(id, nr, counter, uval);
623-
619+
printout(id, nr, counter, uval);
624620
if (!csv_output)
625621
print_noise(counter, 1.0);
626622

@@ -651,11 +647,7 @@ static void print_aggr_thread(struct perf_evsel *counter, char *prefix)
651647
fprintf(output, "%s", prefix);
652648

653649
uval = val * counter->scale;
654-
655-
if (nsec_counter(counter))
656-
nsec_printout(thread, 0, counter, uval);
657-
else
658-
abs_printout(thread, 0, counter, uval);
650+
printout(thread, 0, counter, uval);
659651

660652
if (!csv_output)
661653
print_noise(counter, 1.0);
@@ -705,11 +697,7 @@ static void print_counter_aggr(struct perf_evsel *counter, char *prefix)
705697
}
706698

707699
uval = avg * counter->scale;
708-
709-
if (nsec_counter(counter))
710-
nsec_printout(-1, 0, counter, uval);
711-
else
712-
abs_printout(-1, 0, counter, uval);
700+
printout(-1, 0, counter, uval);
713701

714702
print_noise(counter, avg);
715703

@@ -762,12 +750,7 @@ static void print_counter(struct perf_evsel *counter, char *prefix)
762750
}
763751

764752
uval = val * counter->scale;
765-
766-
if (nsec_counter(counter))
767-
nsec_printout(cpu, 0, counter, uval);
768-
else
769-
abs_printout(cpu, 0, counter, uval);
770-
753+
printout(cpu, 0, counter, uval);
771754
if (!csv_output)
772755
print_noise(counter, 1.0);
773756
print_running(run, ena);

0 commit comments

Comments
 (0)