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

tools/rtla: Add osnoise_trace_is_off()

All of the users of trace_is_off() passes in &record->trace as the second
parameter, where record is a pointer to a struct osnoise_tool. This record
could be NULL and there is a hidden dependency that the trace field is the
first field to allow &record->trace to work with a NULL record pointer.

In order to make this code a bit more robust, as record shouldn't be
dereferenced if it is NULL, even if the code does work, create a new
function called osnoise_trace_is_off() that takes the pointer to a
struct osnoise_tool as its second parameter. This way it can properly test
if it is NULL before it dereferences it.

The old function trace_is_off() is removed and the function
osnoise_trace_is_off() is added into osnoise.c which is what the
struct osnoise_tool is associated with.

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: Tomas Glozar <tglozar@redhat.com>
Cc: Gabriele Monaco <gmonaco@redhat.com>
Link: https://lore.kernel.org/20250115180055.2136815-1-costa.shul@redhat.com


Signed-off-by: default avatarCosta Shulyupin <costa.shul@redhat.com>
Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
parent 217f0b1e
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -1079,6 +1079,22 @@ struct osnoise_tool *osnoise_init_trace_tool(char *tracer)
	return NULL;
}

bool osnoise_trace_is_off(struct osnoise_tool *tool, struct osnoise_tool *record)
{
	/*
	 * The tool instance is always present, it is the one used to collect
	 * data.
	 */
	if (!tracefs_trace_is_on(tool->trace.inst))
		return true;

	/*
	 * The trace record instance is only enabled when -t is set. IOW, when the system
	 * is tracing.
	 */
	return record && !tracefs_trace_is_on(record->trace.inst);
}

static void osnoise_usage(int err)
{
	int i;
+1 −0
Original line number Diff line number Diff line
@@ -104,6 +104,7 @@ struct osnoise_tool {
void osnoise_destroy_tool(struct osnoise_tool *top);
struct osnoise_tool *osnoise_init_tool(char *tool_name);
struct osnoise_tool *osnoise_init_trace_tool(char *tracer);
bool osnoise_trace_is_off(struct osnoise_tool *tool, struct osnoise_tool *record);

int osnoise_hist_main(int argc, char *argv[]);
int osnoise_top_main(int argc, char **argv);
+2 −2
Original line number Diff line number Diff line
@@ -970,7 +970,7 @@ int osnoise_hist_main(int argc, char *argv[])
			goto out_hist;
		}

		if (trace_is_off(&tool->trace, &record->trace))
		if (osnoise_trace_is_off(tool, record))
			break;
	}

@@ -980,7 +980,7 @@ int osnoise_hist_main(int argc, char *argv[])

	return_value = 0;

	if (trace_is_off(&tool->trace, &record->trace)) {
	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);
+2 −2
Original line number Diff line number Diff line
@@ -801,7 +801,7 @@ int osnoise_top_main(int argc, char **argv)
		if (!params->quiet)
			osnoise_print_stats(params, tool);

		if (trace_is_off(&tool->trace, &record->trace))
		if (osnoise_trace_is_off(tool, record))
			break;

	}
@@ -810,7 +810,7 @@ int osnoise_top_main(int argc, char **argv)

	return_value = 0;

	if (trace_is_off(&tool->trace, &record->trace)) {
	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);
+2 −2
Original line number Diff line number Diff line
@@ -1347,7 +1347,7 @@ int timerlat_hist_main(int argc, char *argv[])
			goto out_hist;
		}

		if (trace_is_off(&tool->trace, &record->trace))
		if (osnoise_trace_is_off(tool, record))
			break;

		/* is there still any user-threads ? */
@@ -1368,7 +1368,7 @@ int timerlat_hist_main(int argc, char *argv[])

	return_value = 0;

	if (trace_is_off(&tool->trace, &record->trace) && !stop_tracing) {
	if (osnoise_trace_is_off(tool, record) && !stop_tracing) {
		printf("rtla timerlat hit stop tracing\n");

		if (!params->no_aa)
Loading