[PATCH] perf mem: Standardize 'perf mem' arg parsing

From: Brett Holman
Date: Tue Jul 20 2021 - 22:26:05 EST


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@xxxxxxxxx>
---
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