[PATCH 6/7] rtla/osnoise: Add -e/--event option

From: Daniel Bristot de Oliveira
Date: Fri Feb 18 2022 - 06:09:55 EST


Add the -e <sys:[event]> option. This option allows the osnoise top to
enable additional events to the trace instance. Multiple -e are enabled,
and it implies the -t option (if not already set).

Cc: Daniel Bristot de Oliveira <bristot@xxxxxxxxxx>
Cc: Steven Rostedt <rostedt@xxxxxxxxxxx>
Cc: Jonathan Corbet <corbet@xxxxxxx>
Cc: linux-trace-devel@xxxxxxxxxxxxxxx
Cc: linux-doc@xxxxxxxxxxxxxxx
Cc: linux-kernel@xxxxxxxxxxxxxxx
Signed-off-by: Daniel Bristot de Oliveira <bristot@xxxxxxxxxx>
---
tools/tracing/rtla/src/osnoise_top.c | 29 +++++++++++++++++++++++++++-
1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/tools/tracing/rtla/src/osnoise_top.c b/tools/tracing/rtla/src/osnoise_top.c
index 714976080dd8..c5ecaebe6a0d 100644
--- a/tools/tracing/rtla/src/osnoise_top.c
+++ b/tools/tracing/rtla/src/osnoise_top.c
@@ -31,6 +31,7 @@ struct osnoise_top_params {
int quiet;
int set_sched;
struct sched_attr sched_param;
+ struct trace_events *events;
};

struct osnoise_top_cpu {
@@ -286,6 +287,7 @@ void osnoise_top_usage(char *usage)
struct osnoise_top_params *osnoise_top_parse_args(int argc, char **argv)
{
struct osnoise_top_params *params;
+ struct trace_events *tevent;
int retval;
int c;

@@ -299,6 +301,7 @@ struct osnoise_top_params *osnoise_top_parse_args(int argc, char **argv)
{"cpus", required_argument, 0, 'c'},
{"debug", no_argument, 0, 'D'},
{"duration", required_argument, 0, 'd'},
+ {"event", required_argument, 0, 'e'},
{"help", no_argument, 0, 'h'},
{"period", required_argument, 0, 'p'},
{"priority", required_argument, 0, 'P'},
@@ -314,7 +317,7 @@ struct osnoise_top_params *osnoise_top_parse_args(int argc, char **argv)
/* getopt_long stores the option index here. */
int option_index = 0;

- c = getopt_long(argc, argv, "a:c:d:Dhp:P:qr:s:S:t::T:",
+ c = getopt_long(argc, argv, "a:c:d:De:hp:P:qr:s:S:t::T:",
long_options, &option_index);

/* Detect the end of the options. */
@@ -347,6 +350,21 @@ struct osnoise_top_params *osnoise_top_parse_args(int argc, char **argv)
if (!params->duration)
osnoise_top_usage("Invalid -D duration\n");
break;
+ case 'e':
+ tevent = alloc_trace_event(optarg);
+ if (!tevent) {
+ err_msg("error alloc trace event");
+ exit(EXIT_FAILURE);
+ }
+
+ if (params->events)
+ tevent->next = params->events;
+ params->events = tevent;
+
+ /* if -e && !-t -> -t */
+ if (!params->trace_output)
+ params->trace_output = "osnoise_trace.txt";
+ break;
case 'h':
case '?':
osnoise_top_usage(NULL);
@@ -556,6 +574,13 @@ int osnoise_top_main(int argc, char **argv)
err_msg("Failed to enable the trace instance\n");
goto out_top;
}
+
+ if (params->events) {
+ retval = enable_trace_events(&record->trace, params->events);
+ if (retval)
+ goto out_top;
+ }
+
trace_instance_start(&record->trace);
}

@@ -597,6 +622,8 @@ int osnoise_top_main(int argc, char **argv)
}

out_top:
+ destroy_trace_events(&record->trace, params->events);
+ params->events = NULL;
osnoise_free_top(tool->data);
osnoise_destroy_tool(record);
osnoise_destroy_tool(tool);
--
2.34.1