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

perf stat: Pass struct outstate to printout()

The printout() takes a lot of arguments and sets an outstate with the
value. Instead, we can fill the outstate first and then pass it to
reduce the number of arguments.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Athira Jajeev <atrajeev@linux.vnet.ibm.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: James Clark <james.clark@arm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: https://lore.kernel.org/r/20221123180208.2068936-11-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Namhyung Kim and committed by
Arnaldo Carvalho de Melo
e7f4da31 922ae948

+18 -20
+18 -20
tools/perf/util/stat-display.c
··· 673 673 return false; 674 674 } 675 675 676 - static void printout(struct perf_stat_config *config, struct aggr_cpu_id id, int nr, 677 - struct evsel *counter, double uval, 678 - const char *prefix, u64 run, u64 ena, double noise, 676 + static void printout(struct perf_stat_config *config, struct outstate *os, 677 + double uval, u64 run, u64 ena, double noise, 679 678 struct runtime_stat *st, int map_idx) 680 679 { 681 680 struct perf_stat_output_ctx out; 682 - struct outstate os = { 683 - .fh = config->output, 684 - .prefix = prefix ? prefix : "", 685 - .id = id, 686 - .nr = nr, 687 - .evsel = counter, 688 - }; 689 681 print_metric_t pm; 690 682 new_line_t nl; 691 683 bool ok = true; 684 + struct evsel *counter = os->evsel; 692 685 693 686 if (config->csv_output) { 694 687 static const int aggr_fields[AGGR_MAX] = { ··· 697 704 698 705 pm = config->metric_only ? print_metric_only_csv : print_metric_csv; 699 706 nl = config->metric_only ? new_line_metric : new_line_csv; 700 - os.nfields = 3 + aggr_fields[config->aggr_mode] + (counter->cgrp ? 1 : 0); 707 + os->nfields = 3 + aggr_fields[config->aggr_mode] + (counter->cgrp ? 1 : 0); 701 708 } else if (config->json_output) { 702 709 pm = config->metric_only ? print_metric_only_json : print_metric_json; 703 710 nl = config->metric_only ? new_line_metric : new_line_json; ··· 708 715 709 716 if (run == 0 || ena == 0 || counter->counts->scaled == -1) { 710 717 if (config->metric_only) { 711 - pm(config, &os, NULL, "", "", 0); 718 + pm(config, os, NULL, "", "", 0); 712 719 return; 713 720 } 714 721 ··· 725 732 726 733 out.print_metric = pm; 727 734 out.new_line = nl; 728 - out.ctx = &os; 735 + out.ctx = os; 729 736 out.force_header = false; 730 737 731 738 if (!config->metric_only) { 732 - abs_printout(config, id, nr, counter, uval, ok); 739 + abs_printout(config, os->id, os->nr, counter, uval, ok); 733 740 734 741 print_noise(config, counter, noise, /*before_metric=*/true); 735 742 print_running(config, run, ena, /*before_metric=*/true); ··· 807 814 struct aggr_cpu_id id = config->aggr_map->map[s]; 808 815 double avg = aggr->counts.val; 809 816 bool metric_only = config->metric_only; 817 + struct outstate os = { 818 + .fh = config->output, 819 + .prefix = prefix ? prefix : "", 820 + .id = id, 821 + .nr = aggr->nr, 822 + .evsel = counter, 823 + }; 810 824 811 825 if (counter->supported && aggr->nr == 0) 812 826 return; ··· 834 834 835 835 uval = val * counter->scale; 836 836 837 - printout(config, id, aggr->nr, counter, uval, 838 - prefix, run, ena, avg, &rt_stat, s); 837 + printout(config, &os, uval, run, ena, avg, &rt_stat, s); 839 838 840 839 if (!metric_only) 841 840 fputc('\n', output); ··· 970 971 evlist__for_each_entry(evlist, counter) { 971 972 u64 ena, run, val; 972 973 double uval; 973 - struct aggr_cpu_id id; 974 974 struct perf_stat_evsel *ps = counter->stats; 975 975 int counter_idx = perf_cpu_map__idx(evsel__cpus(counter), cpu); 976 976 977 977 if (counter_idx < 0) 978 978 continue; 979 979 980 - id = aggr_cpu_id__cpu(cpu, /*data=*/NULL); 980 + os.evsel = counter; 981 + os.id = aggr_cpu_id__cpu(cpu, /*data=*/NULL); 981 982 if (first) { 982 983 print_metric_begin(config, evlist, &os, counter_idx); 983 984 first = false; ··· 987 988 run = ps->aggr[counter_idx].counts.run; 988 989 989 990 uval = val * counter->scale; 990 - printout(config, id, 0, counter, uval, prefix, 991 - run, ena, 1.0, &rt_stat, counter_idx); 991 + printout(config, &os, uval, run, ena, 1.0, &rt_stat, counter_idx); 992 992 } 993 993 if (!first) 994 994 print_metric_end(config);