10 #include <subcmd/exec-cmd.h> 12 #include <subcmd/parse-options.h> 13 #include <subcmd/run-command.h> 14 #include <subcmd/help.h> 16 #include <linux/kernel.h> 19 #include <sys/types.h> 43 if (!strcmp(format,
"man"))
45 if (!strcmp(format,
"info"))
47 if (!strcmp(format,
"web") || !strcmp(format,
"html"))
50 pr_err(
"unrecognized help format '%s'", format);
59 if (!strcasecmp(name, viewer->
name))
68 struct child_process ec_process;
69 const char *argv_ec[] = {
"emacsclient",
"--version", NULL };
74 memset(&ec_process, 0,
sizeof(ec_process));
75 ec_process.argv = argv_ec;
77 ec_process.stdout_to_stderr = 1;
78 if (start_command(&ec_process)) {
79 fprintf(stderr,
"Failed to start emacsclient.\n");
83 fprintf(stderr,
"Failed to read emacsclient version\n");
86 close(ec_process.err);
92 finish_command(&ec_process);
94 if (!strstarts(buffer.
buf,
"emacsclient")) {
95 fprintf(stderr,
"Failed to parse emacsclient version.\n");
99 version = atoi(buffer.
buf + strlen(
"emacsclient"));
103 "emacsclient version '%d' too old (< 22).\n",
115 pr_warning(
"failed to exec '%s': %s", cmd, str_error_r(errno, sbuf,
sizeof(sbuf)));
125 path =
"emacsclient";
126 if (asprintf(&man_page,
"(woman \"%s\")", page) > 0) {
127 execlp(path,
"emacsclient",
"-e", man_page, NULL);
136 const char *display = getenv(
"DISPLAY");
138 if (display && *display) {
144 const char *file = strrchr(path,
'/');
145 if (file && !strcmp(file + 1,
"konqueror")) {
146 char *
new = strdup(path);
147 char *dest = strrchr(
new,
'/');
150 strcpy(dest + 1,
"kfmclient");
157 if (asprintf(&man_page,
"man:%s(1)", page) > 0) {
158 execlp(path, filename,
"newTab", man_page, NULL);
169 execlp(path,
"man", page, NULL);
177 if (asprintf(&shell_cmd,
"%s %s", cmd, page) > 0) {
178 execl(
"/bin/sh",
"sh",
"-c", shell_cmd, NULL);
187 size_t len = strlen(name);
191 *p =
zalloc(
sizeof(**p) + len + 1);
192 strncpy((*p)->name, name, len);
197 return (!strncasecmp(
"man", name, len) ||
198 !strncasecmp(
"woman", name, len) ||
199 !strncasecmp(
"konqueror", name, len));
208 strncpy(
new->name, name, len);
209 new->info = strdup(value);
216 pr_warning(
"'%s': path for unsupported man viewer.\n" 217 "Please consider using 'man.<tool>.%s' instead.", name, var);
246 const char *
name = var + 4;
247 const char *subkey = strrchr(name,
'.');
250 pr_err(
"Config with no key for man viewer: %s", name);
254 if (!strcmp(subkey,
".path")) {
259 if (!strcmp(subkey,
".cmd")) {
265 pr_warning(
"'%s': unsupported man viewer sub key.", subkey);
273 if (!strcmp(var,
"help.format")) {
281 if (!strcmp(var,
"man.viewer")) {
287 if (strstarts(var,
"man."))
297 unsigned int i, longest = 0;
304 puts(
" The most commonly used perf commands are:");
317 else if (strstarts(perf_cmd,
"perf"))
320 return asprintf(&s,
"perf-%s", perf_cmd) < 0 ? NULL : s;
326 const char *old_path = getenv(
"MANPATH");
332 if (asprintf(&new_path,
"%s:%s", system_path(PERF_MAN_PATH), old_path ?:
"") > 0) {
333 setenv(
"MANPATH", new_path, 1);
336 pr_err(
"Unable to setup man path");
344 if (!strcasecmp(name,
"man"))
346 else if (!strcasecmp(name,
"woman"))
348 else if (!strcasecmp(name,
"konqueror"))
353 pr_warning(
"'%s': unknown man viewer.", name);
360 const char *fallback = getenv(
"PERF_MAN_VIEWER");
370 pr_err(
"no man viewer handled the request");
377 setenv(
"INFOPATH", system_path(PERF_INFO_PATH), 1);
378 execlp(
"info",
"info",
"perfman", page, NULL);
385 const char *html_path = system_path(PERF_HTML_PATH);
388 if (stat(
mkpath(
"%s/perf.html", html_path), &st)
389 || !S_ISREG(st.st_mode)) {
390 pr_err(
"'%s': not a documentation directory.", html_path);
394 return asprintf(page_path,
"%s/%s.html", html_path, page);
405 execl_cmd(
"web--browse",
"-c",
"help.browser", path, NULL);
424 bool show_all =
false;
426 struct option builtin_help_options[] = {
427 OPT_BOOLEAN(
'a',
"all", &show_all,
"print all available commands"),
428 OPT_SET_UINT(
'm',
"man", &help_format,
"show man page",
HELP_FORMAT_MAN),
429 OPT_SET_UINT(
'w',
"web", &help_format,
"show manual in web browser",
431 OPT_SET_UINT(
'i',
"info", &help_format,
"show info page",
435 const char *
const builtin_help_subcommands[] = {
436 "buildid-cache",
"buildid-list",
"diff",
"evlist",
"help",
"list",
437 "record",
"report",
"bench",
"stat",
"timechart",
"top",
"annotate",
438 "script",
"sched",
"kallsyms",
"kmem",
"lock",
"kvm",
"test",
"inject",
"mem",
"data",
439 #ifdef HAVE_LIBELF_SUPPORT 442 #if defined(HAVE_LIBAUDIT_SUPPORT) || defined(HAVE_SYSCALL_TABLE_SUPPORT) 446 const char *builtin_help_usage[] = {
447 "perf help [--all] [--man|--web|--info] [command]",
452 load_command_list(
"perf-", &main_cmds, &
other_cmds);
458 argc = parse_options_subcommand(argc, argv, builtin_help_options,
459 builtin_help_subcommands, builtin_help_usage, 0);
463 list_commands(
"perf commands", &main_cmds, &
other_cmds);
475 switch (help_format) {
static const char * cmd_to_page(const char *perf_cmd)
const char perf_usage_string[]
const char perf_more_info_string[]
static void setup_man_path(void)
static void exec_man_cmd(const char *cmd, const char *page)
static void open_html(const char *path)
static struct version version
static int add_man_viewer_info(const char *var, const char *value)
static struct cmdnames main_cmds other_cmds
static struct man_viewer_info_list * man_viewer_info_list
struct man_viewer_info_list * next
static int show_man_page(const char *perf_cmd)
static int add_man_viewer_cmd(const char *name, size_t len, const char *value)
static int show_html_page(const char *perf_cmd)
static int show_info_page(const char *perf_cmd)
x86 movsq based memset() in arch/x86/lib/memset_64.S") MEMSET_FN(memset_erms
static void exec_man_konqueror(const char *path, const char *page)
static void unsupported_man_viewer(const char *name, const char *var)
static int get_html_page_path(char **page_path, const char *page)
struct man_viewer_list * next
static const char * get_man_viewer_info(const char *name)
static struct cmdname_help common_cmds[]
void list_common_cmds_help(void)
static void add_man_viewer(const char *name)
static void exec_viewer(const char *name, const char *page)
ssize_t strbuf_read(struct strbuf *sb, int fd, ssize_t hint)
static enum help_format parse_help_format(const char *format)
int perf_config(config_fn_t fn, void *data)
static struct man_viewer_list * man_viewer_list
int cmd_help(int argc, const char **argv)
static void exec_failed(const char *cmd)
static void do_add_man_viewer_info(const char *name, size_t len, const char *value)
#define pr_warning(fmt,...)
int config_error_nonbool(const char *var)
static int supported_man_viewer(const char *name, size_t len)
char * mkpath(const char *fmt,...) __printf(1
static int add_man_viewer_path(const char *name, size_t len, const char *value)
void strbuf_release(struct strbuf *sb)
static void exec_man_man(const char *path, const char *page)
static int perf_help_config(const char *var, const char *value, void *cb)
static int check_emacsclient_version(void)
static void exec_woman_emacs(const char *path, const char *page)
void static void * zalloc(size_t size)