[PATCH 2/2] perf sched latency: Fix subcommand matching error

From: Yang Jihong
Date: Mon Aug 08 2022 - 05:27:17 EST


perf sched latency use strncmp to match subcommands which matching does not
meet expectation.

Before:

# perf sched lat1234 >/dev/null
# echo $?
0
#

Solution: Use strstarts to match subcommand.

After:

# perf sched lat1234

Usage: perf sched [<options>] {record|latency|map|replay|script|timehist}

-D, --dump-raw-trace dump raw trace in ASCII
-f, --force don't complain, do it
-i, --input <file> input file name
-v, --verbose be more verbose (show symbol address, etc)

# echo $?
129
#
# perf sched lat >/dev/null
# echo $?
0
#

Signed-off-by: Yang Jihong <yangjihong1@xxxxxxxxxx>
---
tools/perf/builtin-sched.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 646bd938927a..2f6cd1b8b662 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -3563,7 +3563,7 @@ int cmd_sched(int argc, const char **argv)

if (strlen(argv[0]) > 2 && strstarts("record", argv[0])) {
return __cmd_record(argc, argv);
- } else if (!strncmp(argv[0], "lat", 3)) {
+ } else if (strlen(argv[0]) > 2 && strstarts("latency", argv[0])) {
sched.tp_handler = &lat_ops;
if (argc > 1) {
argc = parse_options(argc, argv, latency_options, latency_usage, 0);
--
2.30.GIT