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 3/9] perf tracepoint: Sort events in iterator
Date: Mon, 14 Nov 2022 10:12:45 -0800 [thread overview]
Message-ID: <20221114181251.2683871-4-irogers@google.com> (raw)
In-Reply-To: <20221114181251.2683871-1-irogers@google.com>
In print_tracepoint_events use tracing_events__scandir_alphasort and
scandir alphasort so that the subsystem and events are sorted and
don't need a secondary qsort. Locally this results in the following
change:
...
ext4:ext4_zero_range [Tracepoint event]
- fib6:fib6_table_lookup [Tracepoint event]
fib:fib_table_lookup [Tracepoint event]
+ fib6:fib6_table_lookup [Tracepoint event]
filelock:break_lease_block [Tracepoint event]
...
ie fib6 now is after fib and not before it. This is more consistent
with how numbers are more generally sorted, such as:
...
syscalls:sys_enter_renameat [Tracepoint event]
syscalls:sys_enter_renameat2 [Tracepoint event]
...
and so an improvement over the qsort approach.
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/util/print-events.c | 108 +++++++++++----------------------
1 file changed, 37 insertions(+), 71 deletions(-)
diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c
index c4d5d87fae2f..fefc025bc259 100644
--- a/tools/perf/util/print-events.c
+++ b/tools/perf/util/print-events.c
@@ -66,26 +66,21 @@ static int cmp_string(const void *a, const void *b)
void print_tracepoint_events(const char *subsys_glob,
const char *event_glob, bool name_only)
{
- DIR *sys_dir, *evt_dir;
- struct dirent *sys_dirent, *evt_dirent;
- char evt_path[MAXPATHLEN];
- char *dir_path;
- char **evt_list = NULL;
- unsigned int evt_i = 0, evt_num = 0;
- bool evt_num_known = false;
-
-restart:
- sys_dir = tracing_events__opendir();
- if (!sys_dir)
- return;
-
- if (evt_num_known) {
- evt_list = zalloc(sizeof(char *) * evt_num);
- if (!evt_list)
- goto out_close_sys_dir;
- }
+ struct dirent **sys_namelist = NULL;
+ bool printed = false;
+ int sys_items = tracing_events__scandir_alphasort(&sys_namelist);
+
+ for (int i = 0; i < sys_items; i++) {
+ struct dirent *sys_dirent = sys_namelist[i];
+ struct dirent **evt_namelist = NULL;
+ char *dir_path;
+ int evt_items;
+
+ if (sys_dirent->d_type != DT_DIR ||
+ !strcmp(sys_dirent->d_name, ".") ||
+ !strcmp(sys_dirent->d_name, ".."))
+ continue;
- for_each_subsystem(sys_dir, sys_dirent) {
if (subsys_glob != NULL &&
!strglobmatch(sys_dirent->d_name, subsys_glob))
continue;
@@ -93,69 +88,40 @@ void print_tracepoint_events(const char *subsys_glob,
dir_path = get_events_file(sys_dirent->d_name);
if (!dir_path)
continue;
- evt_dir = opendir(dir_path);
- if (!evt_dir)
- goto next;
- for_each_event(dir_path, evt_dir, evt_dirent) {
- if (event_glob != NULL &&
- !strglobmatch(evt_dirent->d_name, event_glob))
+ evt_items = scandir(dir_path, &evt_namelist, NULL, alphasort);
+ for (int j = 0; j < evt_items; j++) {
+ struct dirent *evt_dirent = evt_namelist[j];
+ char evt_path[MAXPATHLEN];
+
+ if (evt_dirent->d_type != DT_DIR ||
+ !strcmp(evt_dirent->d_name, ".") ||
+ !strcmp(evt_dirent->d_name, ".."))
continue;
- if (!evt_num_known) {
- evt_num++;
+ if (tp_event_has_id(dir_path, evt_dirent) != 0)
+ continue;
+
+ if (event_glob != NULL &&
+ !strglobmatch(evt_dirent->d_name, event_glob))
continue;
- }
snprintf(evt_path, MAXPATHLEN, "%s:%s",
sys_dirent->d_name, evt_dirent->d_name);
-
- evt_list[evt_i] = strdup(evt_path);
- if (evt_list[evt_i] == NULL) {
- put_events_file(dir_path);
- goto out_close_evt_dir;
+ if (name_only)
+ printf("%s ", evt_path);
+ else {
+ printf(" %-50s [%s]\n", evt_path,
+ event_type_descriptors[PERF_TYPE_TRACEPOINT]);
}
- evt_i++;
+ printed = true;
}
- closedir(evt_dir);
-next:
- put_events_file(dir_path);
+ free(dir_path);
+ free(evt_namelist);
}
- closedir(sys_dir);
-
- 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) {
- if (name_only) {
- printf("%s ", evt_list[evt_i++]);
- continue;
- }
- printf(" %-50s [%s]\n", evt_list[evt_i++],
- event_type_descriptors[PERF_TYPE_TRACEPOINT]);
- }
- if (evt_num && pager_in_use())
+ free(sys_namelist);
+ if (printed && 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_close_evt_dir:
- closedir(evt_dir);
-out_close_sys_dir:
- closedir(sys_dir);
-
- printf("FATAL: not enough memory to print %s\n",
- event_type_descriptors[PERF_TYPE_TRACEPOINT]);
- if (evt_list)
- goto out_free;
}
void print_sdt_events(const char *subsys_glob, const char *event_glob,
--
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 ` Ian Rogers [this message]
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 ` [PATCH v2 6/9] perf list: Simplify symbol " Ian Rogers
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-4-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).