From: Ian Rogers <irogers@google.com>
To: Weilin Wang <weilin.wang@intel.com>,
Perry Taylor <perry.taylor@intel.com>,
Caleb Biggers <caleb.biggers@intel.com>,
Leo Yan <leo.yan@linaro.org>,
Adrian Hunter <adrian.hunter@intel.com>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>, Namhyung Kim <namhyung@kernel.org>,
Sandipan Das <sandipan.das@amd.com>,
Kajol Jain <kjain@linux.ibm.com>,
Zhengjun Xing <zhengjun.xing@linux.intel.com>,
Kan Liang <kan.liang@linux.intel.com>,
Ravi Bangoria <ravi.bangoria@amd.com>,
Xin Gao <gaoxin@cdjrlc.com>, Rob Herring <robh@kernel.org>,
linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org
Cc: Stephane Eranian <eranian@google.com>, Ian Rogers <irogers@google.com>
Subject: [PATCH v2 6/9] perf list: Simplify symbol event printing
Date: Mon, 14 Nov 2022 10:12:48 -0800 [thread overview]
Message-ID: <20221114181251.2683871-7-irogers@google.com> (raw)
In-Reply-To: <20221114181251.2683871-1-irogers@google.com>
The current code computes an array of symbol names then sorts and
prints them. Use a strlist to create a list of names that is
sorted and then print it.
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/util/print-events.c | 79 +++++++++-------------------------
1 file changed, 21 insertions(+), 58 deletions(-)
diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c
index ff7793944246..d53dba033597 100644
--- a/tools/perf/util/print-events.c
+++ b/tools/perf/util/print-events.c
@@ -52,14 +52,6 @@ static const struct event_symbol event_symbols_tool[PERF_TOOL_MAX] = {
},
};
-static int cmp_string(const void *a, const void *b)
-{
- const char * const *as = a;
- const char * const *bs = b;
-
- return strcmp(*as, *bs);
-}
-
/*
* Print the events from <debugfs_mount_point>/tracing/events
*/
@@ -298,77 +290,48 @@ void print_symbol_events(const char *event_glob, unsigned int type,
struct event_symbol *syms, unsigned int max,
bool name_only)
{
- unsigned int i, evt_i = 0, evt_num = 0;
- char name[MAX_NAME_LEN];
- char **evt_list = NULL;
- bool evt_num_known = false;
-
-restart:
- if (evt_num_known) {
- evt_list = zalloc(sizeof(char *) * evt_num);
- if (!evt_list)
- goto out_enomem;
- syms -= max;
- }
+ struct strlist *evt_name_list = strlist__new(NULL, NULL);
+ struct str_node *nd;
- for (i = 0; i < max; i++, syms++) {
+ if (!evt_name_list) {
+ pr_debug("Failed to allocate new strlist for symbol events\n");
+ return;
+ }
+ for (unsigned int i = 0; i < max; i++) {
/*
* New attr.config still not supported here, the latest
* example was PERF_COUNT_SW_CGROUP_SWITCHES
*/
- if (syms->symbol == NULL)
+ if (syms[i].symbol == NULL)
continue;
- if (event_glob != NULL && !(strglobmatch(syms->symbol, event_glob) ||
- (syms->alias && strglobmatch(syms->alias, event_glob))))
+ if (event_glob != NULL && !(strglobmatch(syms[i].symbol, event_glob) ||
+ (syms[i].alias && strglobmatch(syms[i].alias, event_glob))))
continue;
if (!is_event_supported(type, i))
continue;
- if (!evt_num_known) {
- evt_num++;
- continue;
- }
-
- if (!name_only && strlen(syms->alias))
- snprintf(name, MAX_NAME_LEN, "%s OR %s", syms->symbol, syms->alias);
- else
- strlcpy(name, syms->symbol, MAX_NAME_LEN);
+ if (strlen(syms[i].alias)) {
+ char name[MAX_NAME_LEN];
- evt_list[evt_i] = strdup(name);
- if (evt_list[evt_i] == NULL)
- goto out_enomem;
- evt_i++;
+ snprintf(name, MAX_NAME_LEN, "%s OR %s", syms[i].symbol, syms[i].alias);
+ strlist__add(evt_name_list, name);
+ } else
+ strlist__add(evt_name_list, syms[i].symbol);
}
- if (!evt_num_known) {
- evt_num_known = true;
- goto restart;
- }
- qsort(evt_list, evt_num, sizeof(char *), cmp_string);
- evt_i = 0;
- while (evt_i < evt_num) {
+ strlist__for_each_entry(nd, evt_name_list) {
if (name_only) {
- printf("%s ", evt_list[evt_i++]);
+ printf("%s ", nd->s);
continue;
}
- printf(" %-50s [%s]\n", evt_list[evt_i++], event_type_descriptors[type]);
+ printf(" %-50s [%s]\n", nd->s, event_type_descriptors[type]);
}
- if (evt_num && pager_in_use())
+ if (!strlist__empty(evt_name_list) && pager_in_use())
printf("\n");
-out_free:
- evt_num = evt_i;
- for (evt_i = 0; evt_i < evt_num; evt_i++)
- zfree(&evt_list[evt_i]);
- zfree(&evt_list);
- return;
-
-out_enomem:
- printf("FATAL: not enough memory to print %s\n", event_type_descriptors[type]);
- if (evt_list)
- goto out_free;
+ strlist__delete(evt_name_list);
}
/*
--
2.38.1.431.g37b22c650d-goog
next prev parent reply other threads:[~2022-11-14 18:14 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-14 18:12 [PATCH v2 0/9] Restructure perf list and add json output Ian Rogers
2022-11-14 18:12 ` [PATCH v2 1/9] perf pmu: Add documentation Ian Rogers
2022-11-14 18:12 ` [PATCH v2 2/9] tools lib api fs tracing_path: Add scandir alphasort Ian Rogers
2022-11-14 18:12 ` [PATCH v2 3/9] perf tracepoint: Sort events in iterator Ian Rogers
2022-11-14 18:12 ` [PATCH v2 4/9] perf list: Generalize limiting to a PMU name Ian Rogers
2022-11-14 18:12 ` [PATCH v2 5/9] perf list: Simplify cache event printing Ian Rogers
2022-11-14 18:12 ` Ian Rogers [this message]
2022-11-14 18:12 ` [PATCH v2 7/9] perf pmu: Restructure print_pmu_events Ian Rogers
2022-11-14 18:12 ` [PATCH v2 8/9] perf list: Reorganize to use callbacks Ian Rogers
2022-11-14 18:12 ` [PATCH v2 9/9] perf list: Add json output option Ian Rogers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221114181251.2683871-7-irogers@google.com \
--to=irogers@google.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=caleb.biggers@intel.com \
--cc=eranian@google.com \
--cc=gaoxin@cdjrlc.com \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=kjain@linux.ibm.com \
--cc=leo.yan@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=perry.taylor@intel.com \
--cc=peterz@infradead.org \
--cc=ravi.bangoria@amd.com \
--cc=robh@kernel.org \
--cc=sandipan.das@amd.com \
--cc=weilin.wang@intel.com \
--cc=zhengjun.xing@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).