linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] perf mem: Standardize \'perf mem\' arg parsing
@ 2021-07-21  2:24 Brett Holman
  2021-07-21  2:24 ` [PATCH] perf mem: Standardize 'perf mem' " Brett Holman
  0 siblings, 1 reply; 2+ messages in thread
From: Brett Holman @ 2021-07-21  2:24 UTC (permalink / raw)
  Cc: linux-perf-users, Peter Zijlstra, Ingo Molnar,
	Arnaldo Carvalho de Melo, Mark Rutland, Alexander Shishkin,
	Jiri Olsa, Namhyung Kim, linux-kernel

This is my first time contributing here, please let me know if I
missed anything.

To compare the commands tested, use the following:

strace -f ./perf     record foo -pv bar 2>&1 | grep -a execve
strace -f ./perf mem record foo -pv bar 2>&1 | grep -a execve

Before this patch, note that '-pv' is stripped out of the command under
test for 'perf mem record', but not for 'perf record'. This patch makes
the behaviors match.



^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH] perf mem: Standardize 'perf mem' arg parsing
  2021-07-21  2:24 [PATCH] perf mem: Standardize \'perf mem\' arg parsing Brett Holman
@ 2021-07-21  2:24 ` Brett Holman
  0 siblings, 0 replies; 2+ messages in thread
From: Brett Holman @ 2021-07-21  2:24 UTC (permalink / raw)
  Cc: linux-perf-users, Brett Holman, Peter Zijlstra, Ingo Molnar,
	Arnaldo Carvalho de Melo, Mark Rutland, Alexander Shishkin,
	Jiri Olsa, Namhyung Kim, linux-kernel

Arguments are parsed differently by 'perf record' and 'perf mem
record'. While '--' can be used to stop parsing arguments in both,
'perf record' stops parsing when an unknown argument is found and 'perf
mem record' does not. This may lead to surprise when flags are stripped
from the command being tested with 'perf mem record'. This patch
eliminates this difference in behavior.

Signed-off-by: Brett Holman <bholman.devel@gmail.com>
---
 tools/perf/builtin-mem.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/tools/perf/builtin-mem.c b/tools/perf/builtin-mem.c
index 0fd2a74dbaca..ce734774b552 100644
--- a/tools/perf/builtin-mem.c
+++ b/tools/perf/builtin-mem.c
@@ -89,7 +89,7 @@ static int __cmd_record(int argc, const char **argv, struct perf_mem *mem)
 	}
 
 	argc = parse_options(argc, argv, options, record_mem_usage,
-			     PARSE_OPT_KEEP_UNKNOWN);
+			     PARSE_OPT_STOP_AT_NON_OPTION);
 
 	if (!perf_pmu__has_hybrid())
 		rec_argc = argc + 9; /* max number of arguments */
@@ -484,9 +484,14 @@ int cmd_mem(int argc, const char **argv)
 		NULL
 	};
 
-	argc = parse_options_subcommand(argc, argv, mem_options, mem_subcommands,
+	if (!strncmp(argv[1], "rec", 3))
+		argc = parse_options_subcommand(argc, argv, mem_options, mem_subcommands,
+					mem_usage, PARSE_OPT_STOP_AT_NON_OPTION);
+	else
+		argc = parse_options_subcommand(argc, argv, mem_options, mem_subcommands,
 					mem_usage, PARSE_OPT_KEEP_UNKNOWN);
 
+
 	if (!argc || !(strncmp(argv[0], "rec", 3) || mem.operation))
 		usage_with_options(mem_usage, mem_options);
 
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-07-21  2:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-21  2:24 [PATCH] perf mem: Standardize \'perf mem\' arg parsing Brett Holman
2021-07-21  2:24 ` [PATCH] perf mem: Standardize 'perf mem' " Brett Holman

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