Skip to content

Commit 30f0b43

Browse files
captain5050acmel
authored andcommitted
perf pmu: Remove str from perf_pmu_alias
Currently the value is only used in perf list. Compute the value just when needed to avoid unnecessary overhead. Recycle the strbuf to avoid memory allocation overhead. Signed-off-by: Ian Rogers <irogers@google.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: James Clark <james.clark@arm.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lore.kernel.org/lkml/20230830070753.1821629-3-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 7a6e916 commit 30f0b43

File tree

1 file changed

+10
-23
lines changed

1 file changed

+10
-23
lines changed

tools/perf/util/pmu.c

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,6 @@ struct perf_pmu_alias {
5151
* json events.
5252
*/
5353
char *topic;
54-
/**
55-
* @str: Comma separated parameter list like
56-
* "event=0xcd,umask=0x1,ldlat=0x3".
57-
*/
58-
char *str;
5954
/** @terms: Owned list of the original parsed parameters. */
6055
struct list_head terms;
6156
/** @list: List element of struct perf_pmu aliases. */
@@ -408,7 +403,6 @@ static void perf_pmu_free_alias(struct perf_pmu_alias *newalias)
408403
zfree(&newalias->desc);
409404
zfree(&newalias->long_desc);
410405
zfree(&newalias->topic);
411-
zfree(&newalias->str);
412406
zfree(&newalias->pmu_name);
413407
parse_events_terms__purge(&newalias->terms);
414408
free(newalias);
@@ -489,7 +483,7 @@ static int update_alias(const struct pmu_event *pe,
489483
assign_str(pe->name, "long_desc", &data->alias->long_desc, pe->long_desc);
490484
assign_str(pe->name, "topic", &data->alias->topic, pe->topic);
491485
data->alias->per_pkg = pe->perpkg;
492-
if (assign_str(pe->name, "value", &data->alias->str, pe->event)) {
486+
if (pe->event) {
493487
parse_events_terms__purge(&data->alias->terms);
494488
ret = parse_events_terms(&data->alias->terms, pe->event, /*input=*/NULL);
495489
}
@@ -511,7 +505,6 @@ static int perf_pmu__new_alias(struct perf_pmu *pmu, const char *name,
511505
int ret;
512506
const char *long_desc = NULL, *topic = NULL, *unit = NULL, *pmu_name = NULL;
513507
bool deprecated = false, perpkg = false;
514-
struct strbuf sb;
515508

516509
if (perf_pmu__find_alias(pmu, name, /*load=*/ false)) {
517510
/* Alias was already created/loaded. */
@@ -531,7 +524,6 @@ static int perf_pmu__new_alias(struct perf_pmu *pmu, const char *name,
531524
if (!alias)
532525
return -ENOMEM;
533526

534-
alias->str = NULL;
535527
INIT_LIST_HEAD(&alias->terms);
536528
alias->scale = 1.0;
537529
alias->unit[0] = '\0';
@@ -574,17 +566,6 @@ static int perf_pmu__new_alias(struct perf_pmu *pmu, const char *name,
574566
}
575567
}
576568

577-
/* Scan event and remove leading zeroes, spaces, newlines, some
578-
* platforms have terms specified as
579-
* event=0x0091 (read from files ../<PMU>/events/<FILE>
580-
* and terms specified as event=0x91 (read from JSON files).
581-
*
582-
* Rebuild string to make alias->str member comparable.
583-
*/
584-
zfree(&alias->str);
585-
strbuf_init(&sb, /*hint=*/ 0);
586-
parse_events_term__to_strbuf(&alias->terms, &sb);
587-
alias->str = strbuf_detach(&sb, /*sz=*/ NULL);
588569
if (!pe)
589570
pmu->sysfs_aliases++;
590571
else
@@ -1682,7 +1663,9 @@ int perf_pmu__for_each_event(struct perf_pmu *pmu, bool skip_duplicate_pmus,
16821663
.pmu = pmu,
16831664
};
16841665
int ret = 0;
1666+
struct strbuf sb;
16851667

1668+
strbuf_init(&sb, /*hint=*/ 0);
16861669
pmu_add_cpu_aliases(pmu);
16871670
list_for_each_entry(event, &pmu->aliases, list) {
16881671
size_t buf_used;
@@ -1710,14 +1693,16 @@ int perf_pmu__for_each_event(struct perf_pmu *pmu, bool skip_duplicate_pmus,
17101693
info.desc = event->desc;
17111694
info.long_desc = event->long_desc;
17121695
info.encoding_desc = buf + buf_used;
1696+
parse_events_term__to_strbuf(&event->terms, &sb);
17131697
buf_used += snprintf(buf + buf_used, sizeof(buf) - buf_used,
1714-
"%s/%s/", info.pmu_name, event->str) + 1;
1698+
"%s/%s/", info.pmu_name, sb.buf) + 1;
17151699
info.topic = event->topic;
1716-
info.str = event->str;
1700+
info.str = sb.buf;
17171701
info.deprecated = event->deprecated;
17181702
ret = cb(state, &info);
17191703
if (ret)
1720-
return ret;
1704+
goto out;
1705+
strbuf_setlen(&sb, /*len=*/ 0);
17211706
}
17221707
if (pmu->selectable) {
17231708
info.name = buf;
@@ -1732,6 +1717,8 @@ int perf_pmu__for_each_event(struct perf_pmu *pmu, bool skip_duplicate_pmus,
17321717
info.deprecated = false;
17331718
ret = cb(state, &info);
17341719
}
1720+
out:
1721+
strbuf_release(&sb);
17351722
return ret;
17361723
}
17371724

0 commit comments

Comments
 (0)