All of lore.kernel.org
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: linux-trace-devel@vger.kernel.org
Cc: "Steven Rostedt (Google)" <rostedt@goodmis.org>
Subject: [PATCH 4/4] trace-cmd stat: Use tracefs_instance_file_read()
Date: Thu, 28 Dec 2023 22:16:47 -0500	[thread overview]
Message-ID: <20231229031907.69432-5-rostedt@goodmis.org> (raw)
In-Reply-To: <20231229031907.69432-1-rostedt@goodmis.org>

From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

Instead of open coding reading an instance file, use the libtracefs
library tracefs_instance_file_read().

Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 tracecmd/trace-stat.c | 45 ++++++++-----------------------------------
 1 file changed, 8 insertions(+), 37 deletions(-)

diff --git a/tracecmd/trace-stat.c b/tracecmd/trace-stat.c
index 391a05ffcec9..9a6e22254b48 100644
--- a/tracecmd/trace-stat.c
+++ b/tracecmd/trace-stat.c
@@ -24,19 +24,6 @@ static inline int is_top_instance(struct buffer_instance *instance)
 	return instance == &top_instance;
 }
 
-static int get_instance_file_fd(struct buffer_instance *instance,
-				const char *file)
-{
-	char *path;
-	int fd;
-
-	path = tracefs_instance_get_file(instance->tracefs, file);
-	fd = open(path, O_RDONLY);
-	tracefs_put_tracing_file(path);
-
-	return fd;
-}
-
 char *strstrip(char *str)
 {
 	char *s;
@@ -108,22 +95,6 @@ char *get_file_content(const char *file)
 	return str;
 }
 
-static char *get_instance_file_content(struct buffer_instance *instance,
-				       const char *file)
-{
-	char *str = NULL;
-	int fd;
-
-	fd = get_instance_file_fd(instance, file);
-	if (fd < 0)
-		return NULL;
-
-	str = get_fd_content(fd, file);
-
-	close(fd);
-	return str;
-}
-
 static void report_file(struct buffer_instance *instance,
 			char *name, char *def_value, char *description)
 {
@@ -132,7 +103,7 @@ static void report_file(struct buffer_instance *instance,
 
 	if (!tracefs_file_exists(instance->tracefs, name))
 		return;
-	str = get_instance_file_content(instance, name);
+	str = tracefs_instance_file_read(instance->tracefs, name, NULL);
 	if (!str)
 		return;
 	cont = strstrip(str);
@@ -346,7 +317,7 @@ static void report_events(struct buffer_instance *instance)
 	enum event_process processed = PROCESSED_NONE;
 	enum event_process processed_part = PROCESSED_NONE;
 
-	str = get_instance_file_content(instance, "events/enable");
+	str = tracefs_instance_file_read(instance->tracefs, "events/enable", NULL);
 	if (!str)
 		return;
 
@@ -664,7 +635,7 @@ static void report_buffers(struct buffer_instance *instance)
 	char file[FILE_SIZE];
 	int cpu;
 
-	str = get_instance_file_content(instance, "buffer_size_kb");
+	str = tracefs_instance_file_read(instance->tracefs, "buffer_size_kb", NULL);
 	if (!str)
 		return;
 
@@ -684,7 +655,7 @@ static void report_buffers(struct buffer_instance *instance)
 	for (cpu = 0; ; cpu++) {
 
 		snprintf(file, FILE_SIZE, "per_cpu/cpu%d/buffer_size_kb", cpu);
-		str = get_instance_file_content(instance, file);
+		str = tracefs_instance_file_read(instance->tracefs, file, NULL);
 		if (!str)
 			break;
 
@@ -699,7 +670,7 @@ static void report_buffers(struct buffer_instance *instance)
  total:
 	free(str);
 
-	str = get_instance_file_content(instance, "buffer_total_size_kb");
+	str = tracefs_instance_file_read(instance->tracefs, "buffer_total_size_kb", NULL);
 	if (!str)
 		return;
 
@@ -733,7 +704,7 @@ static void report_cpumask(struct buffer_instance *instance)
 	int n;
 	int i;
 
-	str = get_instance_file_content(instance, "tracing_cpumask");
+	str = tracefs_instance_file_read(instance->tracefs, "tracing_cpumask", NULL);
 	if (!str)
 		return;
 
@@ -783,7 +754,7 @@ static void report_probes(struct buffer_instance *instance,
 	int newline;
 	int i;
 
-	str = get_instance_file_content(instance, file);
+	str = tracefs_instance_file_read(instance->tracefs, file, NULL);
 	if (!str)
 		return;
 
@@ -828,7 +799,7 @@ static void report_traceon(struct buffer_instance *instance)
 	char *str;
 	char *cont;
 
-	str = get_instance_file_content(instance, "tracing_on");
+	str = tracefs_instance_file_read(instance->tracefs, "tracing_on", NULL);
 	if (!str)
 		return;
 
-- 
2.42.0


      parent reply	other threads:[~2023-12-29  3:18 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-29  3:16 [PATCH 0/4] trace-cmd: Add ways to read more tracefs files Steven Rostedt
2023-12-29  3:16 ` [PATCH 1/4] trace-cmd show: Re-arrange the enum long option values Steven Rostedt
2023-12-29  3:16 ` [PATCH 2/4] trace-cmd show: Add --buffer-subbuf-size option Steven Rostedt
2023-12-29  3:16 ` [PATCH 3/4] trace-cmd show: Add option to read buffer_percent Steven Rostedt
2023-12-29  3:16 ` Steven Rostedt [this message]

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=20231229031907.69432-5-rostedt@goodmis.org \
    --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 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.