]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
rtla: Refactor save_trace_to_file
authorCosta Shulyupin <costa.shul@redhat.com>
Wed, 19 Feb 2025 11:51:10 +0000 (13:51 +0200)
committerSteven Rostedt (Google) <rostedt@goodmis.org>
Tue, 4 Mar 2025 19:17:19 +0000 (14:17 -0500)
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>
tools/tracing/rtla/src/osnoise_hist.c
tools/tracing/rtla/src/osnoise_top.c
tools/tracing/rtla/src/timerlat_hist.c
tools/tracing/rtla/src/timerlat_top.c
tools/tracing/rtla/src/trace.c

index b4930b835b0a1253e3e4fc6dde1143994aaccf22..7c6ef67ef3e6ca52eac84f8dfc641517b89baa19 100644 (file)
@@ -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:
index 4772677ac762ce9586c254523d4ed72770310263..0eeefbbbf317361126ed01fabff15de31f4303a5 100644 (file)
@@ -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:
index 202d99a598ba856e64595b8bcbbecbb363740633..93d0c9e450204b5dd172ba14b3da9625cd75db0d 100644 (file)
@@ -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:
index 1b6455b9e09397b5f30dc1a8be8d850c7b41e6a6..3894ac37d81ca43fa547ce7f0083cd9607a0f133 100644 (file)
@@ -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
index 728f5029d5335fd510c619d4c886b3aa04384080..74ed2f6208baa3ecd71ae549e9bb755d27c9ca0f 100644 (file)
@@ -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);