Skip to contentSkip to conversation

perf_counter: Improve perf stat and perf record option parsing

PATCH Applied Anton Blanchard 2 participants 2 messages Jul 22, 2009 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf_counter: Improve perf stat and perf record option parsing

perf stat and perf record currently look for all options on the command line. This can lead to some confusion:

# perf stat ls -l
  Error: unknown switch `l'

While we can work around this by adding '--' before the command, the git option parsing code can stop at the first non option:

# perf stat ls -l
 Performance counter stats for 'ls -l':
...

---

tools/perf/builtin-record.c +2 -1
Index: linux.trees.git/tools/perf/builtin-record.c
===================================================================
@@ -664,7 +664,8 @@ int cmd_record(int argc, const char **ar
 {
 	int counter;
 
-	argc = parse_options(argc, argv, options, record_usage, 0);
+	argc = parse_options(argc, argv, options, record_usage,
+		PARSE_OPT_STOP_AT_NON_OPTION);
 	if (!argc && target_pid == -1 && !system_wide)
 		usage_with_options(record_usage, options);
 
tools/perf/builtin-stat.c +2 -1
Index: linux.trees.git/tools/perf/builtin-stat.c
===================================================================
@@ -511,7 +511,8 @@ int cmd_stat(int argc, const char **argv
 {
 	int status;
 
-	argc = parse_options(argc, argv, options, stat_usage, 0);
+	argc = parse_options(argc, argv, options, stat_usage,
+		PARSE_OPT_STOP_AT_NON_OPTION);
 	if (!argc)
 		usage_with_options(stat_usage, options);
 	if (run_count <= 0 || run_count > MAX_RUN)
#1 lore raw
Quoted 6 lines · Anton Blanchard

perf stat and perf record currently look for all options on the command line. This can lead to some confusion:

# perf stat ls -l
  Error: unknown switch `l'
Quoted 8 lines

While we can work around this by adding '--' before the command, the git option parsing code can stop at the first non option:

# perf stat ls -l
 Performance counter stats for 'ls -l':
....

I queued it, thanks Anton.