All of lore.kernel.org
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: linux-trace-devel@vger.kernel.org
Cc: "Tzvetomir (VMware)  Stoyanov" <tz.stoyanov@gmail.com>
Subject: [PATCH 5/9] libtracefs: Extend tracefs_iterate_raw_events() to iterate per CPU
Date: Wed, 09 Dec 2020 21:29:11 -0500	[thread overview]
Message-ID: <20201210022943.538427964@goodmis.org> (raw)
In-Reply-To: 20201210022906.112066412@goodmis.org

From: "Tzvetomir (VMware) Stoyanov" <tz.stoyanov@gmail.com>

There are some use cases where only raw events from particular CPUs
should be iterated. An additional parameter is added to this API which
allows only trace buffers for specified CPUs to be iterated.

Link: https://lore.kernel.org/linux-trace-devel/20201204084739.555327-1-tz.stoyanov@gmail.com

Signed-off-by: Tzvetomir (VMware)  Stoyanov <tz.stoyanov@gmail.com>
[ Ported to work with trace-cmd ]
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 include/tracefs/tracefs.h    | 2 ++
 lib/tracefs/tracefs-events.c | 6 ++++++
 tracecmd/trace-record.c      | 2 +-
 3 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/include/tracefs/tracefs.h b/include/tracefs/tracefs.h
index 3358e33d9f11..ce8b09ca5bd0 100644
--- a/include/tracefs/tracefs.h
+++ b/include/tracefs/tracefs.h
@@ -6,6 +6,7 @@
 #ifndef _TRACE_FS_H
 #define _TRACE_FS_H
 
+#include <sched.h>
 #include "traceevent/event-parse.h"
 
 char *tracefs_get_tracing_file(const char *name);
@@ -44,6 +45,7 @@ char **tracefs_event_systems(const char *tracing_dir);
 char **tracefs_system_events(const char *tracing_dir, const char *system);
 int tracefs_iterate_raw_events(struct tep_handle *tep,
 				struct tracefs_instance *instance,
+				cpu_set_t *cpus, int cpu_size,
 				int (*callback)(struct tep_event *,
 						struct tep_record *,
 						int, void *),
diff --git a/lib/tracefs/tracefs-events.c b/lib/tracefs/tracefs-events.c
index a4e5215f8971..ba640a9e162c 100644
--- a/lib/tracefs/tracefs-events.c
+++ b/lib/tracefs/tracefs-events.c
@@ -116,6 +116,9 @@ get_events_in_page(struct tep_handle *tep, void *page,
  *				per CPU trace buffers
  * @tep: a handle to the trace event parser context
  * @instance: ftrace instance, can be NULL for the top instance
+ * @cpus: Iterate only through the buffers of CPUs, set in the mask.
+ *	  If NULL, iterate through all CPUs.
+ * @cpu_size: size of @cpus set
  * @callback: A user function, called for each record from the file
  * @callback_context: A custom context, passed to the user callback function
  *
@@ -126,6 +129,7 @@ get_events_in_page(struct tep_handle *tep, void *page,
  */
 int tracefs_iterate_raw_events(struct tep_handle *tep,
 				struct tracefs_instance *instance,
+				cpu_set_t *cpus, int cpu_size,
 				int (*callback)(struct tep_event *,
 						struct tep_record *,
 						int, void *),
@@ -166,6 +170,8 @@ int tracefs_iterate_raw_events(struct tep_handle *tep,
 		if (strlen(name) < 4 || strncmp(name, "cpu", 3) != 0)
 			continue;
 		cpu = atoi(name + 3);
+		if (cpus && !CPU_ISSET_S(cpu, cpu_size, cpus))
+			continue;
 		sprintf(file, "%s/%s", path, name);
 		ret = stat(file, &st);
 		if (ret < 0 || !S_ISDIR(st.st_mode))
diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c
index 3a63f1bdda97..f8baed7dcd47 100644
--- a/tracecmd/trace-record.c
+++ b/tracecmd/trace-record.c
@@ -4585,7 +4585,7 @@ static unsigned long long find_time_stamp(struct tep_handle *tep)
 {
 	unsigned long long ts = 0;
 
-	if (!tracefs_iterate_raw_events(tep, NULL, find_ts, &ts))
+	if (!tracefs_iterate_raw_events(tep, NULL, NULL, 0, find_ts, &ts))
 		return ts;
 
 	return 0;
-- 
2.29.2



  parent reply	other threads:[~2020-12-10  2:31 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-10  2:29 [PATCH 0/9] trace-cmd: Clean ups and fixes for installing libraries Steven Rostedt
2020-12-10  2:29 ` [PATCH 1/9] trace-cmd: Fix whitespace in usage message of trace-cmd report --ts-diff Steven Rostedt
2020-12-10  2:29 ` [PATCH 2/9] trace-cmd: Add reference to trace-cmd.org in README Steven Rostedt
2020-12-10  2:29 ` [PATCH 3/9] trace-cmd: Add --ts-check option to report Steven Rostedt
2020-12-10  2:29 ` [PATCH 4/9] trace-cmd: Update .gitignore Steven Rostedt
2020-12-10  2:29 ` Steven Rostedt [this message]
2020-12-10  2:29 ` [PATCH 6/9] libtracefs: Unit test for tracefs_iterate_raw_events() per CPU Steven Rostedt
2020-12-10  2:29 ` [PATCH 7/9] trace-cmd: Use system trace libraries, if available Steven Rostedt
2020-12-10  2:29 ` [PATCH 8/9] trace-cmd: Have "make test" use system libraries if present Steven Rostedt
2020-12-10  2:29 ` [PATCH 9/9] trace-cmd: Only install libtraceevent and libtracefs if not in system 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=20201210022943.538427964@goodmis.org \
    --to=rostedt@goodmis.org \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=tz.stoyanov@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.