From patchwork Fri Mar 1 20:13:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 209070 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:fa17:b0:10a:f01:a869 with SMTP id ju23csp130375dyc; Fri, 1 Mar 2024 12:13:43 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUbiFktE/Zc6E+kjDOu/mP60rXT0myiqLwAs+g9m0ucICYOe9bKbG54hwUQz5Ujd6+pQMiaYBljV1zhHTnPQ2MwLvwbsQ== X-Google-Smtp-Source: AGHT+IFBDmTlDj8AihEBNqXNObmGaovXEy/O6W3QersGxTARqxxzp3jxg14+8+ekHvtK0RzHZO8S X-Received: by 2002:a5e:8f43:0:b0:7c8:27c6:23fc with SMTP id x3-20020a5e8f43000000b007c827c623fcmr2401981iop.17.1709324023265; Fri, 01 Mar 2024 12:13:43 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709324023; cv=pass; d=google.com; s=arc-20160816; b=z7f0SqmT/9Mcbp6F4mpL7qgrB7BULDJmCROrg+lba0MJwizFzyd9I03uD0zJe8NejT 3DvYO7R/YZRx6Q/i4gQrwezMxaIVJlX/0OpkrA2STy0QUd7Ih4ZOIWdRLlwbYUAKAQNb aZZNiPkcl9PhsqIoMfZdM1QaX8BMkne0mQJbsCXZ8z8TCh9qkTx4EWx2IUpHAVhk/emX fGT0/HxB/okaNFSB9D26Xgcfs79U8H6c6OJe9dv2bl+ArP9VeHioNyiU2RYQDewUYEkF o9AAgFJrrxgOF2Lc+lfaZwhYj5qC0+uUtwoc5ulPgiyv7kqU1tvFBrgXm+1IWwy1GdL0 VYmw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:from:subject:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:message-id:date:dkim-signature; bh=Qw7Tnae9oeOOLeAJfa9C2dxnvmn7Vxe3GYTFlwpmYPw=; fh=or+NHjn0ABk96j+nlpZXQgG+EeiNZ9ZNCoM1icClqGc=; b=bw+2iVTsW/hk/ujLpxHF8weTaC9qVSSJqrw/INIMwKB6q+0euiOI4KKkg2IzyPHW1H 6sr8v7yB5K/YMLoRtpI6Ne4a3Ay2sCkF8QeMab/tiy6FtxuP6qdQyD6odrHEDImWA8Af YmkQvDHRhWAyXRIKGMKuBqCdVvIm2fsYMbFD38HjMl/ohzmt01hXqBT0bNkKOWFmB+Dh tkHprQqzmn5M1VWNHPxcrnwSmGxCaXQB7VBi9ZBtzoy8OQFdnm50CHFoLXPpcYqfUSME IK9xt3zhzJxAtDIcJ/SBN4xRwCvtGpSneQnI4SqeRf8lYR7a8ZU3fXu0GsgVP2G2z4dL ljTQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=emI3hcdx; arc=pass (i=1 spf=pass spfdomain=flex--irogers.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-89061-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-89061-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id v4-20020a63f204000000b005d7b75a5df9si4171591pgh.669.2024.03.01.12.13.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 12:13:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-89061-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=emI3hcdx; arc=pass (i=1 spf=pass spfdomain=flex--irogers.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-89061-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-89061-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 0E9A528440E for ; Fri, 1 Mar 2024 20:13:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9357C3C484; Fri, 1 Mar 2024 20:13:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="emI3hcdx" Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5531F7EC for ; Fri, 1 Mar 2024 20:13:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709324000; cv=none; b=pXBx67Rgfry5YjAEqW6HvaoSIlX0p0AsnhJwc55bl9KG8nUkAxDq4uK8q9zWCZ2vE7gidMgOf0/jzUOgcRPLUYGYRlcfoYEZNZ88lwN3ayYM59jblu4M04jQgiXS9wC84C0O3m6+lrrrCrDnpfV2yYVWENfZIm3RZuLz8Tkcmzo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709324000; c=relaxed/simple; bh=YQYej9/wbHDh4U0pOqtD+f9bdmuRw3dDIO6iC4Atlvs=; h=Date:Message-Id:Mime-Version:Subject:From:To:Content-Type; b=Vm2U3Wb2TTulrB/Bne3mj4uEyMY3Py32mBrTCvazjXCnFyZJniHUMlFVjEt31ob6qXlwEfCRR4gOga5kt9nqxMwIJd0FRdEuxtA9KurjFrqeiZTN7SZyckxb0ll2tjJXt09zkLdEJ7KjbUw2VLUe8Wsz4YeGxa6qtZqawqo8K40= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=emI3hcdx; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-60904453110so32493477b3.2 for ; Fri, 01 Mar 2024 12:13:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709323998; x=1709928798; darn=vger.kernel.org; h=to:from:subject:mime-version:message-id:date:from:to:cc:subject :date:message-id:reply-to; bh=Qw7Tnae9oeOOLeAJfa9C2dxnvmn7Vxe3GYTFlwpmYPw=; b=emI3hcdxfGFfFcTe+qzezSQNmmMt4UCOFw/SeO10Oj89o7bwAeO6AAsxHHyA5p265Q syGlZyzPDrlLe3Ig+JndNlPIkcOY2vEt0Uma5PT2oGeCVt1jaDXvlpISo/xy2CESmhT8 3OPmTqTPDvyfJMJI1WcKnMIk/R5ztuqZUVaGsjscoxO5p/olSmSqjKnquwXxcClMj6f5 3jqi9MtvSSe4qZXeMndAJKT2dOcOjFoPCqLf4s9aD93Cv69Hzgfnh+Ds5nt4jg4BPyud 6P0LTvQ2R3ho2qOBe1ceWyxWH371CB9BvgDjPDxRmnUcq0MOfGj6FCv800HrgVqy2aM5 uPJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709323998; x=1709928798; h=to:from:subject:mime-version:message-id:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=Qw7Tnae9oeOOLeAJfa9C2dxnvmn7Vxe3GYTFlwpmYPw=; b=Oa8or2UyTOcjMT3M6vewETNT+IN5MzLGpDU23+WFYUti5TNn6Q2RTAm100Ddh+kih7 2TnhdIMDzBWYEBx7O8Z1B5UAWCzPIhYxI4Tb71lGAld5XbGXlVp/vP5fIutBBJ+oei2n nJDkWR3xjtdWXUgWcM5ZMjuZ/zPNurs96eiX4WXixj1eWdkptVQLP1qXZFBmrPIxD7jV aAfhEgokfqhzFEs0n0w+t6rgwj/sue6cd2xcWKC0uj9sSk8LJOOrBuTZa1qw0QoQ0WK6 aOLJySyRVFBdulDYt74RhvJdp4WZu+b6dDKXhHMHsNSgHZL6grJHAT/hAK/BdpokOc0f 9CIg== X-Forwarded-Encrypted: i=1; AJvYcCW5LEYQViGEvFG84i2rlmnZP3K4G/dmg4579TT3TURxzvJOhX/7M5oXCtAk+F+gZQ6Q5SUb/KmpDPU4RZmuZSRhh76XZ4bIza05fb96 X-Gm-Message-State: AOJu0Yx95PE+wkajaroaDTA4E5lX0nBPX2uSwKYemtn0LUyVuMdmC+qA THTQ0TVSkniIm8CtovV6KWEWOLG/927PZ6EnPCkOBWEEybt4YFcnAOHLr3rFUXlJ+L71l9inZou RPQpP4Q== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:af4b:7fc1:b7be:fcb7]) (user=irogers job=sendgmr) by 2002:a05:690c:d21:b0:608:1b39:246b with SMTP id cn33-20020a05690c0d2100b006081b39246bmr717835ywb.3.1709323998427; Fri, 01 Mar 2024 12:13:18 -0800 (PST) Date: Fri, 1 Mar 2024 12:13:05 -0800 Message-Id: <20240301201306.2680986-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Subject: [PATCH v2 1/2] perf: Suggest inbuilt commands for unknown command From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792356146616322705 X-GMAIL-MSGID: 1792356146616322705 The existing unknown command code looks for perf scripts like perf-archive.sh and perf-iostat.sh, however, inbuilt commands aren't suggested. Add the inbuilt commands so they may be suggested too. Before: ``` $ perf reccord perf: 'reccord' is not a perf-command. See 'perf --help'. ``` After: ``` $ perf reccord perf: 'reccord' is not a perf-command. See 'perf --help'. Did you mean this? record ``` Signed-off-by: Ian Rogers --- v2. Drops a merged patch and rebases. No functional change. Arnaldo reported the patch not working for him, but I've not found a reproduction and it works for me: https://lore.kernel.org/lkml/ZZcdDyyADG8dP8LM@kernel.org/ --- tools/perf/builtin.h | 4 ++- tools/perf/perf.c | 21 +++++++++++--- tools/perf/util/help-unknown-cmd.c | 45 ++++++++++++++---------------- 3 files changed, 41 insertions(+), 29 deletions(-) diff --git a/tools/perf/builtin.h b/tools/perf/builtin.h index f2ab5bae2150..f4375deabfa3 100644 --- a/tools/perf/builtin.h +++ b/tools/perf/builtin.h @@ -2,8 +2,10 @@ #ifndef BUILTIN_H #define BUILTIN_H +struct cmdnames; + void list_common_cmds_help(void); -const char *help_unknown_cmd(const char *cmd); +const char *help_unknown_cmd(const char *cmd, struct cmdnames *main_cmds); int cmd_annotate(int argc, const char **argv); int cmd_bench(int argc, const char **argv); diff --git a/tools/perf/perf.c b/tools/perf/perf.c index 921bee0a6437..c719e6ccd9e2 100644 --- a/tools/perf/perf.c +++ b/tools/perf/perf.c @@ -18,6 +18,7 @@ #include #include "util/parse-events.h" #include +#include #include "util/debug.h" #include "util/event.h" #include "util/util.h" // usage() @@ -557,7 +558,7 @@ int main(int argc, const char **argv) pthread__block_sigwinch(); while (1) { - static int done_help; + int done_help; run_argv(&argc, &argv); @@ -565,14 +566,26 @@ int main(int argc, const char **argv) break; if (!done_help) { - cmd = argv[0] = help_unknown_cmd(cmd); + struct cmdnames main_cmds; + + for (unsigned int i = 0; i < ARRAY_SIZE(commands); i++) { + add_cmdname(&main_cmds, + commands[i].cmd, + strlen(commands[i].cmd)); + } + cmd = argv[0] = help_unknown_cmd(cmd, &main_cmds); + clean_cmdnames(&main_cmds); done_help = 1; + if (!cmd) + break; } else break; } - fprintf(stderr, "Failed to run command '%s': %s\n", - cmd, str_error_r(errno, sbuf, sizeof(sbuf))); + if (cmd) { + fprintf(stderr, "Failed to run command '%s': %s\n", + cmd, str_error_r(errno, sbuf, sizeof(sbuf))); + } out: if (debug_fp) fclose(debug_fp); diff --git a/tools/perf/util/help-unknown-cmd.c b/tools/perf/util/help-unknown-cmd.c index eab99ea6ac01..2ba3369f1620 100644 --- a/tools/perf/util/help-unknown-cmd.c +++ b/tools/perf/util/help-unknown-cmd.c @@ -52,46 +52,44 @@ static int add_cmd_list(struct cmdnames *cmds, struct cmdnames *old) return 0; } -const char *help_unknown_cmd(const char *cmd) +const char *help_unknown_cmd(const char *cmd, struct cmdnames *main_cmds) { unsigned int i, n = 0, best_similarity = 0; - struct cmdnames main_cmds, other_cmds; + struct cmdnames other_cmds; - memset(&main_cmds, 0, sizeof(main_cmds)); - memset(&other_cmds, 0, sizeof(main_cmds)); + memset(&other_cmds, 0, sizeof(other_cmds)); perf_config(perf_unknown_cmd_config, NULL); - load_command_list("perf-", &main_cmds, &other_cmds); + load_command_list("perf-", main_cmds, &other_cmds); - if (add_cmd_list(&main_cmds, &other_cmds) < 0) { + if (add_cmd_list(main_cmds, &other_cmds) < 0) { fprintf(stderr, "ERROR: Failed to allocate command list for unknown command.\n"); goto end; } - qsort(main_cmds.names, main_cmds.cnt, - sizeof(main_cmds.names), cmdname_compare); - uniq(&main_cmds); + qsort(main_cmds->names, main_cmds->cnt, + sizeof(main_cmds->names), cmdname_compare); + uniq(main_cmds); - if (main_cmds.cnt) { + if (main_cmds->cnt) { /* This reuses cmdname->len for similarity index */ - for (i = 0; i < main_cmds.cnt; ++i) - main_cmds.names[i]->len = - levenshtein(cmd, main_cmds.names[i]->name, 0, 2, 1, 4); + for (i = 0; i < main_cmds->cnt; ++i) + main_cmds->names[i]->len = + levenshtein(cmd, main_cmds->names[i]->name, 0, 2, 1, 4); - qsort(main_cmds.names, main_cmds.cnt, - sizeof(*main_cmds.names), levenshtein_compare); + qsort(main_cmds->names, main_cmds->cnt, + sizeof(*main_cmds->names), levenshtein_compare); - best_similarity = main_cmds.names[0]->len; + best_similarity = main_cmds->names[0]->len; n = 1; - while (n < main_cmds.cnt && best_similarity == main_cmds.names[n]->len) + while (n < main_cmds->cnt && best_similarity == main_cmds->names[n]->len) ++n; } if (autocorrect && n == 1) { - const char *assumed = main_cmds.names[0]->name; + const char *assumed = main_cmds->names[0]->name; - main_cmds.names[0] = NULL; - clean_cmdnames(&main_cmds); + main_cmds->names[0] = NULL; clean_cmdnames(&other_cmds); fprintf(stderr, "WARNING: You called a perf program named '%s', " "which does not exist.\n" @@ -107,15 +105,14 @@ const char *help_unknown_cmd(const char *cmd) fprintf(stderr, "perf: '%s' is not a perf-command. See 'perf --help'.\n", cmd); - if (main_cmds.cnt && best_similarity < 6) { + if (main_cmds->cnt && best_similarity < 6) { fprintf(stderr, "\nDid you mean %s?\n", n < 2 ? "this": "one of these"); for (i = 0; i < n; i++) - fprintf(stderr, "\t%s\n", main_cmds.names[i]->name); + fprintf(stderr, "\t%s\n", main_cmds->names[i]->name); } end: - clean_cmdnames(&main_cmds); clean_cmdnames(&other_cmds); - exit(1); + return NULL; } From patchwork Fri Mar 1 20:13:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 209071 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:fa17:b0:10a:f01:a869 with SMTP id ju23csp130462dyc; Fri, 1 Mar 2024 12:13:51 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXKYY4nlxVtDu+qiNC+0rlkkaBG2yh2tBvU3dXG3pyFDCp5WP3Bl7U/sOyFWOdY2I+y64LLjsf/6T+kAEVhDBs3sdQmBA== X-Google-Smtp-Source: AGHT+IGRv/6CgBsZ0oK2YI+kpbeVfOLwLIgr0jLmF6klwvJKiyEN84MQsVPMjnuF2ysSYj2gJnsp X-Received: by 2002:a05:620a:1673:b0:788:188a:37de with SMTP id d19-20020a05620a167300b00788188a37demr93156qko.62.1709324031497; Fri, 01 Mar 2024 12:13:51 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709324031; cv=pass; d=google.com; s=arc-20160816; b=g4BCeli7fldevF4/VLcLU9/KKNIfYSNNIYrFOSSTG9MsDe+aLwHjFRr3qxMRdYNwSM qie1413JNRgSbJ0mOHxSQVkClFHc8J5SjsEjRNZEQe8wcGVG9fwkstUKb0RG+o8iuV0w 06FMXfqmFMCJyLOe+OTzlYlOFqDCKiFoZ1nDHEl+wKuR4VbV1VnFjVJdwvk17c493s75 rvoQHe6JiOSx70PPsPrEvv/v3VUMqrHwuvgd29EK0SjYGTLnJTLJHHoJMSi/O4Hyc+yg tTJyZ315iMNarSviRUmpG19ROQY6UwdtjOP5v3B0U9MTXeZRPRTMEHBgiQC2CeFOi008 pNpw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:from:subject:references:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:in-reply-to:date :dkim-signature; bh=leHy2ZuaaIVqOoEaFIcU0dOPh3TtFIVXPy4dpXtCtQQ=; fh=OJHqQpgyNkKXIRyRuRdTK0WDEtuJxlqqyuFW6Jwmdic=; b=Z4yVkJ/ufNbpRy7efRuCNzyHAYDIIdVPt+u2tV3UkQbloT/vgDiOS33JuBiIm2x89b SV1GFSqFSZEfW8W+awDsrJhUULXleOJSqGVPxIZoqySkYzYDv4syOYM0TFNIqI40919s +INXR+atU13vtzfjyd8vJkwlzAFFcqfCVNr54ZxPdeYqRTDpk+SJwsCdUgws6VzCjtSo ZAslcZxg1Ci5utav3zLH51kzLUc/P8pOvQDEgVxhBiP2B1UKlUUT3aNANUayLTFe6Wip bFpY/QCE48f7euVayNo/znhTkHH/wft6vSQ+GB+DpchGaS6K8M3cCWFKMtsN3xoi/zqw 2WNA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=4uuUvcJP; arc=pass (i=1 spf=pass spfdomain=flex--irogers.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-89062-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-89062-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id a16-20020a05620a02f000b00787dea877e0si4244405qko.188.2024.03.01.12.13.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 12:13:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-89062-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=4uuUvcJP; arc=pass (i=1 spf=pass spfdomain=flex--irogers.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-89062-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-89062-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 46A391C24134 for ; Fri, 1 Mar 2024 20:13:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0518D3D0A4; Fri, 1 Mar 2024 20:13:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="4uuUvcJP" Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BA9DC3C470 for ; Fri, 1 Mar 2024 20:13:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709324003; cv=none; b=WOgB02p1OtWjW588rMP3aXBSDX9E1RXbFoQOI8hgmExgTeZySG+pjL11C0clL4LaKEdfcAw6Vkm5b/jaymtDv0QgRkT1tBjtJIWGNjS5zfPT5bseSw3iGuTs8+fvwj+YI8OPPwDvwBZjsLhF0CbPr3ZYbFjonhkhx4KFI6AWwVI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709324003; c=relaxed/simple; bh=+kXeHXthEWZD7iWx2K1wgOR5WC1VJeE1+Ab0otEfR+s=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=Q0Zwn4Q9Sxochww1gwpGJ9x2duabU2SvV32fh2HtmoYEtIFTbbWCct9kAm4FKjVnAWo4Whhu4ECscx4EdvBtK//tsgjvIBdbaoZAdYXnIOGwm7MhmUcf975qI1naNFoGCcbZDLMWQJ4rLhZJtnIkqxY2yXfLXdgNYS1ywT98kWE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=4uuUvcJP; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dc6b26783b4so3523051276.0 for ; Fri, 01 Mar 2024 12:13:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709324001; x=1709928801; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=leHy2ZuaaIVqOoEaFIcU0dOPh3TtFIVXPy4dpXtCtQQ=; b=4uuUvcJP4diR1DgxCzpfQ0oXzCEZRYp7YbVphmRn3/ubpFdYpJqYn1W031AhxHbpU9 HgFOCH1qHJDvMyrosnPmJKgZsrgZvAq6FPVcREKlLKFUJzb0a/iOVpskNZ8ZpK2xnFVd /bU6HPEQXgeyA0C6zMMP3mFlVqvmzhm5EgmTuXjPS977SvRKtiSu/fO2B+YXCJe/6WHM f7MNR+5LpRoGXjJgupuo+vIrzEukBZVmK/r2wTw4kd9KXr3jPlmkqUQNQEyifLrJ0ZG3 WL7LUzU3TnWNEl8qiYlkdn+qDSKz8dwtCtuerR/aIeul1vkW/Dfnbdgqvz2EBjU21sem F80Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709324001; x=1709928801; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=leHy2ZuaaIVqOoEaFIcU0dOPh3TtFIVXPy4dpXtCtQQ=; b=f054WW925USVO45b50Z+IHPb8WW3YsPV9jchDubQRUrgjCfN8RlYKa0vjEijX1Ptsc q9ckqRNCzRAwmtSx7ypFhaqyl2ETOvKPfabERKTImnhgAVVJjsFpWZ0NRdiayEa5cN+I rYGz+ce52ySnzFdKqOo3XNouOXGmzdJF2Ud207jyanTh9zDVLzGwtihapYVwRyc1kRoC gtCX3XRr22tDDXk5QaqJCyDxCEE6A7whe0mJ2IWLhX8LIFBediM0JSmEotpZRLM4F2Wg XzrEw5MgshftidqZ3FDRHZ1USJXdCZs6/nqFdLT2m+zO0JFgBq8WyHmMSuqgpVo6oiJp 3YXg== X-Forwarded-Encrypted: i=1; AJvYcCXx5HNrCzJ7c4m6LpXMADhF80+OSoV1kJJpKFCXAlWMgZXCmEveEZKFGc9S5VdrEGP6GneXqPEUWWlsvktir7Rp5AfY1p5GGrSqwLlv X-Gm-Message-State: AOJu0Yx3quOV+NrjgVECxtVCxxdovddW1nYR8fYWL5q3bf2DoUjSjGqI wh8TcSNToBo4IzLJJ7pDteUrlxQUklrpERzrSV39MKAnA1bJGGd9bq4frRnR/0qQHoIvuarrkLu 8y9P59Q== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:af4b:7fc1:b7be:fcb7]) (user=irogers job=sendgmr) by 2002:a25:ce8a:0:b0:dcc:8927:7496 with SMTP id x132-20020a25ce8a000000b00dcc89277496mr102198ybe.5.1709324000837; Fri, 01 Mar 2024 12:13:20 -0800 (PST) Date: Fri, 1 Mar 2024 12:13:06 -0800 In-Reply-To: <20240301201306.2680986-1-irogers@google.com> Message-Id: <20240301201306.2680986-2-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240301201306.2680986-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Subject: [PATCH v2 2/2] perf help: Lower levenshtein penality for deleting character From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792356155446967330 X-GMAIL-MSGID: 1792356155446967330 The levenshtein penalty for deleting a character was far higher than subsituting or inserting a character. Lower the penalty to match that of inserting a character. Before: ``` $ perf recccord perf: 'recccord' is not a perf-command. See 'perf --help'. ``` After: ``` $ perf recccord perf: 'recccord' is not a perf-command. See 'perf --help'. Did you mean this? record ``` Signed-off-by: Ian Rogers --- tools/perf/util/help-unknown-cmd.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/help-unknown-cmd.c b/tools/perf/util/help-unknown-cmd.c index 2ba3369f1620..a0a46e34f8d1 100644 --- a/tools/perf/util/help-unknown-cmd.c +++ b/tools/perf/util/help-unknown-cmd.c @@ -73,10 +73,14 @@ const char *help_unknown_cmd(const char *cmd, struct cmdnames *main_cmds) if (main_cmds->cnt) { /* This reuses cmdname->len for similarity index */ - for (i = 0; i < main_cmds->cnt; ++i) + for (i = 0; i < main_cmds->cnt; ++i) { main_cmds->names[i]->len = - levenshtein(cmd, main_cmds->names[i]->name, 0, 2, 1, 4); - + levenshtein(cmd, main_cmds->names[i]->name, + /*swap_penalty=*/0, + /*substition_penality=*/2, + /*insertion_penality=*/1, + /*deletion_penalty=*/1); + } qsort(main_cmds->names, main_cmds->cnt, sizeof(*main_cmds->names), levenshtein_compare);