Skip to content

Commit dc4d4e7

Browse files
makelinuxrostedt
authored andcommitted
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 <[email protected]> Cc: John Kacur <[email protected]> Cc: "Luis Claudio R. Goncalves" <[email protected]> Cc: Eder Zulian <[email protected]> Cc: Dan Carpenter <[email protected]> Cc: Gabriele Monaco <[email protected]> Link: https://lore.kernel.org/[email protected] Signed-off-by: Costa Shulyupin <[email protected]> Reviewed-by: Tomas Glozar <[email protected]> Tested-by: Tomas Glozar <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent e82c78a commit dc4d4e7

File tree

5 files changed

+8
-16
lines changed

5 files changed

+8
-16
lines changed

tools/tracing/rtla/src/osnoise_hist.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -983,10 +983,7 @@ int osnoise_hist_main(int argc, char *argv[])
983983

984984
if (osnoise_trace_is_off(tool, record)) {
985985
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);
990987
}
991988

992989
out_hist:

tools/tracing/rtla/src/osnoise_top.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -813,10 +813,7 @@ int osnoise_top_main(int argc, char **argv)
813813

814814
if (osnoise_trace_is_off(tool, record)) {
815815
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);
820817
}
821818

822819
out_top:

tools/tracing/rtla/src/timerlat_hist.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,10 +1473,7 @@ int timerlat_hist_main(int argc, char *argv[])
14731473
if (!params->no_aa)
14741474
timerlat_auto_analysis(params->stop_us, params->stop_total_us);
14751475

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);
14801477
}
14811478

14821479
out_hist:

tools/tracing/rtla/src/timerlat_top.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,10 +1295,7 @@ int timerlat_top_main(int argc, char *argv[])
12951295
if (!params->no_aa)
12961296
timerlat_auto_analysis(params->stop_us, params->stop_total_us);
12971297

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);
13021299
} else if (params->aa_only) {
13031300
/*
13041301
* If the trace did not stop with --aa-only, at least print the

tools/tracing/rtla/src/trace.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,16 @@ int save_trace_to_file(struct tracefs_instance *inst, const char *filename)
7575
int out_fd, in_fd;
7676
int retval = -1;
7777

78+
if (!filename)
79+
return 0;
80+
7881
in_fd = tracefs_instance_file_open(inst, file, O_RDONLY);
7982
if (in_fd < 0) {
8083
err_msg("Failed to open trace file\n");
8184
return -1;
8285
}
8386

87+
printf(" Saving trace to %s\n", filename);
8488
out_fd = creat(filename, mode);
8589
if (out_fd < 0) {
8690
err_msg("Failed to create output file %s\n", filename);

0 commit comments

Comments
 (0)