diff mbox series

[1/3] trace-cmd show: Add --hist and --trigger options

Message ID 20240106042428.279706-2-rostedt@goodmis.org (mailing list archive)
State Accepted
Commit 3e930655bd95a548b701a7ec16e4eaf03f8fc249
Headers show
Series trace-cmd: Add sqlhist option and show hist and triggers | expand

Commit Message

Steven Rostedt Jan. 6, 2024, 4:22 a.m. UTC
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

Add the option --hist [<system>:]<event> to show the histogram output of a
given event, and --trigger [<system>:]<event> to show the content of the
trigger file.

Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 Documentation/trace-cmd/trace-cmd-show.1.txt |  6 +++
 tracecmd/trace-show.c                        | 51 ++++++++++++++++++++
 2 files changed, 57 insertions(+)
diff mbox series

Patch

diff --git a/Documentation/trace-cmd/trace-cmd-show.1.txt b/Documentation/trace-cmd/trace-cmd-show.1.txt
index f85c070b0598..6d397b842a21 100644
--- a/Documentation/trace-cmd/trace-cmd-show.1.txt
+++ b/Documentation/trace-cmd/trace-cmd-show.1.txt
@@ -88,6 +88,12 @@  OPTIONS
 *--graph_notrace*::
      Show the functions that will not be graphed.
 
+*--hist* '[system:]event'::
+     Show the content of a histogram "hist" file for a given event
+
+*--trigger* '[system:]event'::
+     Show the content of the "trigger" file for a given event
+
 *--cpumask*::
      Show the mask of CPUs that tracing will trace.
 
diff --git a/tracecmd/trace-show.c b/tracecmd/trace-show.c
index d91362e47c50..cf70d86ca61c 100644
--- a/tracecmd/trace-show.c
+++ b/tracecmd/trace-show.c
@@ -23,6 +23,8 @@  enum {
 	OPT_buffer_percent,
 	OPT_current_tracer,
 	OPT_tracing_on,
+	OPT_hist,
+	OPT_trigger,
 };
 
 void trace_show(int argc, char **argv)
@@ -31,6 +33,8 @@  void trace_show(int argc, char **argv)
 	const char *file = "trace";
 	const char *cpu = NULL;
 	struct buffer_instance *instance = &top_instance;
+	char *hist = NULL;
+	char *trigger = NULL;
 	char cpu_path[128];
 	char *path;
 	int snap = 0;
@@ -40,6 +44,8 @@  void trace_show(int argc, char **argv)
 	int stop = 0;
 	int c;
 	static struct option long_options[] = {
+		{"hist", required_argument, NULL, OPT_hist},
+		{"trigger", required_argument, NULL, OPT_trigger},
 		{"tracing_on", no_argument, NULL, OPT_tracing_on},
 		{"current_tracer", no_argument, NULL, OPT_current_tracer},
 		{"buffer_size", no_argument, NULL, OPT_buffer_size_kb},
@@ -90,6 +96,13 @@  void trace_show(int argc, char **argv)
 			if (snap)
 				die("Can not have -s and -p together");
 			break;
+		case OPT_hist:
+			hist = optarg;
+			break;
+		case OPT_trigger:
+			trigger = optarg;
+			break;
+
 		case OPT_tracing_on:
 			show_instance_file(instance, "tracing_on");
 			stop = 1;
@@ -149,6 +162,44 @@  void trace_show(int argc, char **argv)
 	else if (snap)
 		file = "snapshot";
 
+	if (hist || trigger) {
+		char **systems = NULL;
+		char *system = NULL;
+		char *event = hist ? hist : trigger;
+		char *file = hist ? "hist" : "trigger";
+		char *p;
+
+		if ((p = strstr(event, ":"))) {
+			system = event;
+			event = p + 1;
+			*p = '\0';
+		}
+
+		if (!system) {
+			systems = tracefs_event_systems(NULL);
+
+			for (int i = 0; systems && systems[i]; i++) {
+				system = systems[i];
+				if (tracefs_event_file_exists(instance->tracefs,
+							      system, event, file))
+					break;
+			}
+			if (!system)
+				die("Could not find system of event %s",
+				    event);
+		}
+
+		path = tracefs_event_file_read(instance->tracefs,
+					       system, event, file, NULL);
+		tracefs_list_free(systems);
+		if (!path)
+			die("Could not find hist for %s%s%s",
+			    system ? system : "", system ? ":":"", event);
+		printf("%s\n", path);
+		free(path);
+		exit(0);
+	}
+
 	if (cpu) {
 		char *endptr;
 		long val;