Skip to content

Commit 63ce844

Browse files
committed
perf stat: Only auto-merge events that are PMU aliases
Peter reported that when he explicitely asked for multiple events with the same name on the command line it got coalesced into just one line, i.e.: # perf stat -e cycles -e cycles -e cycles usleep 1 Performance counter stats for 'usleep 1': 3,269,652 cycles 0.000884123 seconds time elapsed # And while there is the --no-merges option to disable that auto-merging, this is a blunt change in behaviour for such explicit request, so change the code so that this auto merging is done only when handling the multi PMU aliases with the same name that introduced this coalescing, restoring the previous behaviour for the explicit case: # perf stat -e cycles -e cycles -e cycles usleep 1 Performance counter stats for 'usleep 1': 1,472,837 cycles 1,472,837 cycles 1,472,837 cycles 0.001764870 seconds time elapsed # Reported-by: Peter Zijlstra <[email protected]> Acked-by: Andi Kleen <[email protected]> Acked-by: Jiri Olsa <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Wang Nan <[email protected]> Fixes: 430daf2 ("perf stat: Collapse identically named events") Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent fc33dcc commit 63ce844

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

tools/perf/builtin-stat.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1257,7 +1257,7 @@ static bool collect_data(struct perf_evsel *counter,
12571257
if (counter->merged_stat)
12581258
return false;
12591259
cb(counter, data, true);
1260-
if (!no_merge)
1260+
if (!no_merge && counter->auto_merge_stats)
12611261
collect_all_aliases(counter, cb, data);
12621262
return true;
12631263
}

tools/perf/util/evsel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ struct perf_evsel {
131131
bool cmdline_group_boundary;
132132
struct list_head config_terms;
133133
int bpf_fd;
134+
bool auto_merge_stats;
134135
bool merged_stat;
135136
const char * metric_expr;
136137
const char * metric_name;

tools/perf/util/parse-events.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ static struct perf_evsel *
310310
__add_event(struct list_head *list, int *idx,
311311
struct perf_event_attr *attr,
312312
char *name, struct cpu_map *cpus,
313-
struct list_head *config_terms)
313+
struct list_head *config_terms, bool auto_merge_stats)
314314
{
315315
struct perf_evsel *evsel;
316316

@@ -324,6 +324,7 @@ __add_event(struct list_head *list, int *idx,
324324
evsel->cpus = cpu_map__get(cpus);
325325
evsel->own_cpus = cpu_map__get(cpus);
326326
evsel->system_wide = !!cpus;
327+
evsel->auto_merge_stats = auto_merge_stats;
327328

328329
if (name)
329330
evsel->name = strdup(name);
@@ -339,7 +340,7 @@ static int add_event(struct list_head *list, int *idx,
339340
struct perf_event_attr *attr, char *name,
340341
struct list_head *config_terms)
341342
{
342-
return __add_event(list, idx, attr, name, NULL, config_terms) ? 0 : -ENOMEM;
343+
return __add_event(list, idx, attr, name, NULL, config_terms, false) ? 0 : -ENOMEM;
343344
}
344345

345346
static int parse_aliases(char *str, const char *names[][PERF_EVSEL__MAX_ALIASES], int size)
@@ -1209,9 +1210,9 @@ int parse_events_add_numeric(struct parse_events_state *parse_state,
12091210
get_config_name(head_config), &config_terms);
12101211
}
12111212

1212-
int parse_events_add_pmu(struct parse_events_state *parse_state,
1213+
static int __parse_events_add_pmu(struct parse_events_state *parse_state,
12131214
struct list_head *list, char *name,
1214-
struct list_head *head_config)
1215+
struct list_head *head_config, bool auto_merge_stats)
12151216
{
12161217
struct perf_event_attr attr;
12171218
struct perf_pmu_info info;
@@ -1232,7 +1233,7 @@ int parse_events_add_pmu(struct parse_events_state *parse_state,
12321233

12331234
if (!head_config) {
12341235
attr.type = pmu->type;
1235-
evsel = __add_event(list, &parse_state->idx, &attr, NULL, pmu->cpus, NULL);
1236+
evsel = __add_event(list, &parse_state->idx, &attr, NULL, pmu->cpus, NULL, auto_merge_stats);
12361237
return evsel ? 0 : -ENOMEM;
12371238
}
12381239

@@ -1254,7 +1255,7 @@ int parse_events_add_pmu(struct parse_events_state *parse_state,
12541255

12551256
evsel = __add_event(list, &parse_state->idx, &attr,
12561257
get_config_name(head_config), pmu->cpus,
1257-
&config_terms);
1258+
&config_terms, auto_merge_stats);
12581259
if (evsel) {
12591260
evsel->unit = info.unit;
12601261
evsel->scale = info.scale;
@@ -1267,6 +1268,13 @@ int parse_events_add_pmu(struct parse_events_state *parse_state,
12671268
return evsel ? 0 : -ENOMEM;
12681269
}
12691270

1271+
int parse_events_add_pmu(struct parse_events_state *parse_state,
1272+
struct list_head *list, char *name,
1273+
struct list_head *head_config)
1274+
{
1275+
return __parse_events_add_pmu(parse_state, list, name, head_config, false);
1276+
}
1277+
12701278
int parse_events_multi_pmu_add(struct parse_events_state *parse_state,
12711279
char *str, struct list_head **listp)
12721280
{
@@ -1296,8 +1304,8 @@ int parse_events_multi_pmu_add(struct parse_events_state *parse_state,
12961304
return -1;
12971305
list_add_tail(&term->list, head);
12981306

1299-
if (!parse_events_add_pmu(parse_state, list,
1300-
pmu->name, head)) {
1307+
if (!__parse_events_add_pmu(parse_state, list,
1308+
pmu->name, head, true)) {
13011309
pr_debug("%s -> %s/%s/\n", str,
13021310
pmu->name, alias->str);
13031311
ok++;

0 commit comments

Comments
 (0)