Skip to content

Commit 842fc5b

Browse files
John KacurDaniel Bristot de Oliveira
authored andcommitted
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>
1 parent 01b05fc commit 842fc5b

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
@@ -437,7 +437,7 @@ static void osnoise_hist_usage(char *usage)
437437
static const char * const msg[] = {
438438
"",
439439
" usage: rtla osnoise hist [-h] [-D] [-d s] [-a us] [-p us] [-r us] [-s us] [-S us] \\",
440-
" [-T us] [-t[=file]] [-e sys[:event]] [--filter <filter>] [--trigger <trigger>] \\",
440+
" [-T us] [-t[file]] [-e sys[:event]] [--filter <filter>] [--trigger <trigger>] \\",
441441
" [-c cpu-list] [-H cpu-list] [-P priority] [-b N] [-E N] [--no-header] [--no-summary] \\",
442442
" [--no-index] [--with-zeros] [-C[=cgroup_name]] [--warm-up]",
443443
"",
@@ -453,7 +453,7 @@ static void osnoise_hist_usage(char *usage)
453453
" -C/--cgroup[=cgroup_name]: set cgroup, if no cgroup_name is passed, the rtla's cgroup will be inherited",
454454
" -d/--duration time[s|m|h|d]: duration of the session",
455455
" -D/--debug: print debug info",
456-
" -t/--trace[=file]: save the stopped trace to [file|osnoise_trace.txt]",
456+
" -t/--trace[file]: save the stopped trace to [file|osnoise_trace.txt]",
457457
" -e/--event <sys:event>: enable the <sys:event> in the trace instance, multiple -e are allowed",
458458
" --filter <filter>: enable a trace event filter to the previous -e event",
459459
" --trigger <trigger>: enable a trace event trigger to the previous -e event",
@@ -645,9 +645,13 @@ static struct osnoise_hist_params
645645
params->threshold = get_llong_from_str(optarg);
646646
break;
647647
case 't':
648-
if (optarg)
649-
/* skip = */
650-
params->trace_output = &optarg[1];
648+
if (optarg) {
649+
if (optarg[0] == '=')
650+
params->trace_output = &optarg[1];
651+
else
652+
params->trace_output = &optarg[0];
653+
} else if (optind < argc && argv[optind][0] != '0')
654+
params->trace_output = argv[optind];
651655
else
652656
params->trace_output = "osnoise_trace.txt";
653657
break;

tools/tracing/rtla/src/osnoise_top.c

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

284284
static const char * const msg[] = {
285285
" [-h] [-q] [-D] [-d s] [-a us] [-p us] [-r us] [-s us] [-S us] \\",
286-
" [-T us] [-t[=file]] [-e sys[:event]] [--filter <filter>] [--trigger <trigger>] \\",
286+
" [-T us] [-t[file]] [-e sys[:event]] [--filter <filter>] [--trigger <trigger>] \\",
287287
" [-c cpu-list] [-H cpu-list] [-P priority] [-C[=cgroup_name]] [--warm-up s]",
288288
"",
289289
" -h/--help: print this menu",
@@ -298,7 +298,7 @@ static void osnoise_top_usage(struct osnoise_top_params *params, char *usage)
298298
" -C/--cgroup[=cgroup_name]: set cgroup, if no cgroup_name is passed, the rtla's cgroup will be inherited",
299299
" -d/--duration time[s|m|h|d]: duration of the session",
300300
" -D/--debug: print debug info",
301-
" -t/--trace[=file]: save the stopped trace to [file|osnoise_trace.txt]",
301+
" -t/--trace[file]: save the stopped trace to [file|osnoise_trace.txt]",
302302
" -e/--event <sys:event>: enable the <sys:event> in the trace instance, multiple -e are allowed",
303303
" --filter <filter>: enable a trace event filter to the previous -e event",
304304
" --trigger <trigger>: enable a trace event trigger to the previous -e event",
@@ -486,9 +486,13 @@ struct osnoise_top_params *osnoise_top_parse_args(int argc, char **argv)
486486
params->stop_total_us = get_llong_from_str(optarg);
487487
break;
488488
case 't':
489-
if (optarg)
490-
/* skip = */
491-
params->trace_output = &optarg[1];
489+
if (optarg) {
490+
if (optarg[0] == '=')
491+
params->trace_output = &optarg[1];
492+
else
493+
params->trace_output = &optarg[0];
494+
} else if (optind < argc && argv[optind][0] != '-')
495+
params->trace_output = argv[optind];
492496
else
493497
params->trace_output = "osnoise_trace.txt";
494498
break;

tools/tracing/rtla/src/timerlat_hist.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ static void timerlat_hist_usage(char *usage)
652652
char *msg[] = {
653653
"",
654654
" usage: [rtla] timerlat hist [-h] [-q] [-d s] [-D] [-n] [-a us] [-p us] [-i us] [-T us] [-s us] \\",
655-
" [-t[=file]] [-e sys[:event]] [--filter <filter>] [--trigger <trigger>] [-c cpu-list] [-H cpu-list]\\",
655+
" [-t[file]] [-e sys[:event]] [--filter <filter>] [--trigger <trigger>] [-c cpu-list] [-H cpu-list]\\",
656656
" [-P priority] [-E N] [-b N] [--no-irq] [--no-thread] [--no-header] [--no-summary] \\",
657657
" [--no-index] [--with-zeros] [--dma-latency us] [-C[=cgroup_name]] [--no-aa] [--dump-task] [-u|-k]",
658658
" [--warm-up s]",
@@ -669,7 +669,7 @@ static void timerlat_hist_usage(char *usage)
669669
" -d/--duration time[m|h|d]: duration of the session in seconds",
670670
" --dump-tasks: prints the task running on all CPUs if stop conditions are met (depends on !--no-aa)",
671671
" -D/--debug: print debug info",
672-
" -t/--trace[=file]: save the stopped trace to [file|timerlat_trace.txt]",
672+
" -t/--trace[file]: save the stopped trace to [file|timerlat_trace.txt]",
673673
" -e/--event <sys:event>: enable the <sys:event> in the trace instance, multiple -e are allowed",
674674
" --filter <filter>: enable a trace event filter to the previous -e event",
675675
" --trigger <trigger>: enable a trace event trigger to the previous -e event",
@@ -885,9 +885,13 @@ static struct timerlat_hist_params
885885
params->stop_total_us = get_llong_from_str(optarg);
886886
break;
887887
case 't':
888-
if (optarg)
889-
/* skip = */
890-
params->trace_output = &optarg[1];
888+
if (optarg) {
889+
if (optarg[0] == '=')
890+
params->trace_output = &optarg[1];
891+
else
892+
params->trace_output = &optarg[0];
893+
} else if (optind < argc && argv[optind][0] != '-')
894+
params->trace_output = argv[optind];
891895
else
892896
params->trace_output = "timerlat_trace.txt";
893897
break;

tools/tracing/rtla/src/timerlat_top.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ static void timerlat_top_usage(char *usage)
446446
static const char *const msg[] = {
447447
"",
448448
" usage: rtla timerlat [top] [-h] [-q] [-a us] [-d s] [-D] [-n] [-p us] [-i us] [-T us] [-s us] \\",
449-
" [[-t[=file]] [-e sys[:event]] [--filter <filter>] [--trigger <trigger>] [-c cpu-list] [-H cpu-list]\\",
449+
" [[-t[file]] [-e sys[:event]] [--filter <filter>] [--trigger <trigger>] [-c cpu-list] [-H cpu-list]\\",
450450
" [-P priority] [--dma-latency us] [--aa-only us] [-C[=cgroup_name]] [-u|-k] [--warm-up s]",
451451
"",
452452
" -h/--help: print this menu",
@@ -462,7 +462,7 @@ static void timerlat_top_usage(char *usage)
462462
" -d/--duration time[m|h|d]: duration of the session in seconds",
463463
" -D/--debug: print debug info",
464464
" --dump-tasks: prints the task running on all CPUs if stop conditions are met (depends on !--no-aa)",
465-
" -t/--trace[=file]: save the stopped trace to [file|timerlat_trace.txt]",
465+
" -t/--trace[file]: save the stopped trace to [file|timerlat_trace.txt]",
466466
" -e/--event <sys:event>: enable the <sys:event> in the trace instance, multiple -e are allowed",
467467
" --filter <command>: enable a trace event filter to the previous -e event",
468468
" --trigger <command>: enable a trace event trigger to the previous -e event",
@@ -668,9 +668,13 @@ static struct timerlat_top_params
668668
params->stop_total_us = get_llong_from_str(optarg);
669669
break;
670670
case 't':
671-
if (optarg)
672-
/* skip = */
673-
params->trace_output = &optarg[1];
671+
if (optarg) {
672+
if (optarg[0] == '=')
673+
params->trace_output = &optarg[1];
674+
else
675+
params->trace_output = &optarg[0];
676+
} else if (optind < argc && argv[optind][0] != '-')
677+
params->trace_output = argv[optind];
674678
else
675679
params->trace_output = "timerlat_trace.txt";
676680

0 commit comments

Comments
 (0)