blob: 3976aebe36778a6741835382790e364041ac6edd [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Ingo Molnar07800602009-04-20 15:00:56 +02002/*
3 * builtin-help.c
4 *
5 * Builtin help command
6 */
Arnaldo Carvalho de Melo8520a982019-08-29 16:18:59 -03007#include "util/cache.h"
Taeung Song41840d22016-06-23 17:55:17 +09008#include "util/config.h"
Arnaldo Carvalho de Melo8520a982019-08-29 16:18:59 -03009#include "util/strbuf.h"
Ingo Molnar07800602009-04-20 15:00:56 +020010#include "builtin.h"
Josh Poimboeuf4b6ab942015-12-15 09:39:39 -060011#include <subcmd/exec-cmd.h>
Ingo Molnar07800602009-04-20 15:00:56 +020012#include "common-cmds.h"
Josh Poimboeuf4b6ab942015-12-15 09:39:39 -060013#include <subcmd/parse-options.h>
14#include <subcmd/run-command.h>
15#include <subcmd/help.h>
Jiri Olsa84f5d362014-07-14 23:46:48 +020016#include "util/debug.h"
Arnaldo Carvalho de Melo877a7a12017-04-17 11:39:06 -030017#include <linux/kernel.h>
Arnaldo Carvalho de Melo8520a982019-08-29 16:18:59 -030018#include <linux/string.h>
Arnaldo Carvalho de Melo7f7c5362019-07-04 11:32:27 -030019#include <linux/zalloc.h>
Arnaldo Carvalho de Meloa43783a2017-04-18 10:46:11 -030020#include <errno.h>
Arnaldo Carvalho de Melo7a8ef4c2017-04-19 20:57:47 -030021#include <stdio.h>
Arnaldo Carvalho de Melo215a0d32019-07-04 11:21:24 -030022#include <stdlib.h>
Arnaldo Carvalho de Melo8520a982019-08-29 16:18:59 -030023#include <string.h>
Arnaldo Carvalho de Melo7a8ef4c2017-04-19 20:57:47 -030024#include <sys/types.h>
25#include <sys/stat.h>
26#include <unistd.h>
Ingo Molnar07800602009-04-20 15:00:56 +020027
28static struct man_viewer_list {
29 struct man_viewer_list *next;
Arnaldo Carvalho de Melo79096752017-04-17 11:08:20 -030030 char name[0];
Ingo Molnar07800602009-04-20 15:00:56 +020031} *man_viewer_list;
32
33static struct man_viewer_info_list {
34 struct man_viewer_info_list *next;
35 const char *info;
Arnaldo Carvalho de Melo79096752017-04-17 11:08:20 -030036 char name[0];
Ingo Molnar07800602009-04-20 15:00:56 +020037} *man_viewer_info_list;
38
39enum help_format {
David Aherncc584822012-08-26 12:24:45 -060040 HELP_FORMAT_NONE,
Ingo Molnar07800602009-04-20 15:00:56 +020041 HELP_FORMAT_MAN,
42 HELP_FORMAT_INFO,
43 HELP_FORMAT_WEB,
44};
45
Ingo Molnar07800602009-04-20 15:00:56 +020046static enum help_format parse_help_format(const char *format)
47{
48 if (!strcmp(format, "man"))
49 return HELP_FORMAT_MAN;
50 if (!strcmp(format, "info"))
51 return HELP_FORMAT_INFO;
52 if (!strcmp(format, "web") || !strcmp(format, "html"))
53 return HELP_FORMAT_WEB;
David Aherncc584822012-08-26 12:24:45 -060054
55 pr_err("unrecognized help format '%s'", format);
56 return HELP_FORMAT_NONE;
Ingo Molnar07800602009-04-20 15:00:56 +020057}
58
59static const char *get_man_viewer_info(const char *name)
60{
61 struct man_viewer_info_list *viewer;
62
Thiago Farinac1e53012009-11-03 08:28:45 -050063 for (viewer = man_viewer_info_list; viewer; viewer = viewer->next) {
Ingo Molnar07800602009-04-20 15:00:56 +020064 if (!strcasecmp(name, viewer->name))
65 return viewer->info;
66 }
67 return NULL;
68}
69
70static int check_emacsclient_version(void)
71{
72 struct strbuf buffer = STRBUF_INIT;
73 struct child_process ec_process;
74 const char *argv_ec[] = { "emacsclient", "--version", NULL };
75 int version;
Masami Hiramatsub72ca402016-05-10 14:47:17 +090076 int ret = -1;
Ingo Molnar07800602009-04-20 15:00:56 +020077
78 /* emacsclient prints its version number on stderr */
79 memset(&ec_process, 0, sizeof(ec_process));
80 ec_process.argv = argv_ec;
81 ec_process.err = -1;
82 ec_process.stdout_to_stderr = 1;
83 if (start_command(&ec_process)) {
84 fprintf(stderr, "Failed to start emacsclient.\n");
85 return -1;
86 }
Masami Hiramatsub72ca402016-05-10 14:47:17 +090087 if (strbuf_read(&buffer, ec_process.err, 20) < 0) {
88 fprintf(stderr, "Failed to read emacsclient version\n");
89 goto out;
90 }
Ingo Molnar07800602009-04-20 15:00:56 +020091 close(ec_process.err);
92
93 /*
94 * Don't bother checking return value, because "emacsclient --version"
95 * seems to always exits with code 1.
96 */
97 finish_command(&ec_process);
98
Arnaldo Carvalho de Melo8e99b6d2017-07-20 15:27:39 -030099 if (!strstarts(buffer.buf, "emacsclient")) {
Ingo Molnar07800602009-04-20 15:00:56 +0200100 fprintf(stderr, "Failed to parse emacsclient version.\n");
Masami Hiramatsub72ca402016-05-10 14:47:17 +0900101 goto out;
Ingo Molnar07800602009-04-20 15:00:56 +0200102 }
103
Arnaldo Carvalho de Melod1130682016-02-23 16:18:37 -0300104 version = atoi(buffer.buf + strlen("emacsclient"));
Ingo Molnar07800602009-04-20 15:00:56 +0200105
106 if (version < 22) {
107 fprintf(stderr,
108 "emacsclient version '%d' too old (< 22).\n",
109 version);
Masami Hiramatsub72ca402016-05-10 14:47:17 +0900110 } else
111 ret = 0;
112out:
Ingo Molnar07800602009-04-20 15:00:56 +0200113 strbuf_release(&buffer);
Masami Hiramatsub72ca402016-05-10 14:47:17 +0900114 return ret;
Ingo Molnar07800602009-04-20 15:00:56 +0200115}
116
Arnaldo Carvalho de Melo881c3622017-06-27 10:52:57 -0300117static void exec_failed(const char *cmd)
Ingo Molnar07800602009-04-20 15:00:56 +0200118{
Masami Hiramatsuede395d2014-08-14 02:22:53 +0000119 char sbuf[STRERR_BUFSIZE];
Arnaldo Carvalho de Melo881c3622017-06-27 10:52:57 -0300120 pr_warning("failed to exec '%s': %s", cmd, str_error_r(errno, sbuf, sizeof(sbuf)));
121}
Masami Hiramatsuede395d2014-08-14 02:22:53 +0000122
Arnaldo Carvalho de Melo881c3622017-06-27 10:52:57 -0300123static void exec_woman_emacs(const char *path, const char *page)
124{
Ingo Molnar07800602009-04-20 15:00:56 +0200125 if (!check_emacsclient_version()) {
126 /* This works only with emacsclient version >= 22. */
Arnaldo Carvalho de Meloa610f5c2016-03-23 15:44:09 -0300127 char *man_page;
Ingo Molnar07800602009-04-20 15:00:56 +0200128
129 if (!path)
130 path = "emacsclient";
Arnaldo Carvalho de Meloa610f5c2016-03-23 15:44:09 -0300131 if (asprintf(&man_page, "(woman \"%s\")", page) > 0) {
132 execlp(path, "emacsclient", "-e", man_page, NULL);
133 free(man_page);
134 }
Arnaldo Carvalho de Melo881c3622017-06-27 10:52:57 -0300135 exec_failed(path);
Ingo Molnar07800602009-04-20 15:00:56 +0200136 }
137}
138
Thiago Farinac1e53012009-11-03 08:28:45 -0500139static void exec_man_konqueror(const char *path, const char *page)
Ingo Molnar07800602009-04-20 15:00:56 +0200140{
141 const char *display = getenv("DISPLAY");
Masami Hiramatsuede395d2014-08-14 02:22:53 +0000142
Ingo Molnar07800602009-04-20 15:00:56 +0200143 if (display && *display) {
Arnaldo Carvalho de Meloa610f5c2016-03-23 15:44:09 -0300144 char *man_page;
Ingo Molnar07800602009-04-20 15:00:56 +0200145 const char *filename = "kfmclient";
146
147 /* It's simpler to launch konqueror using kfmclient. */
148 if (path) {
149 const char *file = strrchr(path, '/');
150 if (file && !strcmp(file + 1, "konqueror")) {
151 char *new = strdup(path);
152 char *dest = strrchr(new, '/');
153
154 /* strlen("konqueror") == strlen("kfmclient") */
155 strcpy(dest + 1, "kfmclient");
156 path = new;
157 }
158 if (file)
159 filename = file;
160 } else
161 path = "kfmclient";
Arnaldo Carvalho de Meloa610f5c2016-03-23 15:44:09 -0300162 if (asprintf(&man_page, "man:%s(1)", page) > 0) {
163 execlp(path, filename, "newTab", man_page, NULL);
164 free(man_page);
165 }
Arnaldo Carvalho de Melo881c3622017-06-27 10:52:57 -0300166 exec_failed(path);
Ingo Molnar07800602009-04-20 15:00:56 +0200167 }
168}
169
Thiago Farinac1e53012009-11-03 08:28:45 -0500170static void exec_man_man(const char *path, const char *page)
Ingo Molnar07800602009-04-20 15:00:56 +0200171{
172 if (!path)
173 path = "man";
174 execlp(path, "man", page, NULL);
Arnaldo Carvalho de Melo881c3622017-06-27 10:52:57 -0300175 exec_failed(path);
Ingo Molnar07800602009-04-20 15:00:56 +0200176}
177
178static void exec_man_cmd(const char *cmd, const char *page)
179{
Arnaldo Carvalho de Meloa610f5c2016-03-23 15:44:09 -0300180 char *shell_cmd;
Masami Hiramatsuede395d2014-08-14 02:22:53 +0000181
Arnaldo Carvalho de Meloa610f5c2016-03-23 15:44:09 -0300182 if (asprintf(&shell_cmd, "%s %s", cmd, page) > 0) {
183 execl("/bin/sh", "sh", "-c", shell_cmd, NULL);
184 free(shell_cmd);
185 }
Arnaldo Carvalho de Melo881c3622017-06-27 10:52:57 -0300186 exec_failed(cmd);
Ingo Molnar07800602009-04-20 15:00:56 +0200187}
188
189static void add_man_viewer(const char *name)
190{
191 struct man_viewer_list **p = &man_viewer_list;
192 size_t len = strlen(name);
193
194 while (*p)
195 p = &((*p)->next);
Arnaldo Carvalho de Melo36479482009-11-24 12:05:16 -0200196 *p = zalloc(sizeof(**p) + len + 1);
Arnaldo Carvalho de Melob6313892018-12-06 11:20:21 -0300197 strcpy((*p)->name, name);
Ingo Molnar07800602009-04-20 15:00:56 +0200198}
199
200static int supported_man_viewer(const char *name, size_t len)
201{
202 return (!strncasecmp("man", name, len) ||
203 !strncasecmp("woman", name, len) ||
204 !strncasecmp("konqueror", name, len));
205}
206
207static void do_add_man_viewer_info(const char *name,
208 size_t len,
209 const char *value)
210{
Arnaldo Carvalho de Melo36479482009-11-24 12:05:16 -0200211 struct man_viewer_info_list *new = zalloc(sizeof(*new) + len + 1);
Ingo Molnar07800602009-04-20 15:00:56 +0200212
213 strncpy(new->name, name, len);
214 new->info = strdup(value);
215 new->next = man_viewer_info_list;
216 man_viewer_info_list = new;
217}
218
Arnaldo Carvalho de Melo86e474f2017-06-27 10:59:28 -0300219static void unsupported_man_viewer(const char *name, const char *var)
220{
221 pr_warning("'%s': path for unsupported man viewer.\n"
222 "Please consider using 'man.<tool>.%s' instead.", name, var);
223}
224
Ingo Molnar07800602009-04-20 15:00:56 +0200225static int add_man_viewer_path(const char *name,
226 size_t len,
227 const char *value)
228{
229 if (supported_man_viewer(name, len))
230 do_add_man_viewer_info(name, len, value);
231 else
Arnaldo Carvalho de Melo86e474f2017-06-27 10:59:28 -0300232 unsupported_man_viewer(name, "cmd");
Ingo Molnar07800602009-04-20 15:00:56 +0200233
234 return 0;
235}
236
237static int add_man_viewer_cmd(const char *name,
238 size_t len,
239 const char *value)
240{
241 if (supported_man_viewer(name, len))
Arnaldo Carvalho de Melo86e474f2017-06-27 10:59:28 -0300242 unsupported_man_viewer(name, "path");
Ingo Molnar07800602009-04-20 15:00:56 +0200243 else
244 do_add_man_viewer_info(name, len, value);
245
246 return 0;
247}
248
249static int add_man_viewer_info(const char *var, const char *value)
250{
251 const char *name = var + 4;
252 const char *subkey = strrchr(name, '.');
253
Arnaldo Carvalho de Melo62d94b02017-06-27 11:22:31 -0300254 if (!subkey) {
255 pr_err("Config with no key for man viewer: %s", name);
256 return -1;
257 }
Ingo Molnar07800602009-04-20 15:00:56 +0200258
259 if (!strcmp(subkey, ".path")) {
260 if (!value)
261 return config_error_nonbool(var);
262 return add_man_viewer_path(name, subkey - name, value);
263 }
264 if (!strcmp(subkey, ".cmd")) {
265 if (!value)
266 return config_error_nonbool(var);
267 return add_man_viewer_cmd(name, subkey - name, value);
268 }
269
Arnaldo Carvalho de Melo59913aab2017-06-27 11:01:17 -0300270 pr_warning("'%s': unsupported man viewer sub key.", subkey);
Ingo Molnar07800602009-04-20 15:00:56 +0200271 return 0;
272}
273
274static int perf_help_config(const char *var, const char *value, void *cb)
275{
Arnaldo Carvalho de Melo2bae1d12012-10-01 15:20:58 -0300276 enum help_format *help_formatp = cb;
277
Ingo Molnar07800602009-04-20 15:00:56 +0200278 if (!strcmp(var, "help.format")) {
279 if (!value)
280 return config_error_nonbool(var);
Arnaldo Carvalho de Melo2bae1d12012-10-01 15:20:58 -0300281 *help_formatp = parse_help_format(value);
282 if (*help_formatp == HELP_FORMAT_NONE)
David Aherncc584822012-08-26 12:24:45 -0600283 return -1;
Ingo Molnar07800602009-04-20 15:00:56 +0200284 return 0;
285 }
286 if (!strcmp(var, "man.viewer")) {
287 if (!value)
288 return config_error_nonbool(var);
289 add_man_viewer(value);
290 return 0;
291 }
Namhyung Kim2f0af862017-11-14 09:15:42 +0900292 if (strstarts(var, "man."))
Ingo Molnar07800602009-04-20 15:00:56 +0200293 return add_man_viewer_info(var, value);
294
Wang Nanb8cbb342016-02-26 09:31:51 +0000295 return 0;
Ingo Molnar07800602009-04-20 15:00:56 +0200296}
297
298static struct cmdnames main_cmds, other_cmds;
299
300void list_common_cmds_help(void)
301{
Ingo Molnarf37a2912009-07-01 12:37:06 +0200302 unsigned int i, longest = 0;
Ingo Molnar07800602009-04-20 15:00:56 +0200303
304 for (i = 0; i < ARRAY_SIZE(common_cmds); i++) {
305 if (longest < strlen(common_cmds[i].name))
306 longest = strlen(common_cmds[i].name);
307 }
308
Ingo Molnar502fc5c2009-03-13 03:20:49 +0100309 puts(" The most commonly used perf commands are:");
Ingo Molnar07800602009-04-20 15:00:56 +0200310 for (i = 0; i < ARRAY_SIZE(common_cmds); i++) {
Amerigo Wang3912f2a2009-12-14 03:23:56 -0500311 printf(" %-*s ", longest, common_cmds[i].name);
Ingo Molnar07800602009-04-20 15:00:56 +0200312 puts(common_cmds[i].help);
313 }
314}
315
Ingo Molnar07800602009-04-20 15:00:56 +0200316static const char *cmd_to_page(const char *perf_cmd)
317{
Arnaldo Carvalho de Meloa610f5c2016-03-23 15:44:09 -0300318 char *s;
319
Ingo Molnar07800602009-04-20 15:00:56 +0200320 if (!perf_cmd)
321 return "perf";
Namhyung Kim2f0af862017-11-14 09:15:42 +0900322 else if (strstarts(perf_cmd, "perf"))
Ingo Molnar07800602009-04-20 15:00:56 +0200323 return perf_cmd;
Arnaldo Carvalho de Meloa610f5c2016-03-23 15:44:09 -0300324
325 return asprintf(&s, "perf-%s", perf_cmd) < 0 ? NULL : s;
Ingo Molnar07800602009-04-20 15:00:56 +0200326}
327
328static void setup_man_path(void)
329{
Arnaldo Carvalho de Meloa610f5c2016-03-23 15:44:09 -0300330 char *new_path;
Ingo Molnar07800602009-04-20 15:00:56 +0200331 const char *old_path = getenv("MANPATH");
332
333 /* We should always put ':' after our path. If there is no
334 * old_path, the ':' at the end will let 'man' to try
335 * system-wide paths after ours to find the manual page. If
336 * there is old_path, we need ':' as delimiter. */
Arnaldo Carvalho de Meloa610f5c2016-03-23 15:44:09 -0300337 if (asprintf(&new_path, "%s:%s", system_path(PERF_MAN_PATH), old_path ?: "") > 0) {
338 setenv("MANPATH", new_path, 1);
339 free(new_path);
340 } else {
Arnaldo Carvalho de Melo62d94b02017-06-27 11:22:31 -0300341 pr_err("Unable to setup man path");
Arnaldo Carvalho de Meloa610f5c2016-03-23 15:44:09 -0300342 }
Ingo Molnar07800602009-04-20 15:00:56 +0200343}
344
345static void exec_viewer(const char *name, const char *page)
346{
347 const char *info = get_man_viewer_info(name);
348
349 if (!strcasecmp(name, "man"))
350 exec_man_man(info, page);
351 else if (!strcasecmp(name, "woman"))
352 exec_woman_emacs(info, page);
353 else if (!strcasecmp(name, "konqueror"))
354 exec_man_konqueror(info, page);
355 else if (info)
356 exec_man_cmd(info, page);
357 else
Arnaldo Carvalho de Melo59913aab2017-06-27 11:01:17 -0300358 pr_warning("'%s': unknown man viewer.", name);
Ingo Molnar07800602009-04-20 15:00:56 +0200359}
360
David Aherncc584822012-08-26 12:24:45 -0600361static int show_man_page(const char *perf_cmd)
Ingo Molnar07800602009-04-20 15:00:56 +0200362{
363 struct man_viewer_list *viewer;
364 const char *page = cmd_to_page(perf_cmd);
365 const char *fallback = getenv("PERF_MAN_VIEWER");
366
367 setup_man_path();
368 for (viewer = man_viewer_list; viewer; viewer = viewer->next)
Ingo Molnar07800602009-04-20 15:00:56 +0200369 exec_viewer(viewer->name, page); /* will return when unable */
Thiago Farinac1e53012009-11-03 08:28:45 -0500370
Ingo Molnar07800602009-04-20 15:00:56 +0200371 if (fallback)
372 exec_viewer(fallback, page);
373 exec_viewer("man", page);
David Aherncc584822012-08-26 12:24:45 -0600374
375 pr_err("no man viewer handled the request");
376 return -1;
Ingo Molnar07800602009-04-20 15:00:56 +0200377}
378
David Aherncc584822012-08-26 12:24:45 -0600379static int show_info_page(const char *perf_cmd)
Ingo Molnar07800602009-04-20 15:00:56 +0200380{
381 const char *page = cmd_to_page(perf_cmd);
382 setenv("INFOPATH", system_path(PERF_INFO_PATH), 1);
383 execlp("info", "info", "perfman", page, NULL);
David Aherncc584822012-08-26 12:24:45 -0600384 return -1;
Ingo Molnar07800602009-04-20 15:00:56 +0200385}
386
Arnaldo Carvalho de Meloa610f5c2016-03-23 15:44:09 -0300387static int get_html_page_path(char **page_path, const char *page)
Ingo Molnar07800602009-04-20 15:00:56 +0200388{
389 struct stat st;
390 const char *html_path = system_path(PERF_HTML_PATH);
391
392 /* Check that we have a perf documentation directory. */
393 if (stat(mkpath("%s/perf.html", html_path), &st)
David Aherncc584822012-08-26 12:24:45 -0600394 || !S_ISREG(st.st_mode)) {
395 pr_err("'%s': not a documentation directory.", html_path);
396 return -1;
397 }
Ingo Molnar07800602009-04-20 15:00:56 +0200398
Arnaldo Carvalho de Meloa610f5c2016-03-23 15:44:09 -0300399 return asprintf(page_path, "%s/%s.html", html_path, page);
Ingo Molnar07800602009-04-20 15:00:56 +0200400}
401
402/*
403 * If open_html is not defined in a platform-specific way (see for
404 * example compat/mingw.h), we use the script web--browse to display
405 * HTML.
406 */
407#ifndef open_html
Ingo Molnar16f762a2009-05-27 09:10:38 +0200408static void open_html(const char *path)
Ingo Molnar07800602009-04-20 15:00:56 +0200409{
Josh Poimboeuf46113a52015-12-15 09:39:37 -0600410 execl_cmd("web--browse", "-c", "help.browser", path, NULL);
Ingo Molnar07800602009-04-20 15:00:56 +0200411}
412#endif
413
David Aherncc584822012-08-26 12:24:45 -0600414static int show_html_page(const char *perf_cmd)
Ingo Molnar07800602009-04-20 15:00:56 +0200415{
416 const char *page = cmd_to_page(perf_cmd);
Arnaldo Carvalho de Meloa610f5c2016-03-23 15:44:09 -0300417 char *page_path; /* it leaks but we exec bellow */
Ingo Molnar07800602009-04-20 15:00:56 +0200418
Arnaldo Carvalho de Meloa610f5c2016-03-23 15:44:09 -0300419 if (get_html_page_path(&page_path, page) < 0)
David Aherncc584822012-08-26 12:24:45 -0600420 return -1;
Ingo Molnar07800602009-04-20 15:00:56 +0200421
Arnaldo Carvalho de Meloa610f5c2016-03-23 15:44:09 -0300422 open_html(page_path);
David Aherncc584822012-08-26 12:24:45 -0600423
424 return 0;
Ingo Molnar07800602009-04-20 15:00:56 +0200425}
426
Arnaldo Carvalho de Melob0ad8ea2017-03-27 11:47:20 -0300427int cmd_help(int argc, const char **argv)
Ingo Molnar07800602009-04-20 15:00:56 +0200428{
Arnaldo Carvalho de Melo2bae1d12012-10-01 15:20:58 -0300429 bool show_all = false;
Namhyung Kim670ab5d2012-10-22 16:12:23 +0900430 enum help_format help_format = HELP_FORMAT_MAN;
Arnaldo Carvalho de Melo2bae1d12012-10-01 15:20:58 -0300431 struct option builtin_help_options[] = {
432 OPT_BOOLEAN('a', "all", &show_all, "print all available commands"),
433 OPT_SET_UINT('m', "man", &help_format, "show man page", HELP_FORMAT_MAN),
434 OPT_SET_UINT('w', "web", &help_format, "show manual in web browser",
435 HELP_FORMAT_WEB),
436 OPT_SET_UINT('i', "info", &help_format, "show info page",
437 HELP_FORMAT_INFO),
438 OPT_END(),
439 };
Yunlong Songe24a1102015-03-18 21:35:53 +0800440 const char * const builtin_help_subcommands[] = {
441 "buildid-cache", "buildid-list", "diff", "evlist", "help", "list",
442 "record", "report", "bench", "stat", "timechart", "top", "annotate",
Arnaldo Carvalho de Melo35563772017-01-05 15:33:32 -0300443 "script", "sched", "kallsyms", "kmem", "lock", "kvm", "test", "inject", "mem", "data",
Yunlong Songe24a1102015-03-18 21:35:53 +0800444#ifdef HAVE_LIBELF_SUPPORT
445 "probe",
446#endif
Jin Yao22e9af42018-04-09 18:26:48 +0800447#if defined(HAVE_LIBAUDIT_SUPPORT) || defined(HAVE_SYSCALL_TABLE_SUPPORT)
Yunlong Songe24a1102015-03-18 21:35:53 +0800448 "trace",
449#endif
450 NULL };
451 const char *builtin_help_usage[] = {
Arnaldo Carvalho de Melo2bae1d12012-10-01 15:20:58 -0300452 "perf help [--all] [--man|--web|--info] [command]",
453 NULL
454 };
Arnaldo Carvalho de Meloecc4c562017-01-24 13:44:10 -0300455 int rc;
Ingo Molnarf37a2912009-07-01 12:37:06 +0200456
Ingo Molnar07800602009-04-20 15:00:56 +0200457 load_command_list("perf-", &main_cmds, &other_cmds);
458
Arnaldo Carvalho de Meloecc4c562017-01-24 13:44:10 -0300459 rc = perf_config(perf_help_config, &help_format);
460 if (rc)
461 return rc;
Ingo Molnar07800602009-04-20 15:00:56 +0200462
Yunlong Songe24a1102015-03-18 21:35:53 +0800463 argc = parse_options_subcommand(argc, argv, builtin_help_options,
464 builtin_help_subcommands, builtin_help_usage, 0);
Ingo Molnar07800602009-04-20 15:00:56 +0200465
466 if (show_all) {
Yunlong Song3a134ae2015-10-15 15:39:51 +0800467 printf("\n Usage: %s\n\n", perf_usage_string);
Ingo Molnar07800602009-04-20 15:00:56 +0200468 list_commands("perf commands", &main_cmds, &other_cmds);
Ingo Molnar502fc5c2009-03-13 03:20:49 +0100469 printf(" %s\n\n", perf_more_info_string);
Ingo Molnar07800602009-04-20 15:00:56 +0200470 return 0;
471 }
472
473 if (!argv[0]) {
Ingo Molnar502fc5c2009-03-13 03:20:49 +0100474 printf("\n usage: %s\n\n", perf_usage_string);
Ingo Molnar07800602009-04-20 15:00:56 +0200475 list_common_cmds_help();
Ingo Molnar502fc5c2009-03-13 03:20:49 +0100476 printf("\n %s\n\n", perf_more_info_string);
Ingo Molnar07800602009-04-20 15:00:56 +0200477 return 0;
478 }
479
Ingo Molnar07800602009-04-20 15:00:56 +0200480 switch (help_format) {
481 case HELP_FORMAT_MAN:
David Aherncc584822012-08-26 12:24:45 -0600482 rc = show_man_page(argv[0]);
Ingo Molnar07800602009-04-20 15:00:56 +0200483 break;
484 case HELP_FORMAT_INFO:
David Aherncc584822012-08-26 12:24:45 -0600485 rc = show_info_page(argv[0]);
Ingo Molnar07800602009-04-20 15:00:56 +0200486 break;
487 case HELP_FORMAT_WEB:
David Aherncc584822012-08-26 12:24:45 -0600488 rc = show_html_page(argv[0]);
489 break;
490 case HELP_FORMAT_NONE:
491 /* fall-through */
Ingo Molnar83a09442009-08-15 12:26:57 +0200492 default:
David Aherncc584822012-08-26 12:24:45 -0600493 rc = -1;
Ingo Molnar07800602009-04-20 15:00:56 +0200494 break;
495 }
496
David Aherncc584822012-08-26 12:24:45 -0600497 return rc;
Ingo Molnar07800602009-04-20 15:00:56 +0200498}