Commit dc4d4e7c authored by Costa Shulyupin's avatar Costa Shulyupin Committed by Steven Rostedt (Google)
Browse files

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: default avatarCosta Shulyupin <costa.shul@redhat.com>
Reviewed-by: default avatarTomas Glozar <tglozar@redhat.com>
Tested-by: default avatarTomas Glozar <tglozar@redhat.com>
Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
parent e82c78af
Loading
Loading
Loading
Loading
+1 −4
Original line number Diff line number Diff line
@@ -983,11 +983,8 @@ 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);
	}
	}

out_hist:
	trace_events_destroy(&record->trace, params->events);
+1 −4
Original line number Diff line number Diff line
@@ -813,11 +813,8 @@ 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);
	}
	}

out_top:
	trace_events_destroy(&record->trace, params->events);
+1 −4
Original line number Diff line number Diff line
@@ -1473,11 +1473,8 @@ 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);
	}
	}

out_hist:
	timerlat_aa_destroy();
+1 −4
Original line number Diff line number Diff line
@@ -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);
		}
	} else if (params->aa_only) {
		/*
		 * If the trace did not stop with --aa-only, at least print the
+4 −0
Original line number Diff line number Diff line
@@ -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);