[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250306181826.923371010@goodmis.org>
Date: Thu, 06 Mar 2025 13:18:11 -0500
From: Steven Rostedt <rostedt@...dmis.org>
To: linux-kernel@...r.kernel.org
Cc: Tomas Glozar <tglozar@...hat.com>,
John Kacur <jkacur@...hat.com>,
Daniel Bristot de Oliveira <bristot@...nel.org>,
"Luis Claudio R. Goncalves" <lgoncalv@...hat.com>,
Eder Zulian <ezulian@...hat.com>,
Dan Carpenter <dan.carpenter@...aro.org>,
Gabriele Monaco <gmonaco@...hat.com>,
Costa Shulyupin <costa.shul@...hat.com>
Subject: [for-next][PATCH 10/10] rtla: Refactor save_trace_to_file
From: Costa Shulyupin <costa.shul@...hat.com>
The functions osnoise_hist_main(), osnoise_top_main(),
timerlat_hist_main(), and timerlat_top_main() are lengthy and contain
duplicated code.
Refactor by consolidating the duplicate lines into the
save_trace_to_file() function.
Cc: Daniel Bristot de Oliveira <bristot@...nel.org>
Cc: John Kacur <jkacur@...hat.com>
Cc: "Luis Claudio R. Goncalves" <lgoncalv@...hat.com>
Cc: Eder Zulian <ezulian@...hat.com>
Cc: Dan Carpenter <dan.carpenter@...aro.org>
Cc: Gabriele Monaco <gmonaco@...hat.com>
Link: https://lore.kernel.org/20250219115138.406075-1-costa.shul@redhat.com
Signed-off-by: Costa Shulyupin <costa.shul@...hat.com>
Reviewed-by: Tomas Glozar <tglozar@...hat.com>
Tested-by: Tomas Glozar <tglozar@...hat.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@...dmis.org>
---
tools/tracing/rtla/src/osnoise_hist.c | 5 +----
tools/tracing/rtla/src/osnoise_top.c | 5 +----
tools/tracing/rtla/src/timerlat_hist.c | 5 +----
tools/tracing/rtla/src/timerlat_top.c | 5 +----
tools/tracing/rtla/src/trace.c | 4 ++++
5 files changed, 8 insertions(+), 16 deletions(-)
diff --git a/tools/tracing/rtla/src/osnoise_hist.c b/tools/tracing/rtla/src/osnoise_hist.c
index b4930b835b0a..7c6ef67ef3e6 100644
--- a/tools/tracing/rtla/src/osnoise_hist.c
+++ b/tools/tracing/rtla/src/osnoise_hist.c
@@ -983,10 +983,7 @@ int osnoise_hist_main(int argc, char *argv[])
if (osnoise_trace_is_off(tool, record)) {
printf("rtla osnoise hit stop tracing\n");
- if (params->trace_output) {
- printf(" Saving trace to %s\n", params->trace_output);
- save_trace_to_file(record->trace.inst, params->trace_output);
- }
+ save_trace_to_file(record->trace.inst, params->trace_output);
}
out_hist:
diff --git a/tools/tracing/rtla/src/osnoise_top.c b/tools/tracing/rtla/src/osnoise_top.c
index 4772677ac762..0eeefbbbf317 100644
--- a/tools/tracing/rtla/src/osnoise_top.c
+++ b/tools/tracing/rtla/src/osnoise_top.c
@@ -813,10 +813,7 @@ int osnoise_top_main(int argc, char **argv)
if (osnoise_trace_is_off(tool, record)) {
printf("osnoise hit stop tracing\n");
- if (params->trace_output) {
- printf(" Saving trace to %s\n", params->trace_output);
- save_trace_to_file(record->trace.inst, params->trace_output);
- }
+ save_trace_to_file(record->trace.inst, params->trace_output);
}
out_top:
diff --git a/tools/tracing/rtla/src/timerlat_hist.c b/tools/tracing/rtla/src/timerlat_hist.c
index 202d99a598ba..93d0c9e45020 100644
--- a/tools/tracing/rtla/src/timerlat_hist.c
+++ b/tools/tracing/rtla/src/timerlat_hist.c
@@ -1473,10 +1473,7 @@ int timerlat_hist_main(int argc, char *argv[])
if (!params->no_aa)
timerlat_auto_analysis(params->stop_us, params->stop_total_us);
- if (params->trace_output) {
- printf(" Saving trace to %s\n", params->trace_output);
- save_trace_to_file(record->trace.inst, params->trace_output);
- }
+ save_trace_to_file(record->trace.inst, params->trace_output);
}
out_hist:
diff --git a/tools/tracing/rtla/src/timerlat_top.c b/tools/tracing/rtla/src/timerlat_top.c
index 1b6455b9e093..3894ac37d81c 100644
--- a/tools/tracing/rtla/src/timerlat_top.c
+++ b/tools/tracing/rtla/src/timerlat_top.c
@@ -1295,10 +1295,7 @@ int timerlat_top_main(int argc, char *argv[])
if (!params->no_aa)
timerlat_auto_analysis(params->stop_us, params->stop_total_us);
- if (params->trace_output) {
- printf(" Saving trace to %s\n", params->trace_output);
- save_trace_to_file(record->trace.inst, params->trace_output);
- }
+ save_trace_to_file(record->trace.inst, params->trace_output);
} else if (params->aa_only) {
/*
* If the trace did not stop with --aa-only, at least print the
diff --git a/tools/tracing/rtla/src/trace.c b/tools/tracing/rtla/src/trace.c
index 728f5029d533..74ed2f6208ba 100644
--- a/tools/tracing/rtla/src/trace.c
+++ b/tools/tracing/rtla/src/trace.c
@@ -75,12 +75,16 @@ int save_trace_to_file(struct tracefs_instance *inst, const char *filename)
int out_fd, in_fd;
int retval = -1;
+ if (!filename)
+ return 0;
+
in_fd = tracefs_instance_file_open(inst, file, O_RDONLY);
if (in_fd < 0) {
err_msg("Failed to open trace file\n");
return -1;
}
+ printf(" Saving trace to %s\n", filename);
out_fd = creat(filename, mode);
if (out_fd < 0) {
err_msg("Failed to create output file %s\n", filename);
--
2.47.2
Powered by blists - more mailing lists