Skip to content

Commit 51d64c3

Browse files
Daniel Bristot de Oliveirarostedt
authored andcommitted
rtla: Add -e/--event support
Add -e/--event option. This option enables 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. This option is available for all current tools. Link: https://lkml.kernel.org/r/6a3b753be9b1e811953995f7f21a86918ad13390.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 b5aa0be commit 51d64c3

5 files changed

Lines changed: 114 additions & 11 deletions

File tree

Documentation/tools/rtla/common_options.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414

1515
Save the stopped trace to [*file|osnoise_trace.txt*].
1616

17+
**-e**, **--event** *sys:event*
18+
19+
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.
20+
1721
**-P**, **--priority** *o:prio|r:prio|f:prio|d:runtime:period*
1822

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

tools/tracing/rtla/src/osnoise_hist.c

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ struct osnoise_hist_params {
2929
int set_sched;
3030
int output_divisor;
3131
struct sched_attr sched_param;
32+
struct trace_events *events;
3233

3334
char no_header;
3435
char no_summary;
@@ -427,8 +428,8 @@ static void osnoise_hist_usage(char *usage)
427428
static const char * const msg[] = {
428429
"",
429430
" usage: rtla osnoise hist [-h] [-D] [-d s] [-a us] [-p us] [-r us] [-s us] [-S us] \\",
430-
" [-T us] [-t[=file]] [-c cpu-list] [-P priority] [-b N] [-E N] [--no-header] \\",
431-
" [--no-summary] [--no-index] [--with-zeros]",
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]",
432433
"",
433434
" -h/--help: print this menu",
434435
" -a/--auto: set automatic trace mode, stopping the session if argument in us sample is hit",
@@ -441,6 +442,7 @@ static void osnoise_hist_usage(char *usage)
441442
" -d/--duration time[s|m|h|d]: duration of the session",
442443
" -D/--debug: print debug info",
443444
" -t/--trace[=file]: save the stopped trace to [file|osnoise_trace.txt]",
445+
" -e/--event <sys:event>: enable the <sys:event> in the trace instance, multiple -e are allowed",
444446
" -b/--bucket-size N: set the histogram bucket size (default 1)",
445447
" -E/--entries N: set the number of entries of the histogram (default 256)",
446448
" --no-header: do not print header",
@@ -474,6 +476,7 @@ static struct osnoise_hist_params
474476
*osnoise_hist_parse_args(int argc, char *argv[])
475477
{
476478
struct osnoise_hist_params *params;
479+
struct trace_events *tevent;
477480
int retval;
478481
int c;
479482

@@ -501,6 +504,7 @@ static struct osnoise_hist_params
501504
{"stop", required_argument, 0, 's'},
502505
{"stop-total", required_argument, 0, 'S'},
503506
{"trace", optional_argument, 0, 't'},
507+
{"event", required_argument, 0, 'e'},
504508
{"threshold", required_argument, 0, 'T'},
505509
{"no-header", no_argument, 0, '0'},
506510
{"no-summary", no_argument, 0, '1'},
@@ -512,7 +516,7 @@ static struct osnoise_hist_params
512516
/* getopt_long stores the option index here. */
513517
int option_index = 0;
514518

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

518522
/* detect the end of the options. */
@@ -550,6 +554,18 @@ static struct osnoise_hist_params
550554
if (!params->duration)
551555
osnoise_hist_usage("Invalid -D duration\n");
552556
break;
557+
case 'e':
558+
tevent = trace_event_alloc(optarg);
559+
if (!tevent) {
560+
err_msg("Error alloc trace event");
561+
exit(EXIT_FAILURE);
562+
}
563+
564+
if (params->events)
565+
tevent->next = params->events;
566+
567+
params->events = tevent;
568+
break;
553569
case 'E':
554570
params->entries = get_llong_from_str(optarg);
555571
if ((params->entries < 10) || (params->entries > 9999999))
@@ -778,6 +794,13 @@ int osnoise_hist_main(int argc, char *argv[])
778794
err_msg("Failed to enable the trace instance\n");
779795
goto out_hist;
780796
}
797+
798+
if (params->events) {
799+
retval = trace_events_enable(&record->trace, params->events);
800+
if (retval)
801+
goto out_hist;
802+
}
803+
781804
trace_instance_start(&record->trace);
782805
}
783806

@@ -817,6 +840,8 @@ int osnoise_hist_main(int argc, char *argv[])
817840
}
818841

819842
out_hist:
843+
trace_events_destroy(&record->trace, params->events);
844+
params->events = NULL;
820845
osnoise_free_histogram(tool->data);
821846
out_destroy:
822847
osnoise_destroy_tool(record);

tools/tracing/rtla/src/osnoise_top.c

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ struct osnoise_top_params {
3131
int quiet;
3232
int set_sched;
3333
struct sched_attr sched_param;
34+
struct trace_events *events;
3435
};
3536

3637
struct osnoise_top_cpu {
@@ -246,7 +247,7 @@ void osnoise_top_usage(char *usage)
246247

247248
static const char * const msg[] = {
248249
" usage: rtla osnoise [top] [-h] [-q] [-D] [-d s] [-a us] [-p us] [-r us] [-s us] [-S us] \\",
249-
" [-T us] [-t[=file]] [-c cpu-list] [-P priority]",
250+
" [-T us] [-t[=file]] [-e sys[:event]] [-c cpu-list] [-P priority]",
250251
"",
251252
" -h/--help: print this menu",
252253
" -a/--auto: set automatic trace mode, stopping the session if argument in us sample is hit",
@@ -259,6 +260,7 @@ void osnoise_top_usage(char *usage)
259260
" -d/--duration time[s|m|h|d]: duration of the session",
260261
" -D/--debug: print debug info",
261262
" -t/--trace[=file]: save the stopped trace to [file|osnoise_trace.txt]",
263+
" -e/--event <sys:event>: enable the <sys:event> in the trace instance, multiple -e are allowed",
262264
" -q/--quiet print only a summary at the end",
263265
" -P/--priority o:prio|r:prio|f:prio|d:runtime:period : set scheduling parameters",
264266
" o:prio - use SCHED_OTHER with prio",
@@ -286,6 +288,7 @@ void osnoise_top_usage(char *usage)
286288
struct osnoise_top_params *osnoise_top_parse_args(int argc, char **argv)
287289
{
288290
struct osnoise_top_params *params;
291+
struct trace_events *tevent;
289292
int retval;
290293
int c;
291294

@@ -299,6 +302,7 @@ struct osnoise_top_params *osnoise_top_parse_args(int argc, char **argv)
299302
{"cpus", required_argument, 0, 'c'},
300303
{"debug", no_argument, 0, 'D'},
301304
{"duration", required_argument, 0, 'd'},
305+
{"event", required_argument, 0, 'e'},
302306
{"help", no_argument, 0, 'h'},
303307
{"period", required_argument, 0, 'p'},
304308
{"priority", required_argument, 0, 'P'},
@@ -314,7 +318,7 @@ struct osnoise_top_params *osnoise_top_parse_args(int argc, char **argv)
314318
/* getopt_long stores the option index here. */
315319
int option_index = 0;
316320

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

320324
/* Detect the end of the options. */
@@ -347,6 +351,18 @@ struct osnoise_top_params *osnoise_top_parse_args(int argc, char **argv)
347351
if (!params->duration)
348352
osnoise_top_usage("Invalid -D duration\n");
349353
break;
354+
case 'e':
355+
tevent = trace_event_alloc(optarg);
356+
if (!tevent) {
357+
err_msg("Error alloc trace event");
358+
exit(EXIT_FAILURE);
359+
}
360+
361+
if (params->events)
362+
tevent->next = params->events;
363+
params->events = tevent;
364+
365+
break;
350366
case 'h':
351367
case '?':
352368
osnoise_top_usage(NULL);
@@ -556,6 +572,13 @@ int osnoise_top_main(int argc, char **argv)
556572
err_msg("Failed to enable the trace instance\n");
557573
goto out_top;
558574
}
575+
576+
if (params->events) {
577+
retval = trace_events_enable(&record->trace, params->events);
578+
if (retval)
579+
goto out_top;
580+
}
581+
559582
trace_instance_start(&record->trace);
560583
}
561584

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

599622
out_top:
623+
trace_events_destroy(&record->trace, params->events);
624+
params->events = NULL;
600625
osnoise_free_top(tool->data);
601626
osnoise_destroy_tool(record);
602627
osnoise_destroy_tool(tool);

tools/tracing/rtla/src/timerlat_hist.c

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ struct timerlat_hist_params {
2929
int duration;
3030
int set_sched;
3131
struct sched_attr sched_param;
32+
struct trace_events *events;
3233

3334
char no_irq;
3435
char no_thread;
@@ -429,8 +430,8 @@ static void timerlat_hist_usage(char *usage)
429430
char *msg[] = {
430431
"",
431432
" usage: [rtla] timerlat hist [-h] [-q] [-d s] [-D] [-n] [-a us] [-p us] [-i us] [-T us] [-s us] \\",
432-
" [-t[=file]] [-c cpu-list] [-P priority] [-E N] [-b N] [--no-irq] [--no-thread] [--no-header] \\",
433-
" [--no-summary] [--no-index] [--with-zeros]",
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]",
434435
"",
435436
" -h/--help: print this menu",
436437
" -a/--auto: set automatic trace mode, stopping the session if argument in us latency is hit",
@@ -441,7 +442,8 @@ static void timerlat_hist_usage(char *usage)
441442
" -c/--cpus cpus: run the tracer only on the given cpus",
442443
" -d/--duration time[m|h|d]: duration of the session in seconds",
443444
" -D/--debug: print debug info",
444-
" -T/--trace[=file]: save the stopped trace to [file|timerlat_trace.txt]",
445+
" -t/--trace[=file]: save the stopped trace to [file|timerlat_trace.txt]",
446+
" -e/--event <sys:event>: enable the <sys:event> in the trace instance, multiple -e are allowed",
445447
" -n/--nano: display data in nanoseconds",
446448
" -b/--bucket-size N: set the histogram bucket size (default 1)",
447449
" -E/--entries N: set the number of entries of the histogram (default 256)",
@@ -478,6 +480,7 @@ static struct timerlat_hist_params
478480
*timerlat_hist_parse_args(int argc, char *argv[])
479481
{
480482
struct timerlat_hist_params *params;
483+
struct trace_events *tevent;
481484
int auto_thresh;
482485
int retval;
483486
int c;
@@ -507,6 +510,7 @@ static struct timerlat_hist_params
507510
{"stack", required_argument, 0, 's'},
508511
{"thread", required_argument, 0, 'T'},
509512
{"trace", optional_argument, 0, 't'},
513+
{"event", required_argument, 0, 'e'},
510514
{"no-irq", no_argument, 0, '0'},
511515
{"no-thread", no_argument, 0, '1'},
512516
{"no-header", no_argument, 0, '2'},
@@ -519,7 +523,7 @@ static struct timerlat_hist_params
519523
/* getopt_long stores the option index here. */
520524
int option_index = 0;
521525

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

525529
/* detect the end of the options. */
@@ -559,6 +563,18 @@ static struct timerlat_hist_params
559563
if (!params->duration)
560564
timerlat_hist_usage("Invalid -D duration\n");
561565
break;
566+
case 'e':
567+
tevent = trace_event_alloc(optarg);
568+
if (!tevent) {
569+
err_msg("Error alloc trace event");
570+
exit(EXIT_FAILURE);
571+
}
572+
573+
if (params->events)
574+
tevent->next = params->events;
575+
576+
params->events = tevent;
577+
break;
562578
case 'E':
563579
params->entries = get_llong_from_str(optarg);
564580
if ((params->entries < 10) || (params->entries > 9999999))
@@ -791,6 +807,13 @@ int timerlat_hist_main(int argc, char *argv[])
791807
err_msg("Failed to enable the trace instance\n");
792808
goto out_hist;
793809
}
810+
811+
if (params->events) {
812+
retval = trace_events_enable(&record->trace, params->events);
813+
if (retval)
814+
goto out_hist;
815+
}
816+
794817
trace_instance_start(&record->trace);
795818
}
796819

@@ -828,6 +851,8 @@ int timerlat_hist_main(int argc, char *argv[])
828851
}
829852

830853
out_hist:
854+
trace_events_destroy(&record->trace, params->events);
855+
params->events = NULL;
831856
timerlat_free_histogram(tool->data);
832857
osnoise_destroy_tool(record);
833858
osnoise_destroy_tool(tool);

tools/tracing/rtla/src/timerlat_top.c

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ struct timerlat_top_params {
3030
int quiet;
3131
int set_sched;
3232
struct sched_attr sched_param;
33+
struct trace_events *events;
3334
};
3435

3536
struct timerlat_top_cpu {
@@ -267,7 +268,7 @@ static void timerlat_top_usage(char *usage)
267268
static const char *const msg[] = {
268269
"",
269270
" usage: rtla timerlat [top] [-h] [-q] [-a us] [-d s] [-D] [-n] [-p us] [-i us] [-T us] [-s us] \\",
270-
" [[-t[=file]] -c cpu-list] [-P priority]",
271+
" [[-t[=file]] [-e sys[:event]] [-c cpu-list] [-P priority]",
271272
"",
272273
" -h/--help: print this menu",
273274
" -a/--auto: set automatic trace mode, stopping the session if argument in us latency is hit",
@@ -279,6 +280,7 @@ static void timerlat_top_usage(char *usage)
279280
" -d/--duration time[m|h|d]: duration of the session in seconds",
280281
" -D/--debug: print debug info",
281282
" -t/--trace[=file]: save the stopped trace to [file|timerlat_trace.txt]",
283+
" -e/--event <sys:event>: enable the <sys:event> in the trace instance, multiple -e are allowed",
282284
" -n/--nano: display data in nanoseconds",
283285
" -q/--quiet print only a summary at the end",
284286
" -P/--priority o:prio|r:prio|f:prio|d:runtime:period : set scheduling parameters",
@@ -308,6 +310,7 @@ static struct timerlat_top_params
308310
*timerlat_top_parse_args(int argc, char **argv)
309311
{
310312
struct timerlat_top_params *params;
313+
struct trace_events *tevent;
311314
long long auto_thresh;
312315
int retval;
313316
int c;
@@ -325,6 +328,7 @@ static struct timerlat_top_params
325328
{"cpus", required_argument, 0, 'c'},
326329
{"debug", no_argument, 0, 'D'},
327330
{"duration", required_argument, 0, 'd'},
331+
{"event", required_argument, 0, 'e'},
328332
{"help", no_argument, 0, 'h'},
329333
{"irq", required_argument, 0, 'i'},
330334
{"nano", no_argument, 0, 'n'},
@@ -340,7 +344,7 @@ static struct timerlat_top_params
340344
/* getopt_long stores the option index here. */
341345
int option_index = 0;
342346

343-
c = getopt_long(argc, argv, "a:c:d:Dhi:np:P:qs:t::T:",
347+
c = getopt_long(argc, argv, "a:c:d:De:hi:np:P:qs:t::T:",
344348
long_options, &option_index);
345349

346350
/* detect the end of the options. */
@@ -375,6 +379,17 @@ static struct timerlat_top_params
375379
if (!params->duration)
376380
timerlat_top_usage("Invalid -D duration\n");
377381
break;
382+
case 'e':
383+
tevent = trace_event_alloc(optarg);
384+
if (!tevent) {
385+
err_msg("Error alloc trace event");
386+
exit(EXIT_FAILURE);
387+
}
388+
389+
if (params->events)
390+
tevent->next = params->events;
391+
params->events = tevent;
392+
break;
378393
case 'h':
379394
case '?':
380395
timerlat_top_usage(NULL);
@@ -583,6 +598,13 @@ int timerlat_top_main(int argc, char *argv[])
583598
err_msg("Failed to enable the trace instance\n");
584599
goto out_top;
585600
}
601+
602+
if (params->events) {
603+
retval = trace_events_enable(&record->trace, params->events);
604+
if (retval)
605+
goto out_top;
606+
}
607+
586608
trace_instance_start(&record->trace);
587609
}
588610

@@ -624,6 +646,8 @@ int timerlat_top_main(int argc, char *argv[])
624646
}
625647

626648
out_top:
649+
trace_events_destroy(&record->trace, params->events);
650+
params->events = NULL;
627651
timerlat_free_top(top->data);
628652
osnoise_destroy_tool(record);
629653
osnoise_destroy_tool(top);

0 commit comments

Comments
 (0)