diff options
author | Ian Rogers <irogers@google.com> | 2023-08-30 00:07:53 -0700 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2023-08-30 23:03:03 -0300 |
commit | 30f0b435bbf2b83cf822dbe40d23b41bdcae7156 (patch) | |
tree | 91ac890ec60e16d726d24a9f34f4e83cdde8239c /tools | |
parent | 7a6e91644708d514082a00fce3cd509960935fb8 (diff) | |
download | lwn-30f0b435bbf2b83cf822dbe40d23b41bdcae7156.tar.gz lwn-30f0b435bbf2b83cf822dbe40d23b41bdcae7156.zip |
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>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/perf/util/pmu.c | 33 |
1 files changed, 10 insertions, 23 deletions
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 8dbb7008877e..152cda84f273 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -51,11 +51,6 @@ struct perf_pmu_alias { * json events. */ char *topic; - /** - * @str: Comma separated parameter list like - * "event=0xcd,umask=0x1,ldlat=0x3". - */ - char *str; /** @terms: Owned list of the original parsed parameters. */ struct list_head terms; /** @list: List element of struct perf_pmu aliases. */ @@ -408,7 +403,6 @@ static void perf_pmu_free_alias(struct perf_pmu_alias *newalias) zfree(&newalias->desc); zfree(&newalias->long_desc); zfree(&newalias->topic); - zfree(&newalias->str); zfree(&newalias->pmu_name); parse_events_terms__purge(&newalias->terms); free(newalias); @@ -489,7 +483,7 @@ static int update_alias(const struct pmu_event *pe, assign_str(pe->name, "long_desc", &data->alias->long_desc, pe->long_desc); assign_str(pe->name, "topic", &data->alias->topic, pe->topic); data->alias->per_pkg = pe->perpkg; - if (assign_str(pe->name, "value", &data->alias->str, pe->event)) { + if (pe->event) { parse_events_terms__purge(&data->alias->terms); ret = parse_events_terms(&data->alias->terms, pe->event, /*input=*/NULL); } @@ -511,7 +505,6 @@ static int perf_pmu__new_alias(struct perf_pmu *pmu, const char *name, int ret; const char *long_desc = NULL, *topic = NULL, *unit = NULL, *pmu_name = NULL; bool deprecated = false, perpkg = false; - struct strbuf sb; if (perf_pmu__find_alias(pmu, name, /*load=*/ false)) { /* Alias was already created/loaded. */ @@ -531,7 +524,6 @@ static int perf_pmu__new_alias(struct perf_pmu *pmu, const char *name, if (!alias) return -ENOMEM; - alias->str = NULL; INIT_LIST_HEAD(&alias->terms); alias->scale = 1.0; alias->unit[0] = '\0'; @@ -574,17 +566,6 @@ static int perf_pmu__new_alias(struct perf_pmu *pmu, const char *name, } } - /* Scan event and remove leading zeroes, spaces, newlines, some - * platforms have terms specified as - * event=0x0091 (read from files ../<PMU>/events/<FILE> - * and terms specified as event=0x91 (read from JSON files). - * - * Rebuild string to make alias->str member comparable. - */ - zfree(&alias->str); - strbuf_init(&sb, /*hint=*/ 0); - parse_events_term__to_strbuf(&alias->terms, &sb); - alias->str = strbuf_detach(&sb, /*sz=*/ NULL); if (!pe) pmu->sysfs_aliases++; else @@ -1682,7 +1663,9 @@ int perf_pmu__for_each_event(struct perf_pmu *pmu, bool skip_duplicate_pmus, .pmu = pmu, }; int ret = 0; + struct strbuf sb; + strbuf_init(&sb, /*hint=*/ 0); pmu_add_cpu_aliases(pmu); list_for_each_entry(event, &pmu->aliases, list) { size_t buf_used; @@ -1710,14 +1693,16 @@ int perf_pmu__for_each_event(struct perf_pmu *pmu, bool skip_duplicate_pmus, info.desc = event->desc; info.long_desc = event->long_desc; info.encoding_desc = buf + buf_used; + parse_events_term__to_strbuf(&event->terms, &sb); buf_used += snprintf(buf + buf_used, sizeof(buf) - buf_used, - "%s/%s/", info.pmu_name, event->str) + 1; + "%s/%s/", info.pmu_name, sb.buf) + 1; info.topic = event->topic; - info.str = event->str; + info.str = sb.buf; info.deprecated = event->deprecated; ret = cb(state, &info); if (ret) - return ret; + goto out; + strbuf_setlen(&sb, /*len=*/ 0); } if (pmu->selectable) { info.name = buf; @@ -1732,6 +1717,8 @@ int perf_pmu__for_each_event(struct perf_pmu *pmu, bool skip_duplicate_pmus, info.deprecated = false; ret = cb(state, &info); } +out: + strbuf_release(&sb); return ret; } |