Normally with a short option we don't provide an equals sign like this
-tfile.txt
-t file.txt
But we do provide an equals sign with the long option like this
--trace=file.txt
Also, a good parser should work with a space instead of an equals sign
--trace file.txt
Most of these are broken!
/rtla timerlat hist -P f:95 -u -c0-11 -E3500 -T50 -tfile.txt
Saving trace to ile.txt
File name truncated
/rtla timerlat hist -P f:95 -u -c0-11 -E3500 -T50 -t file.txt
Saving trace to timerlat_trace.txt
Default file name used instead of the requested one.
/rtla timerlat hist -P f:95 -u -c0-11 -E3500 -T50 -t=file.txt
Saving trace to file.txt
This works, but people normally don't use '=' with a short option
/rtla timerlat hist -P f:95 -u -c0-11 -E3500 -T50 --trace=file.txt
Saving trace to ile.txt
File name truncated
/rtla timerlat hist -P f:95 -u -c0-11 -E3500 -T50 --trace file.txt
timerlat_trace.txt
Default file name used instead of the requested one.
After the fix
/rtla timerlat hist -P f:95 -u -c0-11 -E3500 -T50 -tfile.txt
Saving trace to file.txt
/rtla timerlat hist -P f:95 -u -c0-11 -E3500 -T50 -t file.txt
Saving trace to file.txt
/rtla timerlat hist -P f:95 -u -c0-11 -E3500 -T50 -t=file.txt
Saving trace to file.txt
/rtla timerlat hist -P f:95 -u -c0-11 -E3500 -T50 --trace=file.txt
Saving trace to file.txt
/rtla timerlat hist -P f:95 -u -c0-11 -E3500 -T50 --trace file.txt
Saving trace to file.txt
I also tested -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 -P f:95 -u -c0-11 -E3500 -T50 -t -u
/rtla timerlat hist -P f:95 -u -c0-11 -E3500 -T50 --trace -u
/rtla timerlat hist -P f:95 -u -c0-11 -E3500 -T50 -t
/rtla timerlat hist -P f:95 -u -c0-11 -E3500 -T50 --trace
And all correctly do Saving trace to timerlat_trace.txt as expected
This fix is applied to both timerlat top and hist
and to osnoise top and hist
Signed-off-by: John Kacur <[email protected]>
---
tools/tracing/rtla/src/osnoise_hist.c | 11 ++++++++---
tools/tracing/rtla/src/osnoise_top.c | 11 ++++++++---
tools/tracing/rtla/src/timerlat_hist.c | 11 ++++++++---
tools/tracing/rtla/src/timerlat_top.c | 11 ++++++++---
4 files changed, 32 insertions(+), 12 deletions(-)
diff --git a/tools/tracing/rtla/src/osnoise_hist.c b/tools/tracing/rtla/src/osnoise_hist.c
index 01870d50942a..8ff1c816eb6a 100644
--- a/tools/tracing/rtla/src/osnoise_hist.c
+++ b/tools/tracing/rtla/src/osnoise_hist.c
@@ -640,9 +640,14 @@ static struct osnoise_hist_params
params->threshold = get_llong_from_str(optarg);
break;
case 't':
- if (optarg)
- /* skip = */
- params->trace_output = &optarg[1];
+ if (optarg) {
+ if (optarg[0] == '=')
+ params->trace_output = &optarg[1];
+ else
+ params->trace_output = &optarg[0];
+ }
+ else if (optind < argc && argv[optind][0] != '0')
+ params->trace_output = argv[optind];
else
params->trace_output = "osnoise_trace.txt";
break;
diff --git a/tools/tracing/rtla/src/osnoise_top.c b/tools/tracing/rtla/src/osnoise_top.c
index 457360db0767..c685d881daf1 100644
--- a/tools/tracing/rtla/src/osnoise_top.c
+++ b/tools/tracing/rtla/src/osnoise_top.c
@@ -480,9 +480,14 @@ struct osnoise_top_params *osnoise_top_parse_args(int argc, char **argv)
params->stop_total_us = get_llong_from_str(optarg);
break;
case 't':
- if (optarg)
- /* skip = */
- params->trace_output = &optarg[1];
+ if (optarg){
+ if (optarg[0] == '=')
+ params->trace_output = &optarg[1];
+ else
+ params->trace_output = &optarg[0];
+ }
+ else if (optind < argc && argv[optind][0] != '-')
+ params->trace_output = argv[optind];
else
params->trace_output = "osnoise_trace.txt";
break;
diff --git a/tools/tracing/rtla/src/timerlat_hist.c b/tools/tracing/rtla/src/timerlat_hist.c
index 8bd51aab6513..d2a639d3c02c 100644
--- a/tools/tracing/rtla/src/timerlat_hist.c
+++ b/tools/tracing/rtla/src/timerlat_hist.c
@@ -720,9 +720,14 @@ static struct timerlat_hist_params
params->stop_total_us = get_llong_from_str(optarg);
break;
case 't':
- if (optarg)
- /* skip = */
- params->trace_output = &optarg[1];
+ if (optarg) {
+ if (optarg[0] == '=')
+ params->trace_output = &optarg[1];
+ else
+ params->trace_output = &optarg[0];
+ }
+ else if (optind < argc && argv[optind][0] != '-')
+ params->trace_output = argv[optind];
else
params->trace_output = "timerlat_trace.txt";
break;
diff --git a/tools/tracing/rtla/src/timerlat_top.c b/tools/tracing/rtla/src/timerlat_top.c
index 8a3fa64319c6..e6e75937832e 100644
--- a/tools/tracing/rtla/src/timerlat_top.c
+++ b/tools/tracing/rtla/src/timerlat_top.c
@@ -547,9 +547,14 @@ static struct timerlat_top_params
params->stop_total_us = get_llong_from_str(optarg);
break;
case 't':
- if (optarg)
- /* skip = */
- params->trace_output = &optarg[1];
+ if (optarg) {
+ if (optarg[0] == '=')
+ params->trace_output = &optarg[1];
+ else
+ params->trace_output = &optarg[0];
+ }
+ else if (optind < argc && argv[optind][0] != '-')
+ params->trace_output = argv[optind];
else
params->trace_output = "timerlat_trace.txt";
--
2.44.0
On 5/8/24 23:21, John Kacur wrote:
> Normally with a short option we don't provide an equals sign like this
> -tfile.txt
> -t file.txt
>
> But we do provide an equals sign with the long option like this
> --trace=file.txt
>
> Also, a good parser should work with a space instead of an equals sign
> --trace file.txt
>
> Most of these are broken!
So, it is set to work _only_ with =file. It would be better to have
it more robust... yes.
> ./rtla timerlat hist -P f:95 -u -c0-11 -E3500 -T50 -tfile.txt
> Saving trace to ile.txt
> File name truncated
>
> ./rtla timerlat hist -P f:95 -u -c0-11 -E3500 -T50 -t file.txt
> Saving trace to timerlat_trace.txt
> Default file name used instead of the requested one.
>
> ./rtla timerlat hist -P f:95 -u -c0-11 -E3500 -T50 -t=file.txt
> Saving trace to file.txt
> This works, but people normally don't use '=' with a short option
>
> /rtla timerlat hist -P f:95 -u -c0-11 -E3500 -T50 --trace=file.txt
> Saving trace to ile.txt
> File name truncated
>
> ./rtla timerlat hist -P f:95 -u -c0-11 -E3500 -T50 --trace file.txt
> timerlat_trace.txt
> Default file name used instead of the requested one.
>
> After the fix
>
> ./rtla timerlat hist -P f:95 -u -c0-11 -E3500 -T50 -tfile.txt
> Saving trace to file.txt
>
> ./rtla timerlat hist -P f:95 -u -c0-11 -E3500 -T50 -t file.txt
> Saving trace to file.txt
>
> ./rtla timerlat hist -P f:95 -u -c0-11 -E3500 -T50 -t=file.txt
> Saving trace to file.txt
>
> ./rtla timerlat hist -P f:95 -u -c0-11 -E3500 -T50 --trace=file.txt
> Saving trace to file.txt
>
> ./rtla timerlat hist -P f:95 -u -c0-11 -E3500 -T50 --trace file.txt
> Saving trace to file.txt
>
> I also tested -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 -P f:95 -u -c0-11 -E3500 -T50 -t -u
> ./rtla timerlat hist -P f:95 -u -c0-11 -E3500 -T50 --trace -u
> ./rtla timerlat hist -P f:95 -u -c0-11 -E3500 -T50 -t
> ./rtla timerlat hist -P f:95 -u -c0-11 -E3500 -T50 --trace
>
> And all correctly do Saving trace to timerlat_trace.txt as expected
>
> This fix is applied to both timerlat top and hist
> and to osnoise top and hist.
Ok, code wise it is fine. But it is still missing the changes for the --help
messages and man pages. Would you mind addressing them?
For instance, removing the need for the =...
s/
-t/--trace[=file]: save the stopped trace to [file|timerlat_trace.txt]
/
-t/--trace [file]: save the stopped trace to [file|timerlat_trace.txt]
/
Also, for the man page we will have to move the -t option from common_options.rst
to common_timerlat_options.rst and common_osnoise_options.rst to fix this in
man rtla-timerlat-top:
-t, --trace[=file]
Save the stopped trace to [file|osnoise_trace.txt].
(it is pointing to the wrong file)
Thanks!
-- Daniel