13 #include <subcmd/exec-cmd.h> 15 #include <subcmd/run-command.h> 17 #include <subcmd/parse-options.h> 21 #include <api/fs/fs.h> 22 #include <api/fs/tracing_path.h> 28 #include <sys/types.h> 31 #include <linux/kernel.h> 34 "perf [--version] [--help] [OPTIONS] COMMAND [ARGS]";
37 "See 'perf help COMMAND' for more information on a specific command.";
44 int (*
fn)(int,
const char **);
68 #ifdef HAVE_LIBELF_SUPPORT 75 #if defined(HAVE_LIBAUDIT_SUPPORT) || defined(HAVE_SYSCALL_TABLE_SUPPORT) 92 if (strstarts(var,
"pager.") && !strcmp(var + 6, c->
cmd))
111 if (strstarts(var,
"tui.") && !strcmp(var + 4, c->
cmd))
113 if (strstarts(var,
"gtk.") && !strcmp(var + 4, c->
cmd))
147 OPT_ARGUMENT(
"help",
"help"),
148 OPT_ARGUMENT(
"version",
"version"),
149 OPT_ARGUMENT(
"exec-path",
"exec-path"),
150 OPT_ARGUMENT(
"html-path",
"html-path"),
151 OPT_ARGUMENT(
"paginate",
"paginate"),
152 OPT_ARGUMENT(
"no-pager",
"no-pager"),
153 OPT_ARGUMENT(
"debugfs-dir",
"debugfs-dir"),
154 OPT_ARGUMENT(
"buildid-dir",
"buildid-dir"),
155 OPT_ARGUMENT(
"list-cmds",
"list-cmds"),
156 OPT_ARGUMENT(
"list-opts",
"list-opts"),
157 OPT_ARGUMENT(
"debug",
"debug"),
166 const char *
cmd = (*argv)[0];
175 if (!strcmp(cmd,
"--help") || !strcmp(cmd,
"--version"))
182 if (!strcmp(cmd,
"-h")) {
183 (*argv)[0] =
"--help";
187 if (!strcmp(cmd,
"-v")) {
188 (*argv)[0] =
"--version";
192 if (!strcmp(cmd,
"-vv")) {
193 (*argv)[0] =
"version";
204 set_argv_exec_path(cmd + 1);
206 puts(get_argv_exec_path());
209 }
else if (!strcmp(cmd,
"--html-path")) {
210 puts(system_path(PERF_HTML_PATH));
212 }
else if (!strcmp(cmd,
"-p") || !strcmp(cmd,
"--paginate")) {
214 }
else if (!strcmp(cmd,
"--no-pager")) {
218 }
else if (!strcmp(cmd,
"--debugfs-dir")) {
220 fprintf(stderr,
"No directory given for --debugfs-dir.\n");
223 tracing_path_set((*argv)[1]);
228 }
else if (!strcmp(cmd,
"--buildid-dir")) {
230 fprintf(stderr,
"No directory given for --buildid-dir.\n");
240 fprintf(stderr,
"dir: %s\n", tracing_path_mount());
243 }
else if (!strcmp(cmd,
"--list-cmds")) {
246 for (i = 0; i < ARRAY_SIZE(commands); i++) {
248 printf(
"%s ", p->
cmd);
252 }
else if (!strcmp(cmd,
"--list-opts")) {
255 for (i = 0; i < ARRAY_SIZE(
options)-1; i++) {
257 printf(
"--%s ", p->long_name);
261 }
else if (!strcmp(cmd,
"--debug")) {
263 fprintf(stderr,
"No variable specified for --debug.\n");
272 fprintf(stderr,
"Unknown option: %s\n", cmd);
283 #define RUN_SETUP (1<<0) 284 #define USE_PAGER (1<<1) 302 status = p->
fn(argc, argv);
309 return status & 0xff;
312 if (fstat(fileno(stdout), &st))
315 if (S_ISFIFO(st.st_mode) || S_ISSOCK(st.st_mode))
320 if (fflush(stdout)) {
321 fprintf(stderr,
"write failure on standard output: %s",
322 str_error_r(errno, sbuf,
sizeof(sbuf)));
325 if (ferror(stdout)) {
326 fprintf(stderr,
"unknown write failure on standard output");
329 if (fclose(stdout)) {
330 fprintf(stderr,
"close failed on standard output: %s",
331 str_error_r(errno, sbuf,
sizeof(sbuf)));
341 const char *
cmd = argv[0];
345 if (argc > 1 && !strcmp(argv[1],
"--help")) {
347 argv[0] = cmd =
"help";
350 for (i = 0; i < ARRAY_SIZE(commands); i++) {
352 if (strcmp(p->
cmd, cmd))
364 if (asprintf(&cmd,
"perf-%s", argv[0]) < 0)
380 status = run_command_v_opt(argv, 0);
381 if (status != -ERR_RUN_COMMAND_EXEC) {
382 if (IS_RUN_COMMAND_ERR(status)) {
384 pr_err(
"FATAL: unable to run '%s'", argv[0]);
395 static int run_argv(
int *argcp,
const char ***argv)
410 sigaddset(&
set, SIGWINCH);
411 pthread_sigmask(SIG_BLOCK, &
set, NULL);
419 sigaddset(&
set, SIGWINCH);
420 pthread_sigmask(SIG_UNBLOCK, &
set, NULL);
436 cmd = extract_argv0_path(argv[0]);
459 if (strstarts(cmd,
"perf-")) {
470 if (strstarts(cmd,
"trace")) {
471 #if defined(HAVE_LIBAUDIT_SUPPORT) || defined(HAVE_SYSCALL_TABLE_SUPPORT) 477 "trace command not available: missing audit-libs devel package at build time.\n");
488 if (strstarts(argv[0],
"--"))
518 static int done_help;
532 fprintf(stderr,
"Failed to run command '%s': %s\n",
533 cmd, str_error_r(errno, sbuf,
sizeof(sbuf)));
int cmd_mem(int argc, const char **argv)
int cmd_report(int argc, const char **argv)
int cmd_kvm(int argc, const char **argv)
void perf_debug_setup(void)
int perf_env__set_cmdline(struct perf_env *env, int argc, const char *argv[])
int cmd_buildid_cache(int argc, const char **argv)
int cmd_record(int argc, const char **argv)
int perf_default_config(const char *var, const char *value, void *dummy __maybe_unused)
static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
static int handle_options(const char ***argv, int *argc, int *envchanged)
static int check_browser_config(const char *cmd)
static int browser_command_config(const char *var, const char *value, void *data)
int perf_config_bool(const char *name, const char *value)
int cmd_ftrace(int argc, const char **argv)
int cmd_list(int argc, const char **argv)
void set_buildid_dir(const char *dir)
int perf_debug_option(const char *str)
int cmd_script(int argc, const char **argv)
static int pager_command_config(const char *var, const char *value, void *data)
int cmd_timechart(int argc, const char **argv)
int cmd_c2c(int argc, const char **argv)
int cmd_kmem(int argc, const char **argv)
void perf_env__exit(struct perf_env *env)
int cmd_test(int argc, const char **argv)
static void commit_pager_choice(void)
const char perf_more_info_string[]
void perf_config__exit(void)
void pthread__unblock_sigwinch(void)
static void pthread__block_sigwinch(void)
int cmd_sched(int argc, const char **argv)
#define EXEC_PATH_ENVIRONMENT
void list_common_cmds_help(void)
int cmd_trace(int argc, const char **argv)
int cmd_lock(int argc, const char **argv)
void test_attr__init(void)
const char perf_usage_string[]
int cmd_version(int argc, const char **argv)
void exit_browser(bool wait_for_ok)
static int check_pager_config(const char *cmd)
static int run_argv(int *argcp, const char ***argv)
int perf_config(config_fn_t fn, void *data)
int cmd_inject(int argc, const char **argv)
static void execv_dashed_external(const char **argv)
int cmd_evlist(int argc, const char **argv)
int cmd_stat(int argc, const char **argv)
int cmd_help(int argc, const char **argv)
int cmd_top(int argc, const char **argv)
const char * help_unknown_cmd(const char *cmd)
int cmd_diff(int argc, const char **argv)
int cmd_probe(int argc, const char **argv)
int cmd_kallsyms(int argc, const char **argv)
int main(int argc, const char **argv)
#define PERF_PAGER_ENVIRONMENT
int cmd_config(int argc, const char **argv)
int cmd_data(int argc, const char **argv)
int cmd_annotate(int argc, const char **argv)
int cmd_buildid_list(int argc, const char **argv)
int cmd_bench(int argc, const char **argv)
static struct cmd_struct commands[]
int(* fn)(int, const char **)
static void handle_internal_command(int argc, const char **argv)