Skip to content

Commit 6e19839

Browse files
captain5050namhyung
authored andcommitted
perf sort: Use perf_env to set arch sort keys and header
Previously arch_support_sort_key and arch_perf_header_entry used a weak symbol to compile as appropriate for x86 and powerpc. A limitation to this is that the handling of a data file could vary in cross-platform development. Change to using the perf_env of the current session to determine the architecture kind and set the sort key and header entries as appropriate. Signed-off-by: Ian Rogers <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Namhyung Kim <[email protected]>
1 parent a563c9f commit 6e19839

File tree

15 files changed

+107
-131
lines changed

15 files changed

+107
-131
lines changed

tools/perf/arch/powerpc/util/Build

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ perf-util-y += mem-events.o
55
perf-util-y += pmu.o
66
perf-util-y += sym-handling.o
77
perf-util-y += evsel.o
8-
perf-util-y += event.o
98

109
perf-util-$(CONFIG_LIBDW) += skip-callchain-idx.o
1110

tools/perf/arch/powerpc/util/event.c

Lines changed: 0 additions & 34 deletions
This file was deleted.

tools/perf/arch/x86/util/event.c

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -91,22 +91,3 @@ int perf_event__synthesize_extra_kmaps(const struct perf_tool *tool,
9191
}
9292

9393
#endif
94-
95-
const char *arch_perf_header_entry(const char *se_header)
96-
{
97-
if (!strcmp(se_header, "Local Pipeline Stage Cycle"))
98-
return "Local Retire Latency";
99-
else if (!strcmp(se_header, "Pipeline Stage Cycle"))
100-
return "Retire Latency";
101-
102-
return se_header;
103-
}
104-
105-
int arch_support_sort_key(const char *sort_key)
106-
{
107-
if (!strcmp(sort_key, "p_stage_cyc"))
108-
return 1;
109-
if (!strcmp(sort_key, "local_p_stage_cyc"))
110-
return 1;
111-
return 0;
112-
}

tools/perf/builtin-annotate.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,7 @@ int cmd_annotate(int argc, const char **argv)
947947
annotate_opts.show_br_cntr = true;
948948
}
949949

950-
if (setup_sorting(NULL) < 0)
950+
if (setup_sorting(/*evlist=*/NULL, perf_session__env(annotate.session)) < 0)
951951
usage_with_options(annotate_usage, options);
952952

953953
ret = __cmd_annotate(&annotate);

tools/perf/builtin-c2c.c

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,14 @@ static struct hist_entry_ops c2c_entry_ops = {
195195

196196
static int c2c_hists__init(struct c2c_hists *hists,
197197
const char *sort,
198-
int nr_header_lines);
198+
int nr_header_lines,
199+
struct perf_env *env);
199200

200201
static struct c2c_hists*
201202
he__get_c2c_hists(struct hist_entry *he,
202203
const char *sort,
203-
int nr_header_lines)
204+
int nr_header_lines,
205+
struct perf_env *env)
204206
{
205207
struct c2c_hist_entry *c2c_he;
206208
struct c2c_hists *hists;
@@ -214,7 +216,7 @@ he__get_c2c_hists(struct hist_entry *he,
214216
if (!hists)
215217
return NULL;
216218

217-
ret = c2c_hists__init(hists, sort, nr_header_lines);
219+
ret = c2c_hists__init(hists, sort, nr_header_lines, env);
218220
if (ret) {
219221
free(hists);
220222
return NULL;
@@ -350,7 +352,7 @@ static int process_sample_event(const struct perf_tool *tool __maybe_unused,
350352

351353
mi = mi_dup;
352354

353-
c2c_hists = he__get_c2c_hists(he, c2c.cl_sort, 2);
355+
c2c_hists = he__get_c2c_hists(he, c2c.cl_sort, 2, machine->env);
354356
if (!c2c_hists)
355357
goto free_mi;
356358

@@ -1966,7 +1968,8 @@ static struct c2c_fmt *get_format(const char *name)
19661968
return c2c_fmt;
19671969
}
19681970

1969-
static int c2c_hists__init_output(struct perf_hpp_list *hpp_list, char *name)
1971+
static int c2c_hists__init_output(struct perf_hpp_list *hpp_list, char *name,
1972+
struct perf_env *env __maybe_unused)
19701973
{
19711974
struct c2c_fmt *c2c_fmt = get_format(name);
19721975
int level = 0;
@@ -1980,14 +1983,14 @@ static int c2c_hists__init_output(struct perf_hpp_list *hpp_list, char *name)
19801983
return 0;
19811984
}
19821985

1983-
static int c2c_hists__init_sort(struct perf_hpp_list *hpp_list, char *name)
1986+
static int c2c_hists__init_sort(struct perf_hpp_list *hpp_list, char *name, struct perf_env *env)
19841987
{
19851988
struct c2c_fmt *c2c_fmt = get_format(name);
19861989
struct c2c_dimension *dim;
19871990

19881991
if (!c2c_fmt) {
19891992
reset_dimensions();
1990-
return sort_dimension__add(hpp_list, name, NULL, 0);
1993+
return sort_dimension__add(hpp_list, name, /*evlist=*/NULL, env, /*level=*/0);
19911994
}
19921995

19931996
dim = c2c_fmt->dim;
@@ -2008,7 +2011,7 @@ static int c2c_hists__init_sort(struct perf_hpp_list *hpp_list, char *name)
20082011
\
20092012
for (tok = strtok_r((char *)_list, ", ", &tmp); \
20102013
tok; tok = strtok_r(NULL, ", ", &tmp)) { \
2011-
ret = _fn(hpp_list, tok); \
2014+
ret = _fn(hpp_list, tok, env); \
20122015
if (ret == -EINVAL) { \
20132016
pr_err("Invalid --fields key: `%s'", tok); \
20142017
break; \
@@ -2021,7 +2024,8 @@ static int c2c_hists__init_sort(struct perf_hpp_list *hpp_list, char *name)
20212024

20222025
static int hpp_list__parse(struct perf_hpp_list *hpp_list,
20232026
const char *output_,
2024-
const char *sort_)
2027+
const char *sort_,
2028+
struct perf_env *env)
20252029
{
20262030
char *output = output_ ? strdup(output_) : NULL;
20272031
char *sort = sort_ ? strdup(sort_) : NULL;
@@ -2052,7 +2056,8 @@ static int hpp_list__parse(struct perf_hpp_list *hpp_list,
20522056

20532057
static int c2c_hists__init(struct c2c_hists *hists,
20542058
const char *sort,
2055-
int nr_header_lines)
2059+
int nr_header_lines,
2060+
struct perf_env *env)
20562061
{
20572062
__hists__init(&hists->hists, &hists->list);
20582063

@@ -2066,15 +2071,16 @@ static int c2c_hists__init(struct c2c_hists *hists,
20662071
/* Overload number of header lines.*/
20672072
hists->list.nr_header_lines = nr_header_lines;
20682073

2069-
return hpp_list__parse(&hists->list, NULL, sort);
2074+
return hpp_list__parse(&hists->list, /*output=*/NULL, sort, env);
20702075
}
20712076

20722077
static int c2c_hists__reinit(struct c2c_hists *c2c_hists,
20732078
const char *output,
2074-
const char *sort)
2079+
const char *sort,
2080+
struct perf_env *env)
20752081
{
20762082
perf_hpp__reset_output_field(&c2c_hists->list);
2077-
return hpp_list__parse(&c2c_hists->list, output, sort);
2083+
return hpp_list__parse(&c2c_hists->list, output, sort, env);
20782084
}
20792085

20802086
#define DISPLAY_LINE_LIMIT 0.001
@@ -2207,8 +2213,9 @@ static int filter_cb(struct hist_entry *he, void *arg __maybe_unused)
22072213
return 0;
22082214
}
22092215

2210-
static int resort_cl_cb(struct hist_entry *he, void *arg __maybe_unused)
2216+
static int resort_cl_cb(struct hist_entry *he, void *arg)
22112217
{
2218+
struct perf_env *env = arg;
22122219
struct c2c_hist_entry *c2c_he;
22132220
struct c2c_hists *c2c_hists;
22142221
bool display = he__display(he, &c2c.shared_clines_stats);
@@ -2222,7 +2229,7 @@ static int resort_cl_cb(struct hist_entry *he, void *arg __maybe_unused)
22222229
c2c_he->cacheline_idx = idx++;
22232230
calc_width(c2c_he);
22242231

2225-
c2c_hists__reinit(c2c_hists, c2c.cl_output, c2c.cl_resort);
2232+
c2c_hists__reinit(c2c_hists, c2c.cl_output, c2c.cl_resort, env);
22262233

22272234
hists__collapse_resort(&c2c_hists->hists, NULL);
22282235
hists__output_resort_cb(&c2c_hists->hists, NULL, filter_cb);
@@ -2334,7 +2341,7 @@ static int resort_shared_cl_cb(struct hist_entry *he, void *arg __maybe_unused)
23342341
return 0;
23352342
}
23362343

2337-
static int hists__iterate_cb(struct hists *hists, hists__resort_cb_t cb)
2344+
static int hists__iterate_cb(struct hists *hists, hists__resort_cb_t cb, void *arg)
23382345
{
23392346
struct rb_node *next = rb_first_cached(&hists->entries);
23402347
int ret = 0;
@@ -2343,7 +2350,7 @@ static int hists__iterate_cb(struct hists *hists, hists__resort_cb_t cb)
23432350
struct hist_entry *he;
23442351

23452352
he = rb_entry(next, struct hist_entry, rb_node);
2346-
ret = cb(he, NULL);
2353+
ret = cb(he, arg);
23472354
if (ret)
23482355
break;
23492356
next = rb_next(&he->rb_node);
@@ -2449,7 +2456,7 @@ static void print_cacheline(struct c2c_hists *c2c_hists,
24492456
hists__fprintf(&c2c_hists->hists, false, 0, 0, 0, out, false);
24502457
}
24512458

2452-
static void print_pareto(FILE *out)
2459+
static void print_pareto(FILE *out, struct perf_env *env)
24532460
{
24542461
struct perf_hpp_list hpp_list;
24552462
struct rb_node *nd;
@@ -2474,7 +2481,7 @@ static void print_pareto(FILE *out)
24742481
"dcacheline";
24752482

24762483
perf_hpp_list__init(&hpp_list);
2477-
ret = hpp_list__parse(&hpp_list, cl_output, NULL);
2484+
ret = hpp_list__parse(&hpp_list, cl_output, /*evlist=*/NULL, env);
24782485

24792486
if (WARN_ONCE(ret, "failed to setup sort entries\n"))
24802487
return;
@@ -2539,7 +2546,7 @@ static void perf_c2c__hists_fprintf(FILE *out, struct perf_session *session)
25392546
fprintf(out, "=================================================\n");
25402547
fprintf(out, "#\n");
25412548

2542-
print_pareto(out);
2549+
print_pareto(out, perf_session__env(session));
25432550
}
25442551

25452552
#ifdef HAVE_SLANG_SUPPORT
@@ -3097,7 +3104,7 @@ static int perf_c2c__report(int argc, const char **argv)
30973104
goto out_session;
30983105
}
30993106

3100-
err = c2c_hists__init(&c2c.hists, "dcacheline", 2);
3107+
err = c2c_hists__init(&c2c.hists, "dcacheline", 2, perf_session__env(session));
31013108
if (err) {
31023109
pr_debug("Failed to initialize hists\n");
31033110
goto out_session;
@@ -3181,13 +3188,13 @@ static int perf_c2c__report(int argc, const char **argv)
31813188
else if (c2c.display == DISPLAY_SNP_PEER)
31823189
sort_str = "tot_peer";
31833190

3184-
c2c_hists__reinit(&c2c.hists, output_str, sort_str);
3191+
c2c_hists__reinit(&c2c.hists, output_str, sort_str, perf_session__env(session));
31853192

31863193
ui_progress__init(&prog, c2c.hists.hists.nr_entries, "Sorting...");
31873194

31883195
hists__collapse_resort(&c2c.hists.hists, NULL);
31893196
hists__output_resort_cb(&c2c.hists.hists, &prog, resort_shared_cl_cb);
3190-
hists__iterate_cb(&c2c.hists.hists, resort_cl_cb);
3197+
hists__iterate_cb(&c2c.hists.hists, resort_cl_cb, perf_session__env(session));
31913198

31923199
ui_progress__finish();
31933200

tools/perf/builtin-diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2003,7 +2003,7 @@ int cmd_diff(int argc, const char **argv)
20032003
sort__mode = SORT_MODE__DIFF;
20042004
}
20052005

2006-
if (setup_sorting(NULL) < 0)
2006+
if (setup_sorting(/*evlist=*/NULL, perf_session__env(data__files[0].session)) < 0)
20072007
usage_with_options(diff_usage, options);
20082008

20092009
setup_pager();

tools/perf/builtin-report.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1790,7 +1790,7 @@ int cmd_report(int argc, const char **argv)
17901790
}
17911791

17921792
if ((last_key != K_SWITCH_INPUT_DATA && last_key != K_RELOAD) &&
1793-
(setup_sorting(session->evlist) < 0)) {
1793+
(setup_sorting(session->evlist, perf_session__env(session)) < 0)) {
17941794
if (sort_order)
17951795
parse_options_usage(report_usage, options, "s", 1);
17961796
if (field_order)

tools/perf/builtin-top.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1767,7 +1767,17 @@ int cmd_top(int argc, const char **argv)
17671767

17681768
setup_browser(false);
17691769

1770-
if (setup_sorting(top.evlist) < 0) {
1770+
top.session = __perf_session__new(/*data=*/NULL, /*tool=*/NULL,
1771+
/*trace_event_repipe=*/false,
1772+
&host_env);
1773+
if (IS_ERR(top.session)) {
1774+
status = PTR_ERR(top.session);
1775+
top.session = NULL;
1776+
goto out_delete_evlist;
1777+
}
1778+
top.evlist->session = top.session;
1779+
1780+
if (setup_sorting(top.evlist, perf_session__env(top.session)) < 0) {
17711781
if (sort_order)
17721782
parse_options_usage(top_usage, options, "s", 1);
17731783
if (field_order)
@@ -1842,16 +1852,6 @@ int cmd_top(int argc, const char **argv)
18421852
signal(SIGWINCH, winch_sig);
18431853
}
18441854

1845-
top.session = __perf_session__new(/*data=*/NULL, /*tool=*/NULL,
1846-
/*trace_event_repipe=*/false,
1847-
&host_env);
1848-
if (IS_ERR(top.session)) {
1849-
status = PTR_ERR(top.session);
1850-
top.session = NULL;
1851-
goto out_delete_evlist;
1852-
}
1853-
top.evlist->session = top.session;
1854-
18551855
if (!evlist__needs_bpf_sb_event(top.evlist))
18561856
top.record_opts.no_bpf_event = true;
18571857

tools/perf/tests/hists_cumulate.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ static int test1(struct evsel *evsel, struct machine *machine)
295295
symbol_conf.cumulate_callchain = false;
296296
evsel__reset_sample_bit(evsel, CALLCHAIN);
297297

298-
setup_sorting(NULL);
298+
setup_sorting(/*evlist=*/NULL, machine->env);
299299
callchain_register_param(&callchain_param);
300300

301301
err = add_hist_entries(hists, machine);
@@ -442,7 +442,7 @@ static int test2(struct evsel *evsel, struct machine *machine)
442442
symbol_conf.cumulate_callchain = false;
443443
evsel__set_sample_bit(evsel, CALLCHAIN);
444444

445-
setup_sorting(NULL);
445+
setup_sorting(/*evlist=*/NULL, machine->env);
446446
callchain_register_param(&callchain_param);
447447

448448
err = add_hist_entries(hists, machine);
@@ -500,7 +500,7 @@ static int test3(struct evsel *evsel, struct machine *machine)
500500
symbol_conf.cumulate_callchain = true;
501501
evsel__reset_sample_bit(evsel, CALLCHAIN);
502502

503-
setup_sorting(NULL);
503+
setup_sorting(/*evlist=*/NULL, machine->env);
504504
callchain_register_param(&callchain_param);
505505

506506
err = add_hist_entries(hists, machine);
@@ -684,7 +684,7 @@ static int test4(struct evsel *evsel, struct machine *machine)
684684
symbol_conf.cumulate_callchain = true;
685685
evsel__set_sample_bit(evsel, CALLCHAIN);
686686

687-
setup_sorting(NULL);
687+
setup_sorting(/*evlist=*/NULL, machine->env);
688688

689689
callchain_param = callchain_param_default;
690690
callchain_register_param(&callchain_param);

tools/perf/tests/hists_filter.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,6 @@ static int test__hists_filter(struct test_suite *test __maybe_unused, int subtes
131131
goto out;
132132
err = TEST_FAIL;
133133

134-
/* default sort order (comm,dso,sym) will be used */
135-
if (setup_sorting(NULL) < 0)
136-
goto out;
137-
138134
machines__init(&machines);
139135

140136
/* setup threads/dso/map/symbols also */
@@ -145,6 +141,10 @@ static int test__hists_filter(struct test_suite *test __maybe_unused, int subtes
145141
if (verbose > 1)
146142
machine__fprintf(machine, stderr);
147143

144+
/* default sort order (comm,dso,sym) will be used */
145+
if (setup_sorting(evlist, machine->env) < 0)
146+
goto out;
147+
148148
/* process sample events */
149149
err = add_hist_entries(evlist, machine);
150150
if (err < 0)

0 commit comments

Comments
 (0)