Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp4525500rwb; Mon, 8 Aug 2022 02:32:03 -0700 (PDT) X-Google-Smtp-Source: AA6agR63zYOtDJM1p0ngvabqVhrWQ+J2N7Ov5vkMGMtkruNvk6tjDvonw3tpwQJfMyOeiaiJmgh+ X-Received: by 2002:a17:907:b02:b0:731:3f2d:f09 with SMTP id h2-20020a1709070b0200b007313f2d0f09mr5560883ejl.122.1659951123081; Mon, 08 Aug 2022 02:32:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659951123; cv=none; d=google.com; s=arc-20160816; b=AtxE2mNeFmWEuJIT4g+CpKZb+na15GwpBmaSwYlb9LZfX5dkXWriGatv6DoiOzpaq2 iavZwb/XrHJZEV+k7gFcrDG2L0A0SzX+SkYsEYblLoztWnxI/kXLt435BTOxqamt6BtI AjOPGavAdp6OB4tZInKQuKLdshba2aBNLhKUuIui7UzMDtwH0JUe68i0a7t1J3Lm0O0z Ww9Mzj8/6jbkcdXfLY3jam6qZkJNO4A8KjoxP8BVC6S62ApyQRrg5HRf8+jSQTNjcP8g 5VbqLXXlAy6oYhqECaf+2UPKUGW7PFo0eYA+Pf9GRUHv6MkmXQHu5lhKsd8iFhhqEMT0 TN4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Cl5CrmoYIXZ1kvh1XsiawbO1nWhPAtefHBtsRfIU+iI=; b=A5OAqARmYxt/UkQmQWGXg4BsuwetPceqTu5b+fYzDUgd198k8I6lYm5pYJ2VBTTvPM xQUccr7nbKL5YxAYhF+jp7F+y4Q6PQvLSlW05cNjVvBTsypo0PK8r0bbDf3aixz7svkw Zu7toiroYpDMK/nCR/JFx2Vgg2irzLSxDs2KDdBSj0Xc43gy7+/iZr35ha0ElHyTDgEb LBOdx9qhwV1+uM4/fnyjMCl2bQy1WqhAFOgd+++/u9MJ3Geg52BV+TwsloT8csn7ZG2x g+37lOhXZazV0KwyTGExTRr3jdxzvliRL5nuOAX2eWateUmEc6bVRCldbafDvj46nxPV r8Hg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h23-20020a170906719700b0072fb2992103si8520095ejk.891.2022.08.08.02.31.30; Mon, 08 Aug 2022 02:32:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242354AbiHHJ1K (ORCPT + 99 others); Mon, 8 Aug 2022 05:27:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237720AbiHHJ1H (ORCPT ); Mon, 8 Aug 2022 05:27:07 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 304B713F15; Mon, 8 Aug 2022 02:27:06 -0700 (PDT) Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4M1W3b1YWPz1M8bN; Mon, 8 Aug 2022 17:23:55 +0800 (CST) Received: from kwepemm600003.china.huawei.com (7.193.23.202) by dggemv711-chm.china.huawei.com (10.1.198.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 8 Aug 2022 17:27:03 +0800 Received: from ubuntu1804.huawei.com (10.67.174.61) by kwepemm600003.china.huawei.com (7.193.23.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 8 Aug 2022 17:27:03 +0800 From: Yang Jihong To: , , , , , , , , CC: Subject: [PATCH 1/2] perf kvm: Fix subcommand matching error Date: Mon, 8 Aug 2022 17:24:07 +0800 Message-ID: <20220808092408.107399-2-yangjihong1@huawei.com> X-Mailer: git-send-email 2.30.GIT In-Reply-To: <20220808092408.107399-1-yangjihong1@huawei.com> References: <20220808092408.107399-1-yangjihong1@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.67.174.61] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemm600003.china.huawei.com (7.193.23.202) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently, diff, top, buildid-list and stat use strncmp to match subcommands. As a result, matching does not meet expectation. For example: # perf kvm diff1234 # Event 'cycles' # # Baseline Delta Abs Shared Object Symbol # ........ ......... ............. ...... # # Event 'dummy:HG' # # Baseline Delta Abs Shared Object Symbol # ........ ......... ............. ...... # # echo $? 0 # Invalid information should be returned, but success is actually returned. Solution: Use strstarts to match subcommands. After: # perf kvm diff1234 Usage: perf kvm [] {top|record|report|diff|buildid-list|stat} -i, --input Input file name -o, --output Output file name -v, --verbose be more verbose (show counter open errors, etc) --guest Collect guest os data --guest-code Guest code can be found in hypervisor process --guestkallsyms file saving guest os /proc/kallsyms --guestmodules file saving guest os /proc/modules --guestmount guest mount directory under which every guest os instance has a subdir --guestvmlinux file saving guest os vmlinux --host Collect host os data # echo $? 129 # Signed-off-by: Yang Jihong --- tools/perf/builtin-kvm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 3696ae97f149..7d9ec1bac1a2 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -1638,14 +1638,14 @@ int cmd_kvm(int argc, const char **argv) return __cmd_record(file_name, argc, argv); else if (strlen(argv[0]) > 2 && strstarts("report", argv[0])) return __cmd_report(file_name, argc, argv); - else if (!strncmp(argv[0], "diff", 4)) + else if (strlen(argv[0]) > 2 && strstarts("diff", argv[0])) return cmd_diff(argc, argv); - else if (!strncmp(argv[0], "top", 3)) + else if (!strcmp(argv[0], "top")) return cmd_top(argc, argv); - else if (!strncmp(argv[0], "buildid-list", 12)) + else if (strlen(argv[0]) > 2 && strstarts("buildid-list", argv[0])) return __cmd_buildid_list(file_name, argc, argv); #ifdef HAVE_KVM_STAT_SUPPORT - else if (!strncmp(argv[0], "stat", 4)) + else if (strlen(argv[0]) > 2 && strstarts("stat", argv[0])) return kvm_cmd_stat(file_name, argc, argv); #endif else -- 2.30.GIT