Skip to content

Commit c0e795b

Browse files
committed
rtla: Fix -t\--trace[=file]
JIRA: https://issues.redhat.com/browse/RHEL-50869 commit 842fc5b Author: John Kacur <jkacur@redhat.com> Date: Wed May 15 14:30:23 2024 -0400 rtla: Fix -t\--trace[=file] The -t option has an optional argument. The usual case is for a short option to be specified without an '=' and for the long version to be specified with an '=' Various forms of this do not work as expected. For example: rtla timerlat hist -T50 -tfile.txt will result in a truncated file name of "ile.txt" Another example is that the long form without the '=' will result in the default file name instead of the requested file name. This patch properly parses the optional argument with and without '=' and with and without spaces for the short form. This patch was also tested using -t and --trace without providing a file name both as the last requested option and with a following long and short option. For example: rtla timerlat hist -T50 -t -u rtla timerlat hist -T50 --trace -u This fix is applied to both timerlat top and hist and to osnoise top and hist. Here is the full testing for rtla timerlat hist. Before applying the patch rtla timerlat hist -T50 -t=file.txt Works as expected, "file.txt" rtla timerlat hist -T50 -tfile.txt Truncated file name "ile.txt" rtla timerlat hist -T50 -t file.txt Default file name instead of file.txt rtla timerlat hist -T50 --trace=file.txt Truncated file name "ile.txt" rtla timerlat hist -T50 --trace file.txt Default file name "timerlat_trace.txt" instead of "file.txt" After applying the patch: rtla timerlat hist -T50 -t=file.txt Works as expected, "file.txt" rtla timerlat hist -T50 -tfile.txt Works as expected, "file.txt" rtla timerlat hist -T50 -t file.txt Works as expected, "file.txt" rtla timerlat hist -T50 --trace=file.txt Works as expected, "file.txt" rtla timerlat hist -T50 --trace file.txt Works as expected, "file.txt" In addition the following tests were performed to make sure that the default file name worked as expected including with trailing options. rtla timerlat hist -T50 -t Works as expected "timerlat_trace.txt" rtla timerlat hist -T50 --trace Works as expected "timerlat_trace.txt" rtla timerlat hist -T50 -t -u Works as expected "timerlat_trace.txt" rtla timerlat hist -T50 --trace -u Works as expected "timerlat_trace.txt" Link: https://lkml.kernel.org/r/20240515183024.59985-1-jkacur@redhat.com Cc: Daniel Bristot de Oliveria <bristot@kernel.org> Signed-off-by: John Kacur <jkacur@redhat.com> Signed-off-by: Daniel Bristot de Oliveira <bristot@kernel.org> Signed-off-by: Luis Claudio R. Goncalves <lgoncalv@redhat.com>
1 parent 15f5528 commit c0e795b

File tree

4 files changed

+36
-20
lines changed

4 files changed

+36
-20
lines changed

tools/tracing/rtla/src/osnoise_hist.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ static void osnoise_hist_usage(char *usage)
436436
static const char * const msg[] = {
437437
"",
438438
" usage: rtla osnoise hist [-h] [-D] [-d s] [-a us] [-p us] [-r us] [-s us] [-S us] \\",
439-
" [-T us] [-t[=file]] [-e sys[:event]] [--filter <filter>] [--trigger <trigger>] \\",
439+
" [-T us] [-t[file]] [-e sys[:event]] [--filter <filter>] [--trigger <trigger>] \\",
440440
" [-c cpu-list] [-H cpu-list] [-P priority] [-b N] [-E N] [--no-header] [--no-summary] \\",
441441
" [--no-index] [--with-zeros] [-C[=cgroup_name]] [--warm-up]",
442442
"",
@@ -452,7 +452,7 @@ static void osnoise_hist_usage(char *usage)
452452
" -C/--cgroup[=cgroup_name]: set cgroup, if no cgroup_name is passed, the rtla's cgroup will be inherited",
453453
" -d/--duration time[s|m|h|d]: duration of the session",
454454
" -D/--debug: print debug info",
455-
" -t/--trace[=file]: save the stopped trace to [file|osnoise_trace.txt]",
455+
" -t/--trace[file]: save the stopped trace to [file|osnoise_trace.txt]",
456456
" -e/--event <sys:event>: enable the <sys:event> in the trace instance, multiple -e are allowed",
457457
" --filter <filter>: enable a trace event filter to the previous -e event",
458458
" --trigger <trigger>: enable a trace event trigger to the previous -e event",
@@ -642,9 +642,13 @@ static struct osnoise_hist_params
642642
params->threshold = get_llong_from_str(optarg);
643643
break;
644644
case 't':
645-
if (optarg)
646-
/* skip = */
647-
params->trace_output = &optarg[1];
645+
if (optarg) {
646+
if (optarg[0] == '=')
647+
params->trace_output = &optarg[1];
648+
else
649+
params->trace_output = &optarg[0];
650+
} else if (optind < argc && argv[optind][0] != '0')
651+
params->trace_output = argv[optind];
648652
else
649653
params->trace_output = "osnoise_trace.txt";
650654
break;

tools/tracing/rtla/src/osnoise_top.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ static void osnoise_top_usage(struct osnoise_top_params *params, char *usage)
282282

283283
static const char * const msg[] = {
284284
" [-h] [-q] [-D] [-d s] [-a us] [-p us] [-r us] [-s us] [-S us] \\",
285-
" [-T us] [-t[=file]] [-e sys[:event]] [--filter <filter>] [--trigger <trigger>] \\",
285+
" [-T us] [-t[file]] [-e sys[:event]] [--filter <filter>] [--trigger <trigger>] \\",
286286
" [-c cpu-list] [-H cpu-list] [-P priority] [-C[=cgroup_name]] [--warm-up s]",
287287
"",
288288
" -h/--help: print this menu",
@@ -297,7 +297,7 @@ static void osnoise_top_usage(struct osnoise_top_params *params, char *usage)
297297
" -C/--cgroup[=cgroup_name]: set cgroup, if no cgroup_name is passed, the rtla's cgroup will be inherited",
298298
" -d/--duration time[s|m|h|d]: duration of the session",
299299
" -D/--debug: print debug info",
300-
" -t/--trace[=file]: save the stopped trace to [file|osnoise_trace.txt]",
300+
" -t/--trace[file]: save the stopped trace to [file|osnoise_trace.txt]",
301301
" -e/--event <sys:event>: enable the <sys:event> in the trace instance, multiple -e are allowed",
302302
" --filter <filter>: enable a trace event filter to the previous -e event",
303303
" --trigger <trigger>: enable a trace event trigger to the previous -e event",
@@ -483,9 +483,13 @@ struct osnoise_top_params *osnoise_top_parse_args(int argc, char **argv)
483483
params->stop_total_us = get_llong_from_str(optarg);
484484
break;
485485
case 't':
486-
if (optarg)
487-
/* skip = */
488-
params->trace_output = &optarg[1];
486+
if (optarg) {
487+
if (optarg[0] == '=')
488+
params->trace_output = &optarg[1];
489+
else
490+
params->trace_output = &optarg[0];
491+
} else if (optind < argc && argv[optind][0] != '-')
492+
params->trace_output = argv[optind];
489493
else
490494
params->trace_output = "osnoise_trace.txt";
491495
break;

tools/tracing/rtla/src/timerlat_hist.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ static void timerlat_hist_usage(char *usage)
650650
char *msg[] = {
651651
"",
652652
" usage: [rtla] timerlat hist [-h] [-q] [-d s] [-D] [-n] [-a us] [-p us] [-i us] [-T us] [-s us] \\",
653-
" [-t[=file]] [-e sys[:event]] [--filter <filter>] [--trigger <trigger>] [-c cpu-list] [-H cpu-list]\\",
653+
" [-t[file]] [-e sys[:event]] [--filter <filter>] [--trigger <trigger>] [-c cpu-list] [-H cpu-list]\\",
654654
" [-P priority] [-E N] [-b N] [--no-irq] [--no-thread] [--no-header] [--no-summary] \\",
655655
" [--no-index] [--with-zeros] [--dma-latency us] [-C[=cgroup_name]] [--no-aa] [--dump-task] [-u]",
656656
" [--warm-up s]",
@@ -667,7 +667,7 @@ static void timerlat_hist_usage(char *usage)
667667
" -d/--duration time[m|h|d]: duration of the session in seconds",
668668
" --dump-tasks: prints the task running on all CPUs if stop conditions are met (depends on !--no-aa)",
669669
" -D/--debug: print debug info",
670-
" -t/--trace[=file]: save the stopped trace to [file|timerlat_trace.txt]",
670+
" -t/--trace[file]: save the stopped trace to [file|timerlat_trace.txt]",
671671
" -e/--event <sys:event>: enable the <sys:event> in the trace instance, multiple -e are allowed",
672672
" --filter <filter>: enable a trace event filter to the previous -e event",
673673
" --trigger <trigger>: enable a trace event trigger to the previous -e event",
@@ -876,9 +876,13 @@ static struct timerlat_hist_params
876876
params->stop_total_us = get_llong_from_str(optarg);
877877
break;
878878
case 't':
879-
if (optarg)
880-
/* skip = */
881-
params->trace_output = &optarg[1];
879+
if (optarg) {
880+
if (optarg[0] == '=')
881+
params->trace_output = &optarg[1];
882+
else
883+
params->trace_output = &optarg[0];
884+
} else if (optind < argc && argv[optind][0] != '-')
885+
params->trace_output = argv[optind];
882886
else
883887
params->trace_output = "timerlat_trace.txt";
884888
break;

tools/tracing/rtla/src/timerlat_top.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ static void timerlat_top_usage(char *usage)
444444
static const char *const msg[] = {
445445
"",
446446
" usage: rtla timerlat [top] [-h] [-q] [-a us] [-d s] [-D] [-n] [-p us] [-i us] [-T us] [-s us] \\",
447-
" [[-t[=file]] [-e sys[:event]] [--filter <filter>] [--trigger <trigger>] [-c cpu-list] [-H cpu-list]\\",
447+
" [[-t[file]] [-e sys[:event]] [--filter <filter>] [--trigger <trigger>] [-c cpu-list] [-H cpu-list]\\",
448448
" [-P priority] [--dma-latency us] [--aa-only us] [-C[=cgroup_name]] [-u] [--warm-up s]",
449449
"",
450450
" -h/--help: print this menu",
@@ -460,7 +460,7 @@ static void timerlat_top_usage(char *usage)
460460
" -d/--duration time[m|h|d]: duration of the session in seconds",
461461
" -D/--debug: print debug info",
462462
" --dump-tasks: prints the task running on all CPUs if stop conditions are met (depends on !--no-aa)",
463-
" -t/--trace[=file]: save the stopped trace to [file|timerlat_trace.txt]",
463+
" -t/--trace[file]: save the stopped trace to [file|timerlat_trace.txt]",
464464
" -e/--event <sys:event>: enable the <sys:event> in the trace instance, multiple -e are allowed",
465465
" --filter <command>: enable a trace event filter to the previous -e event",
466466
" --trigger <command>: enable a trace event trigger to the previous -e event",
@@ -659,9 +659,13 @@ static struct timerlat_top_params
659659
params->stop_total_us = get_llong_from_str(optarg);
660660
break;
661661
case 't':
662-
if (optarg)
663-
/* skip = */
664-
params->trace_output = &optarg[1];
662+
if (optarg) {
663+
if (optarg[0] == '=')
664+
params->trace_output = &optarg[1];
665+
else
666+
params->trace_output = &optarg[0];
667+
} else if (optind < argc && argv[optind][0] != '-')
668+
params->trace_output = argv[optind];
665669
else
666670
params->trace_output = "timerlat_trace.txt";
667671

0 commit comments

Comments
 (0)