Skip to contentSkip to conversation

rtla: Fix -t/--trace[=file]

PATCH Superseded John Kacur 2 participants 2 messages May 8, 2024 – May 10, 2024 Real-time Linux Analysis (rtla) tools

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

John Kacur

author
#0 lore raw

PATCH 1/1 rtla: Fix -t/--trace[=file]

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

---
 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(-)
tools/tracing/rtla/src/osnoise_hist.c +8 -3
index 01870d50942a..8ff1c816eb6a 100644
@@ -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;
tools/tracing/rtla/src/osnoise_top.c +8 -3
index 457360db0767..c685d881daf1 100644
@@ -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;
tools/tracing/rtla/src/timerlat_hist.c +8 -3
index 8bd51aab6513..d2a639d3c02c 100644
@@ -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;
tools/tracing/rtla/src/timerlat_top.c +8 -3
index 8a3fa64319c6..e6e75937832e 100644
@@ -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";
 
Signature · 1 line
2.44.0
#1 lore raw
Quoted 11 lines · John Kacur

Normally with a short option we don't provide an equals sign like this

(quoted diff) +0 -2
-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.

Quoted 47 lines

./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

Quoted 4 lines

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