From: Ian Rogers <irogers@google.com>
To: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>, Namhyung Kim <namhyung@kernel.org>,
Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
Chenyuan Mi <cymi20@fudan.edu.cn>,
linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org
Subject: [PATCH v1 3/3] perf help: Lower levenshtein penality for deleting character
Date: Thu, 7 Dec 2023 16:05:15 -0800 [thread overview]
Message-ID: <20231208000515.1693746-3-irogers@google.com> (raw)
In-Reply-To: <20231208000515.1693746-1-irogers@google.com>
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 <irogers@google.com>
---
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);
--
2.43.0.472.g3155946c3a-goog
next prev parent reply other threads:[~2023-12-08 0:05 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-08 0:05 [PATCH v1 1/3] lib subcmd: Fix memory leak in uniq Ian Rogers
2023-12-08 0:05 ` [PATCH v1 2/3] perf: Suggest inbuilt commands for unknown command Ian Rogers
2023-12-08 0:05 ` Ian Rogers [this message]
2024-01-02 19:30 ` [PATCH v1 1/3] lib subcmd: Fix memory leak in uniq Ian Rogers
2024-01-04 17:56 ` Ian Rogers
2024-01-04 21:03 ` Arnaldo Carvalho de Melo
2024-01-04 23:29 ` Ian Rogers
2024-01-05 14:53 ` Arnaldo Carvalho de Melo
2024-01-06 5:44 ` Ian Rogers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231208000515.1693746-3-irogers@google.com \
--to=irogers@google.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=cymi20@fudan.edu.cn \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).