linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: John Kacur <jkacur@redhat.com>
To: Daniel Bristot de Oliveria <bristot@kernel.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	lkml <linux-kernel@vger.kernel.org>,
	linux-trace-devel@vger.kernel.org
Cc: John Kacur <jkacur@redhat.com>
Subject: [PATCH] rtla: Fix -t/--trace[=file]
Date: Wed,  8 May 2024 17:21:55 -0400	[thread overview]
Message-ID: <20240508212155.71946-1-jkacur@redhat.com> (raw)

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 <jkacur@redhat.com>
---
 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


             reply	other threads:[~2024-05-08 21:22 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-08 21:21 John Kacur [this message]
2024-05-10  8:10 ` [PATCH] rtla: Fix -t/--trace[=file] Daniel Bristot de Oliveira

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240508212155.71946-1-jkacur@redhat.com \
    --to=jkacur@redhat.com \
    --cc=bristot@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).