Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf help: Lower levenshtein penality for deleting character

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>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20240301201306.2680986-2-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Ian Rogers and committed by
Arnaldo Carvalho de Melo
7aea01ea f664d515

+7 -3
+7 -3
tools/perf/util/help-unknown-cmd.c
··· 73 73 74 74 if (main_cmds->cnt) { 75 75 /* This reuses cmdname->len for similarity index */ 76 - for (i = 0; i < main_cmds->cnt; ++i) 76 + for (i = 0; i < main_cmds->cnt; ++i) { 77 77 main_cmds->names[i]->len = 78 - levenshtein(cmd, main_cmds->names[i]->name, 0, 2, 1, 4); 79 - 78 + levenshtein(cmd, main_cmds->names[i]->name, 79 + /*swap_penalty=*/0, 80 + /*substition_penality=*/2, 81 + /*insertion_penality=*/1, 82 + /*deletion_penalty=*/1); 83 + } 80 84 qsort(main_cmds->names, main_cmds->cnt, 81 85 sizeof(*main_cmds->names), levenshtein_compare); 82 86