From: Steven Rostedt <rostedt@goodmis.org>
To: Linux Trace Devel <linux-trace-devel@vger.kernel.org>
Subject: [PATCH] libtracecmd: Optimize what cpus to check in tracecmd_iterate_events()
Date: Tue, 28 May 2024 14:52:19 -0400 [thread overview]
Message-ID: <20240528145219.7cef53b0@rorschach.local.home> (raw)
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>
Currently, tracecmd_iterate_events() will look at all possible CPUs to
find the next event to print, even if the CPUs to look at are filtered.
Instead, create a list of all the CPUs to look at and iterate that, such
that only the CPUs that are needed are looked at instead of all of them,
including those that are filtered out.
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
lib/trace-cmd/trace-input.c | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c
index ce4ecf43..2d12ac33 100644
--- a/lib/trace-cmd/trace-input.c
+++ b/lib/trace-cmd/trace-input.c
@@ -2813,9 +2813,12 @@ int tracecmd_iterate_events(struct tracecmd_input *handle,
struct tep_record *record;
unsigned long long *timestamps;
unsigned long long ts, last_timestamp = 0;
+ int *cpu_list;
+ int cpu_count = 0;
int next_cpu;
int cpu;
int ret = 0;
+ int i;
if (!callback && !handle->nr_followers) {
errno = EINVAL;
@@ -2826,17 +2829,28 @@ int tracecmd_iterate_events(struct tracecmd_input *handle,
if (!timestamps)
return -1;
+ cpu_list = calloc(handle->cpus, sizeof(*cpu_list));
+ if (!cpu_list) {
+ free(timestamps);
+ return -1;
+ }
+
for (cpu = 0; cpu < handle->cpus; cpu++) {
if (cpus && !CPU_ISSET_S(cpu, cpu_size, cpus))
continue;
+ cpu_list[cpu_count++] = cpu;
+ }
+ for (i = 0; i < cpu_count; i++) {
+ cpu = cpu_list[i];
record = tracecmd_peek_data(handle, cpu);
timestamps[cpu] = record ? record->ts : -1ULL;
}
do {
next_cpu = -1;
- for (cpu = 0; cpu < handle->cpus; cpu++) {
+ for (i = 0; i < cpu_count; i++) {
+ cpu = cpu_list[i];
ts = timestamps[cpu];
if (ts == -1ULL)
continue;
@@ -2869,6 +2883,7 @@ int tracecmd_iterate_events(struct tracecmd_input *handle,
} while (next_cpu >= 0 && ret == 0);
free(timestamps);
+ free(cpu_list);
return ret;
}
--
2.43.0
next reply other threads:[~2024-05-28 18:52 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-28 18:52 Steven Rostedt [this message]
-- strict thread matches above, loose matches on Subject: below --
2024-05-28 16:09 [PATCH] libtracecmd: Optimize what cpus to check in tracecmd_iterate_events() Steven Rostedt
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=20240528145219.7cef53b0@rorschach.local.home \
--to=rostedt@goodmis.org \
--cc=linux-trace-devel@vger.kernel.org \
/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).