diff options
| -rw-r--r-- | tools/perf/builtin-help.c | 13 | ||||
| -rw-r--r-- | tools/perf/perf.c | 97 | ||||
| -rw-r--r-- | tools/perf/util/Build | 1 | ||||
| -rw-r--r-- | tools/perf/util/alias.c | 78 | ||||
| -rw-r--r-- | tools/perf/util/cache.h | 1 | ||||
| -rw-r--r-- | tools/perf/util/help-unknown-cmd.c | 8 |
6 files changed, 8 insertions, 190 deletions
diff --git a/tools/perf/builtin-help.c b/tools/perf/builtin-help.c index 7ae238929e95..1eec96a0fa67 100644 --- a/tools/perf/builtin-help.c +++ b/tools/perf/builtin-help.c | |||
| @@ -301,12 +301,6 @@ void list_common_cmds_help(void) | |||
| 301 | } | 301 | } |
| 302 | } | 302 | } |
| 303 | 303 | ||
| 304 | static int is_perf_command(const char *s) | ||
| 305 | { | ||
| 306 | return is_in_cmdlist(&main_cmds, s) || | ||
| 307 | is_in_cmdlist(&other_cmds, s); | ||
| 308 | } | ||
| 309 | |||
| 310 | static const char *cmd_to_page(const char *perf_cmd) | 304 | static const char *cmd_to_page(const char *perf_cmd) |
| 311 | { | 305 | { |
| 312 | char *s; | 306 | char *s; |
| @@ -446,7 +440,6 @@ int cmd_help(int argc, const char **argv) | |||
| 446 | "perf help [--all] [--man|--web|--info] [command]", | 440 | "perf help [--all] [--man|--web|--info] [command]", |
| 447 | NULL | 441 | NULL |
| 448 | }; | 442 | }; |
| 449 | const char *alias; | ||
| 450 | int rc; | 443 | int rc; |
| 451 | 444 | ||
| 452 | load_command_list("perf-", &main_cmds, &other_cmds); | 445 | load_command_list("perf-", &main_cmds, &other_cmds); |
| @@ -472,12 +465,6 @@ int cmd_help(int argc, const char **argv) | |||
| 472 | return 0; | 465 | return 0; |
| 473 | } | 466 | } |
| 474 | 467 | ||
| 475 | alias = alias_lookup(argv[0]); | ||
| 476 | if (alias && !is_perf_command(argv[0])) { | ||
| 477 | printf("`perf %s' is aliased to `%s'\n", argv[0], alias); | ||
| 478 | return 0; | ||
| 479 | } | ||
| 480 | |||
| 481 | switch (help_format) { | 468 | switch (help_format) { |
| 482 | case HELP_FORMAT_MAN: | 469 | case HELP_FORMAT_MAN: |
| 483 | rc = show_man_page(argv[0]); | 470 | rc = show_man_page(argv[0]); |
diff --git a/tools/perf/perf.c b/tools/perf/perf.c index 4b283d18e158..9217f2227f3d 100644 --- a/tools/perf/perf.c +++ b/tools/perf/perf.c | |||
| @@ -267,71 +267,6 @@ static int handle_options(const char ***argv, int *argc, int *envchanged) | |||
| 267 | return handled; | 267 | return handled; |
| 268 | } | 268 | } |
| 269 | 269 | ||
| 270 | static int handle_alias(int *argcp, const char ***argv) | ||
| 271 | { | ||
| 272 | int envchanged = 0, ret = 0, saved_errno = errno; | ||
| 273 | int count, option_count; | ||
| 274 | const char **new_argv; | ||
| 275 | const char *alias_command; | ||
| 276 | char *alias_string; | ||
| 277 | |||
| 278 | alias_command = (*argv)[0]; | ||
| 279 | alias_string = alias_lookup(alias_command); | ||
| 280 | if (alias_string) { | ||
| 281 | if (alias_string[0] == '!') { | ||
| 282 | if (*argcp > 1) { | ||
| 283 | struct strbuf buf; | ||
| 284 | |||
| 285 | if (strbuf_init(&buf, PATH_MAX) < 0 || | ||
| 286 | strbuf_addstr(&buf, alias_string) < 0 || | ||
| 287 | sq_quote_argv(&buf, (*argv) + 1, | ||
| 288 | PATH_MAX) < 0) | ||
| 289 | die("Failed to allocate memory."); | ||
| 290 | free(alias_string); | ||
| 291 | alias_string = buf.buf; | ||
| 292 | } | ||
| 293 | ret = system(alias_string + 1); | ||
| 294 | if (ret >= 0 && WIFEXITED(ret) && | ||
| 295 | WEXITSTATUS(ret) != 127) | ||
| 296 | exit(WEXITSTATUS(ret)); | ||
| 297 | die("Failed to run '%s' when expanding alias '%s'", | ||
| 298 | alias_string + 1, alias_command); | ||
| 299 | } | ||
| 300 | count = split_cmdline(alias_string, &new_argv); | ||
| 301 | if (count < 0) | ||
| 302 | die("Bad alias.%s string", alias_command); | ||
| 303 | option_count = handle_options(&new_argv, &count, &envchanged); | ||
| 304 | if (envchanged) | ||
| 305 | die("alias '%s' changes environment variables\n" | ||
| 306 | "You can use '!perf' in the alias to do this.", | ||
| 307 | alias_command); | ||
| 308 | memmove(new_argv - option_count, new_argv, | ||
| 309 | count * sizeof(char *)); | ||
| 310 | new_argv -= option_count; | ||
| 311 | |||
| 312 | if (count < 1) | ||
| 313 | die("empty alias for %s", alias_command); | ||
| 314 | |||
| 315 | if (!strcmp(alias_command, new_argv[0])) | ||
| 316 | die("recursive alias: %s", alias_command); | ||
| 317 | |||
| 318 | new_argv = realloc(new_argv, sizeof(char *) * | ||
| 319 | (count + *argcp + 1)); | ||
| 320 | /* insert after command name */ | ||
| 321 | memcpy(new_argv + count, *argv + 1, sizeof(char *) * *argcp); | ||
| 322 | new_argv[count + *argcp] = NULL; | ||
| 323 | |||
| 324 | *argv = new_argv; | ||
| 325 | *argcp += count - 1; | ||
| 326 | |||
| 327 | ret = 1; | ||
| 328 | } | ||
| 329 | |||
| 330 | errno = saved_errno; | ||
| 331 | |||
| 332 | return ret; | ||
| 333 | } | ||
| 334 | |||
| 335 | #define RUN_SETUP (1<<0) | 270 | #define RUN_SETUP (1<<0) |
| 336 | #define USE_PAGER (1<<1) | 271 | #define USE_PAGER (1<<1) |
| 337 | 272 | ||
| @@ -455,25 +390,12 @@ do_die: | |||
| 455 | 390 | ||
| 456 | static int run_argv(int *argcp, const char ***argv) | 391 | static int run_argv(int *argcp, const char ***argv) |
| 457 | { | 392 | { |
| 458 | int done_alias = 0; | 393 | /* See if it's an internal command */ |
| 459 | 394 | handle_internal_command(*argcp, *argv); | |
| 460 | while (1) { | ||
| 461 | /* See if it's an internal command */ | ||
| 462 | handle_internal_command(*argcp, *argv); | ||
| 463 | |||
| 464 | /* .. then try the external ones */ | ||
| 465 | execv_dashed_external(*argv); | ||
| 466 | 395 | ||
| 467 | /* It could be an alias -- this works around the insanity | 396 | /* .. then try the external ones */ |
| 468 | * of overriding "perf log" with "perf show" by having | 397 | execv_dashed_external(*argv); |
| 469 | * alias.log = show | 398 | return 0; |
| 470 | */ | ||
| 471 | if (done_alias || !handle_alias(argcp, argv)) | ||
| 472 | break; | ||
| 473 | done_alias = 1; | ||
| 474 | } | ||
| 475 | |||
| 476 | return done_alias; | ||
| 477 | } | 399 | } |
| 478 | 400 | ||
| 479 | static void pthread__block_sigwinch(void) | 401 | static void pthread__block_sigwinch(void) |
| @@ -606,17 +528,12 @@ int main(int argc, const char **argv) | |||
| 606 | 528 | ||
| 607 | while (1) { | 529 | while (1) { |
| 608 | static int done_help; | 530 | static int done_help; |
| 609 | int was_alias = run_argv(&argc, &argv); | 531 | |
| 532 | run_argv(&argc, &argv); | ||
| 610 | 533 | ||
| 611 | if (errno != ENOENT) | 534 | if (errno != ENOENT) |
| 612 | break; | 535 | break; |
| 613 | 536 | ||
| 614 | if (was_alias) { | ||
| 615 | fprintf(stderr, "Expansion of alias '%s' failed; " | ||
| 616 | "'%s' is not a perf-command\n", | ||
| 617 | cmd, argv[0]); | ||
| 618 | goto out; | ||
| 619 | } | ||
| 620 | if (!done_help) { | 537 | if (!done_help) { |
| 621 | cmd = argv[0] = help_unknown_cmd(cmd); | 538 | cmd = argv[0] = help_unknown_cmd(cmd); |
| 622 | done_help = 1; | 539 | done_help = 1; |
diff --git a/tools/perf/util/Build b/tools/perf/util/Build index 2ae92da613dd..5c0ea11a8f0a 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build | |||
| @@ -1,4 +1,3 @@ | |||
| 1 | libperf-y += alias.o | ||
| 2 | libperf-y += annotate.o | 1 | libperf-y += annotate.o |
| 3 | libperf-y += block-range.o | 2 | libperf-y += block-range.o |
| 4 | libperf-y += build-id.o | 3 | libperf-y += build-id.o |
diff --git a/tools/perf/util/alias.c b/tools/perf/util/alias.c deleted file mode 100644 index 6455471d9cd1..000000000000 --- a/tools/perf/util/alias.c +++ /dev/null | |||
| @@ -1,78 +0,0 @@ | |||
| 1 | #include "cache.h" | ||
| 2 | #include "util.h" | ||
| 3 | #include "config.h" | ||
| 4 | |||
| 5 | static const char *alias_key; | ||
| 6 | static char *alias_val; | ||
| 7 | |||
| 8 | static int alias_lookup_cb(const char *k, const char *v, | ||
| 9 | void *cb __maybe_unused) | ||
| 10 | { | ||
| 11 | if (!prefixcmp(k, "alias.") && !strcmp(k+6, alias_key)) { | ||
| 12 | if (!v) | ||
| 13 | return config_error_nonbool(k); | ||
| 14 | alias_val = strdup(v); | ||
| 15 | return 0; | ||
| 16 | } | ||
| 17 | return 0; | ||
| 18 | } | ||
| 19 | |||
| 20 | char *alias_lookup(const char *alias) | ||
| 21 | { | ||
| 22 | alias_key = alias; | ||
| 23 | alias_val = NULL; | ||
| 24 | perf_config(alias_lookup_cb, NULL); | ||
| 25 | return alias_val; | ||
| 26 | } | ||
| 27 | |||
| 28 | int split_cmdline(char *cmdline, const char ***argv) | ||
| 29 | { | ||
| 30 | int src, dst, count = 0, size = 16; | ||
| 31 | char quoted = 0; | ||
| 32 | |||
| 33 | *argv = malloc(sizeof(char*) * size); | ||
| 34 | |||
| 35 | /* split alias_string */ | ||
| 36 | (*argv)[count++] = cmdline; | ||
| 37 | for (src = dst = 0; cmdline[src];) { | ||
| 38 | char c = cmdline[src]; | ||
| 39 | if (!quoted && isspace(c)) { | ||
| 40 | cmdline[dst++] = 0; | ||
| 41 | while (cmdline[++src] | ||
| 42 | && isspace(cmdline[src])) | ||
| 43 | ; /* skip */ | ||
| 44 | if (count >= size) { | ||
| 45 | size += 16; | ||
| 46 | *argv = realloc(*argv, sizeof(char*) * size); | ||
| 47 | } | ||
| 48 | (*argv)[count++] = cmdline + dst; | ||
| 49 | } else if (!quoted && (c == '\'' || c == '"')) { | ||
| 50 | quoted = c; | ||
| 51 | src++; | ||
| 52 | } else if (c == quoted) { | ||
| 53 | quoted = 0; | ||
| 54 | src++; | ||
| 55 | } else { | ||
| 56 | if (c == '\\' && quoted != '\'') { | ||
| 57 | src++; | ||
| 58 | c = cmdline[src]; | ||
| 59 | if (!c) { | ||
| 60 | zfree(argv); | ||
| 61 | return error("cmdline ends with \\"); | ||
| 62 | } | ||
| 63 | } | ||
| 64 | cmdline[dst++] = c; | ||
| 65 | src++; | ||
| 66 | } | ||
| 67 | } | ||
| 68 | |||
| 69 | cmdline[dst] = 0; | ||
| 70 | |||
| 71 | if (quoted) { | ||
| 72 | zfree(argv); | ||
| 73 | return error("unclosed quote"); | ||
| 74 | } | ||
| 75 | |||
| 76 | return count; | ||
| 77 | } | ||
| 78 | |||
diff --git a/tools/perf/util/cache.h b/tools/perf/util/cache.h index 512c0c83fbc6..0328f297a748 100644 --- a/tools/perf/util/cache.h +++ b/tools/perf/util/cache.h | |||
| @@ -15,7 +15,6 @@ | |||
| 15 | #define PERF_TRACEFS_ENVIRONMENT "PERF_TRACEFS_DIR" | 15 | #define PERF_TRACEFS_ENVIRONMENT "PERF_TRACEFS_DIR" |
| 16 | #define PERF_PAGER_ENVIRONMENT "PERF_PAGER" | 16 | #define PERF_PAGER_ENVIRONMENT "PERF_PAGER" |
| 17 | 17 | ||
| 18 | char *alias_lookup(const char *alias); | ||
| 19 | int split_cmdline(char *cmdline, const char ***argv); | 18 | int split_cmdline(char *cmdline, const char ***argv); |
| 20 | 19 | ||
| 21 | #define alloc_nr(x) (((x)+16)*3/2) | 20 | #define alloc_nr(x) (((x)+16)*3/2) |
diff --git a/tools/perf/util/help-unknown-cmd.c b/tools/perf/util/help-unknown-cmd.c index 2821f8d77e52..34201440ac03 100644 --- a/tools/perf/util/help-unknown-cmd.c +++ b/tools/perf/util/help-unknown-cmd.c | |||
| @@ -6,16 +6,12 @@ | |||
| 6 | #include "levenshtein.h" | 6 | #include "levenshtein.h" |
| 7 | 7 | ||
| 8 | static int autocorrect; | 8 | static int autocorrect; |
| 9 | static struct cmdnames aliases; | ||
| 10 | 9 | ||
| 11 | static int perf_unknown_cmd_config(const char *var, const char *value, | 10 | static int perf_unknown_cmd_config(const char *var, const char *value, |
| 12 | void *cb __maybe_unused) | 11 | void *cb __maybe_unused) |
| 13 | { | 12 | { |
| 14 | if (!strcmp(var, "help.autocorrect")) | 13 | if (!strcmp(var, "help.autocorrect")) |
| 15 | autocorrect = perf_config_int(var,value); | 14 | autocorrect = perf_config_int(var,value); |
| 16 | /* Also use aliases for command lookup */ | ||
| 17 | if (!prefixcmp(var, "alias.")) | ||
| 18 | add_cmdname(&aliases, var + 6, strlen(var + 6)); | ||
| 19 | 15 | ||
| 20 | return 0; | 16 | return 0; |
| 21 | } | 17 | } |
| @@ -59,14 +55,12 @@ const char *help_unknown_cmd(const char *cmd) | |||
| 59 | 55 | ||
| 60 | memset(&main_cmds, 0, sizeof(main_cmds)); | 56 | memset(&main_cmds, 0, sizeof(main_cmds)); |
| 61 | memset(&other_cmds, 0, sizeof(main_cmds)); | 57 | memset(&other_cmds, 0, sizeof(main_cmds)); |
| 62 | memset(&aliases, 0, sizeof(aliases)); | ||
| 63 | 58 | ||
| 64 | perf_config(perf_unknown_cmd_config, NULL); | 59 | perf_config(perf_unknown_cmd_config, NULL); |
| 65 | 60 | ||
| 66 | load_command_list("perf-", &main_cmds, &other_cmds); | 61 | load_command_list("perf-", &main_cmds, &other_cmds); |
| 67 | 62 | ||
| 68 | if (add_cmd_list(&main_cmds, &aliases) < 0 || | 63 | if (add_cmd_list(&main_cmds, &other_cmds) < 0) { |
| 69 | add_cmd_list(&main_cmds, &other_cmds) < 0) { | ||
| 70 | fprintf(stderr, "ERROR: Failed to allocate command list for unknown command.\n"); | 64 | fprintf(stderr, "ERROR: Failed to allocate command list for unknown command.\n"); |
| 71 | goto end; | 65 | goto end; |
| 72 | } | 66 | } |
