Commit 14cbfbeb authored by Namhyung Kim's avatar Namhyung Kim Committed by Arnaldo Carvalho de Melo

perf report: Show random usage tip on the help line

Currently perf report only shows a help message "For a higher level
overview, try: perf report --sort comm,dso" unconditionally (even if
the sort keys were used).  Add more help tips and show randomly.

Load tips from ${prefix}/share/doc/perf-tip/tips.txt file.

  $ perf report | tail
      0.10%  swapper  [kernel.vmlinux]   [k] irq_exit
      0.09%  swapper  [kernel.vmlinux]   [k] flush_smp_call_function_queue
      0.08%  swapper  [kernel.vmlinux]   [k] native_write_msr_safe
      0.03%  swapper  [kernel.vmlinux]   [k] group_sched_in
      0.01%  perf     [kernel.vmlinux]   [k] native_write_msr_safe

  #
  # (Tip: Search options using a keyword: perf report -h <keyword>)
  #
Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
Acked-by: default avatarIngo Molnar <mingo@kernel.org>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/r/1452166913-27046-1-git-send-email-namhyung@kernel.org
[ Renamed it to perf_tip() and the parameter dirname to dirpath to fix the build on older distros ]
Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent fc284be9
...@@ -41,6 +41,7 @@ CFLAGS_perf.o += -DPERF_HTML_PATH="BUILD_STR($(htmldir_SQ))" \ ...@@ -41,6 +41,7 @@ CFLAGS_perf.o += -DPERF_HTML_PATH="BUILD_STR($(htmldir_SQ))" \
-DPREFIX="BUILD_STR($(prefix_SQ))" \ -DPREFIX="BUILD_STR($(prefix_SQ))" \
-include $(OUTPUT)PERF-VERSION-FILE -include $(OUTPUT)PERF-VERSION-FILE
CFLAGS_builtin-trace.o += -DSTRACE_GROUPS_DIR="BUILD_STR($(STRACE_GROUPS_DIR_SQ))" CFLAGS_builtin-trace.o += -DSTRACE_GROUPS_DIR="BUILD_STR($(STRACE_GROUPS_DIR_SQ))"
CFLAGS_builtin-report.o += -DTIPDIR="BUILD_STR($(tipdir_SQ))"
libperf-y += util/ libperf-y += util/
libperf-y += arch/ libperf-y += arch/
......
For a higher level overview, try: perf report --sort comm,dso
Sample related events with: perf record -e '{cycles,instructions}:S'
Compare performance results with: perf diff [<old file> <new file>]
Boolean options have negative forms, e.g.: perf report --no-children
Customize output of perf script with: perf script -F event,ip,sym
Generate a script for your data: perf script -g <lang>
Save output of perf stat using: perf stat record <target workload>
Create an archive with symtabs to analyse on other machine: perf archive
Search options using a keyword: perf report -h <keyword>
Use parent filter to see specific call path: perf report -p <regex>
List events using substring match: perf list <keyword>
To see list of saved events and attributes: perf evlist -v
Use --symfs <dir> if your symbol files are in non-standard locations
To see callchains in a more compact form: perf report -g folded
...@@ -567,6 +567,9 @@ endif ...@@ -567,6 +567,9 @@ endif
$(call QUIET_INSTALL, perf_completion-script) \ $(call QUIET_INSTALL, perf_completion-script) \
$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(sysconfdir_SQ)/bash_completion.d'; \ $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(sysconfdir_SQ)/bash_completion.d'; \
$(INSTALL) perf-completion.sh '$(DESTDIR_SQ)$(sysconfdir_SQ)/bash_completion.d/perf' $(INSTALL) perf-completion.sh '$(DESTDIR_SQ)$(sysconfdir_SQ)/bash_completion.d/perf'
$(call QUIET_INSTALL, perf-tip) \
$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(tip_instdir_SQ)'; \
$(INSTALL) Documentation/tips.txt -t '$(DESTDIR_SQ)$(tip_instdir_SQ)'
install-tests: all install-gtk install-tests: all install-gtk
$(call QUIET_INSTALL, tests) \ $(call QUIET_INSTALL, tests) \
......
...@@ -433,7 +433,7 @@ static int report__browse_hists(struct report *rep) ...@@ -433,7 +433,7 @@ static int report__browse_hists(struct report *rep)
int ret; int ret;
struct perf_session *session = rep->session; struct perf_session *session = rep->session;
struct perf_evlist *evlist = session->evlist; struct perf_evlist *evlist = session->evlist;
const char *help = "For a higher level overview, try: perf report --sort comm,dso"; const char *help = perf_tip(TIPDIR);
switch (use_browser) { switch (use_browser) {
case 1: case 1:
......
...@@ -691,6 +691,7 @@ sharedir = $(prefix)/share ...@@ -691,6 +691,7 @@ sharedir = $(prefix)/share
template_dir = share/perf-core/templates template_dir = share/perf-core/templates
STRACE_GROUPS_DIR = share/perf-core/strace/groups STRACE_GROUPS_DIR = share/perf-core/strace/groups
htmldir = share/doc/perf-doc htmldir = share/doc/perf-doc
tipdir = share/doc/perf-tip
ifeq ($(prefix),/usr) ifeq ($(prefix),/usr)
sysconfdir = /etc sysconfdir = /etc
ETC_PERFCONFIG = $(sysconfdir)/perfconfig ETC_PERFCONFIG = $(sysconfdir)/perfconfig
...@@ -717,6 +718,7 @@ infodir_SQ = $(subst ','\'',$(infodir)) ...@@ -717,6 +718,7 @@ infodir_SQ = $(subst ','\'',$(infodir))
perfexecdir_SQ = $(subst ','\'',$(perfexecdir)) perfexecdir_SQ = $(subst ','\'',$(perfexecdir))
template_dir_SQ = $(subst ','\'',$(template_dir)) template_dir_SQ = $(subst ','\'',$(template_dir))
htmldir_SQ = $(subst ','\'',$(htmldir)) htmldir_SQ = $(subst ','\'',$(htmldir))
tipdir_SQ = $(subst ','\'',$(tipdir))
prefix_SQ = $(subst ','\'',$(prefix)) prefix_SQ = $(subst ','\'',$(prefix))
sysconfdir_SQ = $(subst ','\'',$(sysconfdir)) sysconfdir_SQ = $(subst ','\'',$(sysconfdir))
libdir_SQ = $(subst ','\'',$(libdir)) libdir_SQ = $(subst ','\'',$(libdir))
...@@ -724,12 +726,15 @@ libdir_SQ = $(subst ','\'',$(libdir)) ...@@ -724,12 +726,15 @@ libdir_SQ = $(subst ','\'',$(libdir))
ifneq ($(filter /%,$(firstword $(perfexecdir))),) ifneq ($(filter /%,$(firstword $(perfexecdir))),)
perfexec_instdir = $(perfexecdir) perfexec_instdir = $(perfexecdir)
STRACE_GROUPS_INSTDIR = $(STRACE_GROUPS_DIR) STRACE_GROUPS_INSTDIR = $(STRACE_GROUPS_DIR)
tip_instdir = $(tipdir)
else else
perfexec_instdir = $(prefix)/$(perfexecdir) perfexec_instdir = $(prefix)/$(perfexecdir)
STRACE_GROUPS_INSTDIR = $(prefix)/$(STRACE_GROUPS_DIR) STRACE_GROUPS_INSTDIR = $(prefix)/$(STRACE_GROUPS_DIR)
tip_instdir = $(prefix)/$(tipdir)
endif endif
perfexec_instdir_SQ = $(subst ','\'',$(perfexec_instdir)) perfexec_instdir_SQ = $(subst ','\'',$(perfexec_instdir))
STRACE_GROUPS_INSTDIR_SQ = $(subst ','\'',$(STRACE_GROUPS_INSTDIR)) STRACE_GROUPS_INSTDIR_SQ = $(subst ','\'',$(STRACE_GROUPS_INSTDIR))
tip_instdir_SQ = $(subst ','\'',$(tip_instdir))
# If we install to $(HOME) we keep the traceevent default: # If we install to $(HOME) we keep the traceevent default:
# $(HOME)/.traceevent/plugins # $(HOME)/.traceevent/plugins
...@@ -770,6 +775,7 @@ $(call detected_var,ETC_PERFCONFIG_SQ) ...@@ -770,6 +775,7 @@ $(call detected_var,ETC_PERFCONFIG_SQ)
$(call detected_var,STRACE_GROUPS_DIR_SQ) $(call detected_var,STRACE_GROUPS_DIR_SQ)
$(call detected_var,prefix_SQ) $(call detected_var,prefix_SQ)
$(call detected_var,perfexecdir_SQ) $(call detected_var,perfexecdir_SQ)
$(call detected_var,tipdir_SQ)
$(call detected_var,LIBDIR) $(call detected_var,LIBDIR)
$(call detected_var,GTK_CFLAGS) $(call detected_var,GTK_CFLAGS)
$(call detected_var,PERL_EMBED_CCOPTS) $(call detected_var,PERL_EMBED_CCOPTS)
......
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
#include "util/debug.h" #include "util/debug.h"
#include <api/fs/tracing_path.h> #include <api/fs/tracing_path.h>
#include <pthread.h> #include <pthread.h>
#include <stdlib.h>
#include <time.h>
const char perf_usage_string[] = const char perf_usage_string[] =
"perf [--version] [--help] [OPTIONS] COMMAND [ARGS]"; "perf [--version] [--help] [OPTIONS] COMMAND [ARGS]";
...@@ -542,6 +544,8 @@ int main(int argc, const char **argv) ...@@ -542,6 +544,8 @@ int main(int argc, const char **argv)
if (!cmd) if (!cmd)
cmd = "perf-help"; cmd = "perf-help";
srandom(time(NULL));
/* get debugfs/tracefs mount point from /proc/mounts */ /* get debugfs/tracefs mount point from /proc/mounts */
tracing_path_mount(); tracing_path_mount();
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
#include <linux/kernel.h> #include <linux/kernel.h>
#include <unistd.h> #include <unistd.h>
#include "callchain.h" #include "callchain.h"
#include "strlist.h"
#include <subcmd/exec-cmd.h>
struct callchain_param callchain_param = { struct callchain_param callchain_param = {
.mode = CHAIN_GRAPH_ABS, .mode = CHAIN_GRAPH_ABS,
...@@ -663,3 +665,28 @@ fetch_kernel_version(unsigned int *puint, char *str, ...@@ -663,3 +665,28 @@ fetch_kernel_version(unsigned int *puint, char *str,
*puint = (version << 16) + (patchlevel << 8) + sublevel; *puint = (version << 16) + (patchlevel << 8) + sublevel;
return 0; return 0;
} }
const char *perf_tip(const char *dirpath)
{
struct strlist *tips;
struct str_node *node;
char *tip = NULL;
struct strlist_config conf = {
.dirname = system_path(dirpath) ,
};
tips = strlist__new("tips.txt", &conf);
if (tips == NULL || strlist__nr_entries(tips) == 1) {
tip = (char *)"Cannot find tips.txt file";
goto out;
}
node = strlist__entry(tips, random() % strlist__nr_entries(tips));
if (asprintf(&tip, "Tip: %s", node->s) < 0)
tip = (char *)"Tip: get more memory! ;-)";
out:
strlist__delete(tips);
return tip;
}
...@@ -342,4 +342,6 @@ int fetch_kernel_version(unsigned int *puint, ...@@ -342,4 +342,6 @@ int fetch_kernel_version(unsigned int *puint,
#define KVER_FMT "%d.%d.%d" #define KVER_FMT "%d.%d.%d"
#define KVER_PARAM(x) KVER_VERSION(x), KVER_PATCHLEVEL(x), KVER_SUBLEVEL(x) #define KVER_PARAM(x) KVER_VERSION(x), KVER_PATCHLEVEL(x), KVER_SUBLEVEL(x)
const char *perf_tip(const char *dirpath);
#endif /* GIT_COMPAT_UTIL_H */ #endif /* GIT_COMPAT_UTIL_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment