Skip to content

Commit 1a75489

Browse files
Daniel Bristot de Oliveirarostedt
authored andcommitted
rtla: Add --trigger support
Add --trigger option. This option enables a trace event trigger to the previous -e sys:event argument, allowing some advanced tracing options. For instance, in a system with CPUs 2:23 isolated, it is possible to get a stack trace of thread wakeup targeting those CPUs while running osnoise with the following command line: # osnoise top -c 2-23 -a 50 -e sched:sched_wakeup --trigger="stacktrace if target_cpu >= 2" This option is available for all current tools. Link: https://lkml.kernel.org/r/07d2983d5f71261d4da89dbaf02efcad100ab8ee.1646247211.git.bristot@kernel.org Cc: Daniel Bristot de Oliveira <bristot@kernel.org> Cc: Clark Williams <williams@redhat.com> Cc: Juri Lelli <juri.lelli@redhat.com> Cc: Jonathan Corbet <corbet@lwn.net> Signed-off-by: Daniel Bristot de Oliveira <bristot@kernel.org> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent 336c92b commit 1a75489

5 files changed

Lines changed: 65 additions & 10 deletions

File tree

Documentation/tools/rtla/common_options.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818

1919
Enable an event in the trace (**-t**) session. The argument can be a specific event, e.g., **-e** *sched:sched_switch*, or all events of a system group, e.g., **-e** *sched*. Multiple **-e** are allowed. It is only active when **-t** or **-a** are set.
2020

21+
**--trigger** *<trigger>*
22+
Enable a trace event trigger to the previous **-e** *sys:event*. For further information about event trigger see https://www.kernel.org/doc/html/latest/trace/events.html#event-triggers.
23+
2124
**-P**, **--priority** *o:prio|r:prio|f:prio|d:runtime:period*
2225

2326
Set scheduling parameters to the osnoise tracer threads, the format to set the priority are:

tools/tracing/rtla/src/osnoise_hist.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -428,8 +428,8 @@ static void osnoise_hist_usage(char *usage)
428428
static const char * const msg[] = {
429429
"",
430430
" usage: rtla osnoise hist [-h] [-D] [-d s] [-a us] [-p us] [-r us] [-s us] [-S us] \\",
431-
" [-T us] [-t[=file]] [-e sys[:event]] [-c cpu-list] [-P priority] [-b N] [-E N] \\",
432-
" [--no-header] [--no-summary] [--no-index] [--with-zeros]",
431+
" [-T us] [-t[=file]] [-e sys[:event]] [--trigger <trigger>] [-c cpu-list] [-P priority] \\",
432+
" [-b N] [-E N] [--no-header] [--no-summary] [--no-index] [--with-zeros]",
433433
"",
434434
" -h/--help: print this menu",
435435
" -a/--auto: set automatic trace mode, stopping the session if argument in us sample is hit",
@@ -443,6 +443,7 @@ static void osnoise_hist_usage(char *usage)
443443
" -D/--debug: print debug info",
444444
" -t/--trace[=file]: save the stopped trace to [file|osnoise_trace.txt]",
445445
" -e/--event <sys:event>: enable the <sys:event> in the trace instance, multiple -e are allowed",
446+
" --trigger <trigger>: enable a trace event trigger to the previous -e event",
446447
" -b/--bucket-size N: set the histogram bucket size (default 1)",
447448
" -E/--entries N: set the number of entries of the histogram (default 256)",
448449
" --no-header: do not print header",
@@ -510,13 +511,14 @@ static struct osnoise_hist_params
510511
{"no-summary", no_argument, 0, '1'},
511512
{"no-index", no_argument, 0, '2'},
512513
{"with-zeros", no_argument, 0, '3'},
514+
{"trigger", required_argument, 0, '4'},
513515
{0, 0, 0, 0}
514516
};
515517

516518
/* getopt_long stores the option index here. */
517519
int option_index = 0;
518520

519-
c = getopt_long(argc, argv, "a:c:b:d:e:E:Dhp:P:r:s:S:t::T:0123",
521+
c = getopt_long(argc, argv, "a:c:b:d:e:E:Dhp:P:r:s:S:t::T:01234:",
520522
long_options, &option_index);
521523

522524
/* detect the end of the options. */
@@ -619,6 +621,17 @@ static struct osnoise_hist_params
619621
case '3': /* with zeros */
620622
params->with_zeros = 1;
621623
break;
624+
case '4': /* trigger */
625+
if (params->events) {
626+
retval = trace_event_add_trigger(params->events, optarg);
627+
if (retval) {
628+
err_msg("Error adding trigger %s\n", optarg);
629+
exit(EXIT_FAILURE);
630+
}
631+
} else {
632+
osnoise_hist_usage("--trigger requires a previous -e\n");
633+
}
634+
break;
622635
default:
623636
osnoise_hist_usage("Invalid option");
624637
}

tools/tracing/rtla/src/osnoise_top.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ void osnoise_top_usage(char *usage)
247247

248248
static const char * const msg[] = {
249249
" usage: rtla osnoise [top] [-h] [-q] [-D] [-d s] [-a us] [-p us] [-r us] [-s us] [-S us] \\",
250-
" [-T us] [-t[=file]] [-e sys[:event]] [-c cpu-list] [-P priority]",
250+
" [-T us] [-t[=file]] [-e sys[:event]] [--trigger <trigger>] [-c cpu-list] [-P priority]",
251251
"",
252252
" -h/--help: print this menu",
253253
" -a/--auto: set automatic trace mode, stopping the session if argument in us sample is hit",
@@ -261,6 +261,7 @@ void osnoise_top_usage(char *usage)
261261
" -D/--debug: print debug info",
262262
" -t/--trace[=file]: save the stopped trace to [file|osnoise_trace.txt]",
263263
" -e/--event <sys:event>: enable the <sys:event> in the trace instance, multiple -e are allowed",
264+
" --trigger <trigger>: enable a trace event trigger to the previous -e event",
264265
" -q/--quiet print only a summary at the end",
265266
" -P/--priority o:prio|r:prio|f:prio|d:runtime:period : set scheduling parameters",
266267
" o:prio - use SCHED_OTHER with prio",
@@ -312,13 +313,14 @@ struct osnoise_top_params *osnoise_top_parse_args(int argc, char **argv)
312313
{"stop-total", required_argument, 0, 'S'},
313314
{"threshold", required_argument, 0, 'T'},
314315
{"trace", optional_argument, 0, 't'},
316+
{"trigger", required_argument, 0, '0'},
315317
{0, 0, 0, 0}
316318
};
317319

318320
/* getopt_long stores the option index here. */
319321
int option_index = 0;
320322

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

324326
/* Detect the end of the options. */
@@ -402,6 +404,17 @@ struct osnoise_top_params *osnoise_top_parse_args(int argc, char **argv)
402404
case 'T':
403405
params->threshold = get_llong_from_str(optarg);
404406
break;
407+
case '0': /* trigger */
408+
if (params->events) {
409+
retval = trace_event_add_trigger(params->events, optarg);
410+
if (retval) {
411+
err_msg("Error adding trigger %s\n", optarg);
412+
exit(EXIT_FAILURE);
413+
}
414+
} else {
415+
osnoise_top_usage("--trigger requires a previous -e\n");
416+
}
417+
break;
405418
default:
406419
osnoise_top_usage("Invalid option");
407420
}

tools/tracing/rtla/src/timerlat_hist.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,8 @@ static void timerlat_hist_usage(char *usage)
430430
char *msg[] = {
431431
"",
432432
" usage: [rtla] timerlat hist [-h] [-q] [-d s] [-D] [-n] [-a us] [-p us] [-i us] [-T us] [-s us] \\",
433-
" [-t[=file]] [-e sys[:event]] [-c cpu-list] [-P priority] [-E N] [-b N] [--no-irq] \\",
434-
" [--no-thread] [--no-header] [--no-summary] [--no-index] [--with-zeros]",
433+
" [-t[=file]] [-e sys[:event]] [--trigger <trigger>] [-c cpu-list] [-P priority] [-E N] \\",
434+
" [-b N] [--no-irq] [--no-thread] [--no-header] [--no-summary] [--no-index] [--with-zeros]",
435435
"",
436436
" -h/--help: print this menu",
437437
" -a/--auto: set automatic trace mode, stopping the session if argument in us latency is hit",
@@ -444,6 +444,7 @@ static void timerlat_hist_usage(char *usage)
444444
" -D/--debug: print debug info",
445445
" -t/--trace[=file]: save the stopped trace to [file|timerlat_trace.txt]",
446446
" -e/--event <sys:event>: enable the <sys:event> in the trace instance, multiple -e are allowed",
447+
" --trigger <trigger>: enable a trace event trigger to the previous -e event",
447448
" -n/--nano: display data in nanoseconds",
448449
" -b/--bucket-size N: set the histogram bucket size (default 1)",
449450
" -E/--entries N: set the number of entries of the histogram (default 256)",
@@ -517,13 +518,14 @@ static struct timerlat_hist_params
517518
{"no-summary", no_argument, 0, '3'},
518519
{"no-index", no_argument, 0, '4'},
519520
{"with-zeros", no_argument, 0, '5'},
521+
{"trigger", required_argument, 0, '6'},
520522
{0, 0, 0, 0}
521523
};
522524

523525
/* getopt_long stores the option index here. */
524526
int option_index = 0;
525527

526-
c = getopt_long(argc, argv, "a:c:b:d:e:E:Dhi:np:P:s:t::T:012345",
528+
c = getopt_long(argc, argv, "a:c:b:d:e:E:Dhi:np:P:s:t::T:0123456:",
527529
long_options, &option_index);
528530

529531
/* detect the end of the options. */
@@ -632,6 +634,17 @@ static struct timerlat_hist_params
632634
case '5': /* with zeros */
633635
params->with_zeros = 1;
634636
break;
637+
case '6': /* trigger */
638+
if (params->events) {
639+
retval = trace_event_add_trigger(params->events, optarg);
640+
if (retval) {
641+
err_msg("Error adding trigger %s\n", optarg);
642+
exit(EXIT_FAILURE);
643+
}
644+
} else {
645+
timerlat_hist_usage("--trigger requires a previous -e\n");
646+
}
647+
break;
635648
default:
636649
timerlat_hist_usage("Invalid option");
637650
}

tools/tracing/rtla/src/timerlat_top.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ static void timerlat_top_usage(char *usage)
268268
static const char *const msg[] = {
269269
"",
270270
" usage: rtla timerlat [top] [-h] [-q] [-a us] [-d s] [-D] [-n] [-p us] [-i us] [-T us] [-s us] \\",
271-
" [[-t[=file]] [-e sys[:event]] [-c cpu-list] [-P priority]",
271+
" [[-t[=file]] [-e sys[:event]] [--trigger <trigger>] [-c cpu-list] [-P priority]",
272272
"",
273273
" -h/--help: print this menu",
274274
" -a/--auto: set automatic trace mode, stopping the session if argument in us latency is hit",
@@ -281,6 +281,7 @@ static void timerlat_top_usage(char *usage)
281281
" -D/--debug: print debug info",
282282
" -t/--trace[=file]: save the stopped trace to [file|timerlat_trace.txt]",
283283
" -e/--event <sys:event>: enable the <sys:event> in the trace instance, multiple -e are allowed",
284+
" --trigger <command>: enable a trace event trigger to the previous -e event",
284285
" -n/--nano: display data in nanoseconds",
285286
" -q/--quiet print only a summary at the end",
286287
" -P/--priority o:prio|r:prio|f:prio|d:runtime:period : set scheduling parameters",
@@ -338,13 +339,14 @@ static struct timerlat_top_params
338339
{"stack", required_argument, 0, 's'},
339340
{"thread", required_argument, 0, 'T'},
340341
{"trace", optional_argument, 0, 't'},
342+
{"trigger", required_argument, 0, '0'},
341343
{0, 0, 0, 0}
342344
};
343345

344346
/* getopt_long stores the option index here. */
345347
int option_index = 0;
346348

347-
c = getopt_long(argc, argv, "a:c:d:De:hi:np:P:qs:t::T:",
349+
c = getopt_long(argc, argv, "a:c:d:De:hi:np:P:qs:t::T:0:",
348350
long_options, &option_index);
349351

350352
/* detect the end of the options. */
@@ -427,6 +429,17 @@ static struct timerlat_top_params
427429
else
428430
params->trace_output = "timerlat_trace.txt";
429431
break;
432+
case '0': /* trigger */
433+
if (params->events) {
434+
retval = trace_event_add_trigger(params->events, optarg);
435+
if (retval) {
436+
err_msg("Error adding trigger %s\n", optarg);
437+
exit(EXIT_FAILURE);
438+
}
439+
} else {
440+
timerlat_top_usage("--trigger requires a previous -e\n");
441+
}
442+
break;
430443
default:
431444
timerlat_top_usage("Invalid option");
432445
}

0 commit comments

Comments
 (0)