rtla: Refactor save_trace_to_file
Subsystems (2)
PATCH 1/1 rtla: Refactor save_trace_to_file
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.
--- 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(-)
tools/tracing/rtla/src/osnoise_hist.c +1 -4
@@ -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:
tools/tracing/rtla/src/osnoise_top.c +1 -4
@@ -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:
tools/tracing/rtla/src/timerlat_hist.c +1 -4
@@ -1390,10 +1390,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:
tools/tracing/rtla/src/timerlat_top.c +1 -4
@@ -1159,10 +1159,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
tools/tracing/rtla/src/trace.c +4 -0
@@ -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);
Signature · 1 line
2.48.1
st 19. 2. 2025 v 12:52 odesílatel Costa Shulyupin
<[email protected]> napsal:
Quoted 5 lines
The functions
osnoise_hist_main(),osnoise_top_main(),timerlat_hist_main(), andtimerlat_top_main()are lengthy and contain duplicated code.
There is definitely a bunch of code that needs to be unified in rtla. My idea is to eventually merge top and hist, see my note to the cover letter to the BPF patchset [1].
[1] https://lore.kernel.org/linux-trace-kernel/[email protected]/
Quoted 4 lines
Refactor by consolidating the duplicate lines into the
save_trace_to_file()function.Signed-off-by Costa Shulyupin <[email protected]>
Thank you for the cleanup patch.
Quoted 96 lines
--- 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(-)tools/tracing/rtla/src/osnoise_hist.c +1
-4@@ -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:tools/tracing/rtla/src/osnoise_top.c +1
-4@@ -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:tools/tracing/rtla/src/timerlat_hist.c +1
-4@@ -1390,10 +1390,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:tools/tracing/rtla/src/timerlat_top.c +1
-4@@ -1159,10 +1159,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 tools/tracing/rtla/src/trace.c +4
-1@@ -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.48.1