perf mem: Standardize \'perf mem\' arg parsing
PATCH 1/1 perf mem: Standardize \'perf mem\' arg parsing
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.
PATCH 1/1 perf mem: Standardize 'perf mem' arg parsing
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.
--- tools/perf/builtin-mem.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
tools/perf/builtin-mem.c +7 -2
@@ -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);
Signature · 1 line
2.31.1