mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git
synced 2026-11-02 23:54:33 +01:00
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]>
This commit is contained in:
1 parent
e82c78afa3
commit
dc4d4e7c72
5 files changed
+8
-16
No files matched your search
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user