Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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.

Cc: Daniel Bristot de Oliveira <bristot@kernel.org>
Cc: John Kacur <jkacur@redhat.com>
Cc: "Luis Claudio R. Goncalves" <lgoncalv@redhat.com>
Cc: Eder Zulian <ezulian@redhat.com>
Cc: Dan Carpenter <dan.carpenter@linaro.org>
Cc: Gabriele Monaco <gmonaco@redhat.com>
Link: https://lore.kernel.org/20250219115138.406075-1-costa.shul@redhat.com
Signed-off-by: Costa Shulyupin <costa.shul@redhat.com>
Reviewed-by: Tomas Glozar <tglozar@redhat.com>
Tested-by: Tomas Glozar <tglozar@redhat.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>

authored by

Costa Shulyupin and committed by
Steven Rostedt (Google)
dc4d4e7c e82c78af

+8 -16
+1 -4
tools/tracing/rtla/src/osnoise_hist.c
··· 983 983 984 984 if (osnoise_trace_is_off(tool, record)) { 985 985 printf("rtla osnoise hit stop tracing\n"); 986 - if (params->trace_output) { 987 - printf(" Saving trace to %s\n", params->trace_output); 988 - save_trace_to_file(record->trace.inst, params->trace_output); 989 - } 986 + save_trace_to_file(record->trace.inst, params->trace_output); 990 987 } 991 988 992 989 out_hist:
+1 -4
tools/tracing/rtla/src/osnoise_top.c
··· 813 813 814 814 if (osnoise_trace_is_off(tool, record)) { 815 815 printf("osnoise hit stop tracing\n"); 816 - if (params->trace_output) { 817 - printf(" Saving trace to %s\n", params->trace_output); 818 - save_trace_to_file(record->trace.inst, params->trace_output); 819 - } 816 + save_trace_to_file(record->trace.inst, params->trace_output); 820 817 } 821 818 822 819 out_top:
+1 -4
tools/tracing/rtla/src/timerlat_hist.c
··· 1473 1473 if (!params->no_aa) 1474 1474 timerlat_auto_analysis(params->stop_us, params->stop_total_us); 1475 1475 1476 - if (params->trace_output) { 1477 - printf(" Saving trace to %s\n", params->trace_output); 1478 - save_trace_to_file(record->trace.inst, params->trace_output); 1479 - } 1476 + save_trace_to_file(record->trace.inst, params->trace_output); 1480 1477 } 1481 1478 1482 1479 out_hist:
+1 -4
tools/tracing/rtla/src/timerlat_top.c
··· 1295 1295 if (!params->no_aa) 1296 1296 timerlat_auto_analysis(params->stop_us, params->stop_total_us); 1297 1297 1298 - if (params->trace_output) { 1299 - printf(" Saving trace to %s\n", params->trace_output); 1300 - save_trace_to_file(record->trace.inst, params->trace_output); 1301 - } 1298 + save_trace_to_file(record->trace.inst, params->trace_output); 1302 1299 } else if (params->aa_only) { 1303 1300 /* 1304 1301 * If the trace did not stop with --aa-only, at least print the
+4
tools/tracing/rtla/src/trace.c
··· 75 75 int out_fd, in_fd; 76 76 int retval = -1; 77 77 78 + if (!filename) 79 + return 0; 80 + 78 81 in_fd = tracefs_instance_file_open(inst, file, O_RDONLY); 79 82 if (in_fd < 0) { 80 83 err_msg("Failed to open trace file\n"); 81 84 return -1; 82 85 } 83 86 87 + printf(" Saving trace to %s\n", filename); 84 88 out_fd = creat(filename, mode); 85 89 if (out_fd < 0) { 86 90 err_msg("Failed to create output file %s\n", filename);