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

Configure Feed

Select the types of activity you want to include in your feed.

perf stat: Move stat_config into config.c

stat_config is accessed by config.c via helper functions, but declared
in builtin-stat. Move to util/config.c so that stub functions aren't
needed in python.c which doesn't link against the builtin files.

To avoid name conflicts change builtin-script to use the same
stat_config as builtin-stat. Rename local variables in tests to avoid
shadow declaration warnings.

Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Acked-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: Colin Ian King <colin.i.king@gmail.com>
Cc: Dapeng Mi <dapeng1.mi@linux.intel.com>
Cc: Howard Chu <howardchu95@gmail.com>
Cc: Ilya Leoshkevich <iii@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Veronika Molnarova <vmolnaro@redhat.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Link: https://lore.kernel.org/r/20241119011644.971342-9-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Ian Rogers and committed by
Arnaldo Carvalho de Melo
9557d156 d927e30c

+38 -46
-1
tools/perf/builtin-script.c
··· 85 85 static bool print_flags; 86 86 static const char *cpu_list; 87 87 static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS); 88 - static struct perf_stat_config stat_config; 89 88 static int max_blocks; 90 89 static bool native_arch; 91 90 static struct dlfilter *dlfilter;
-27
tools/perf/builtin-stat.c
··· 112 112 .uid = UINT_MAX, 113 113 }; 114 114 115 - #define METRIC_ONLY_LEN 20 116 - 117 115 static volatile sig_atomic_t child_pid = -1; 118 116 static int detailed_run = 0; 119 117 static bool transaction_run; ··· 148 150 #define STAT_RECORD perf_stat.record 149 151 150 152 static volatile sig_atomic_t done = 0; 151 - 152 - static struct perf_stat_config stat_config = { 153 - .aggr_mode = AGGR_GLOBAL, 154 - .aggr_level = MAX_CACHE_LVL + 1, 155 - .scale = true, 156 - .unit_width = 4, /* strlen("unit") */ 157 - .run_count = 1, 158 - .metric_only_len = METRIC_ONLY_LEN, 159 - .walltime_nsecs_stats = &walltime_nsecs_stats, 160 - .ru_stats = &ru_stats, 161 - .big_num = true, 162 - .ctl_fd = -1, 163 - .ctl_fd_ack = -1, 164 - .iostat_run = false, 165 - }; 166 153 167 154 /* Options set from the command line. */ 168 155 struct opt_aggr_mode { ··· 1052 1069 1053 1070 signal(signr, SIG_DFL); 1054 1071 kill(getpid(), signr); 1055 - } 1056 - 1057 - void perf_stat__set_big_num(int set) 1058 - { 1059 - stat_config.big_num = (set != 0); 1060 - } 1061 - 1062 - void perf_stat__set_no_csv_summary(int set) 1063 - { 1064 - stat_config.no_csv_summary = (set != 0); 1065 1072 } 1066 1073 1067 1074 static int stat__set_big_num(const struct option *opt __maybe_unused,
+9 -7
tools/perf/tests/stat.c
··· 27 27 struct machine *machine __maybe_unused) 28 28 { 29 29 struct perf_record_stat_config *config = &event->stat_config; 30 - struct perf_stat_config stat_config = {}; 30 + struct perf_stat_config test_stat_config = {}; 31 31 32 32 #define HAS(term, val) \ 33 33 has_term(config, PERF_STAT_CONFIG_TERM__##term, val) ··· 39 39 40 40 #undef HAS 41 41 42 - perf_event__read_stat_config(&stat_config, config); 42 + perf_event__read_stat_config(&test_stat_config, config); 43 43 44 - TEST_ASSERT_VAL("wrong aggr_mode", stat_config.aggr_mode == AGGR_CORE); 45 - TEST_ASSERT_VAL("wrong scale", stat_config.scale == 1); 46 - TEST_ASSERT_VAL("wrong interval", stat_config.interval == 1); 44 + TEST_ASSERT_VAL("wrong aggr_mode", test_stat_config.aggr_mode == AGGR_CORE); 45 + TEST_ASSERT_VAL("wrong scale", test_stat_config.scale == 1); 46 + TEST_ASSERT_VAL("wrong interval", test_stat_config.interval == 1); 47 47 return 0; 48 48 } 49 49 50 50 static int test__synthesize_stat_config(struct test_suite *test __maybe_unused, 51 51 int subtest __maybe_unused) 52 52 { 53 - struct perf_stat_config stat_config = { 53 + struct perf_stat_config test_stat_config = { 54 54 .aggr_mode = AGGR_CORE, 55 55 .scale = 1, 56 56 .interval = 1, 57 57 }; 58 58 59 59 TEST_ASSERT_VAL("failed to synthesize stat_config", 60 - !perf_event__synthesize_stat_config(NULL, &stat_config, process_stat_config_event, NULL)); 60 + !perf_event__synthesize_stat_config(NULL, &test_stat_config, 61 + process_stat_config_event, 62 + NULL)); 61 63 62 64 return 0; 63 65 }
+27
tools/perf/util/config.c
··· 13 13 #include <sys/param.h> 14 14 #include "cache.h" 15 15 #include "callchain.h" 16 + #include "header.h" 16 17 #include <subcmd/exec-cmd.h> 17 18 #include "util/event.h" /* proc_map_timeout */ 18 19 #include "util/hist.h" /* perf_hist_config */ ··· 35 34 36 35 #define DEBUG_CACHE_DIR ".debug" 37 36 37 + #define METRIC_ONLY_LEN 20 38 + 39 + struct perf_stat_config stat_config = { 40 + .aggr_mode = AGGR_GLOBAL, 41 + .aggr_level = MAX_CACHE_LVL + 1, 42 + .scale = true, 43 + .unit_width = 4, /* strlen("unit") */ 44 + .run_count = 1, 45 + .metric_only_len = METRIC_ONLY_LEN, 46 + .walltime_nsecs_stats = &walltime_nsecs_stats, 47 + .ru_stats = &ru_stats, 48 + .big_num = true, 49 + .ctl_fd = -1, 50 + .ctl_fd_ack = -1, 51 + .iostat_run = false, 52 + }; 38 53 39 54 char buildid_dir[MAXPATHLEN]; /* root dir for buildid, binary cache */ 40 55 ··· 470 453 symbol_conf.show_hist_headers = perf_config_bool(var, value); 471 454 472 455 return 0; 456 + } 457 + 458 + void perf_stat__set_big_num(int set) 459 + { 460 + stat_config.big_num = (set != 0); 461 + } 462 + 463 + static void perf_stat__set_no_csv_summary(int set) 464 + { 465 + stat_config.no_csv_summary = (set != 0); 473 466 } 474 467 475 468 static int perf_stat_config(const char *var, const char *value)
-10
tools/perf/util/python.c
··· 17 17 #include "trace-event.h" 18 18 #include "mmap.h" 19 19 #include "util/env.h" 20 - #include "util/kvm-stat.h" 21 - #include "util/stat.h" 22 20 #include "util/kwork.h" 23 21 #include "util/sample.h" 24 22 #include "util/lock-contention.h" ··· 1304 1306 1305 1307 /* The following are stubs to avoid dragging in builtin-* objects. */ 1306 1308 /* TODO: move the code out of the builtin-* file into util. */ 1307 - 1308 - void perf_stat__set_no_csv_summary(int set __maybe_unused) 1309 - { 1310 - } 1311 - 1312 - void perf_stat__set_big_num(int set __maybe_unused) 1313 - { 1314 - } 1315 1309 1316 1310 int script_spec_register(const char *spec __maybe_unused, struct scripting_ops *ops __maybe_unused) 1317 1311 {
+2 -1
tools/perf/util/stat.h
··· 117 117 unsigned int topdown_level; 118 118 }; 119 119 120 + extern struct perf_stat_config stat_config; 121 + 120 122 void perf_stat__set_big_num(int set); 121 - void perf_stat__set_no_csv_summary(int set); 122 123 123 124 void update_stats(struct stats *stats, u64 val); 124 125 double avg_stats(struct stats *stats);