aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf
diff options
context:
space:
mode:
authorNamhyung Kim <namhyung@kernel.org>2016-01-07 06:41:53 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2016-01-08 11:15:46 -0500
commit14cbfbeb76540cc0c53fbb0ba34b3a4900ebe40f (patch)
tree51bc19a46a576c64d784b6c0713eee59c8f73de3 /tools/perf
parentfc284be9d88528dd2a28d5471e40a6acde6c3036 (diff)
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: Namhyung Kim <namhyung@kernel.org> Acked-by: Ingo 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: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
-rw-r--r--tools/perf/Build1
-rw-r--r--tools/perf/Documentation/tips.txt14
-rw-r--r--tools/perf/Makefile.perf3
-rw-r--r--tools/perf/builtin-report.c2
-rw-r--r--tools/perf/config/Makefile6
-rw-r--r--tools/perf/perf.c4
-rw-r--r--tools/perf/util/util.c27
-rw-r--r--tools/perf/util/util.h2
8 files changed, 58 insertions, 1 deletions
diff --git a/tools/perf/Build b/tools/perf/Build
index 00c4b8c3d8ca..6b67e6f4179f 100644
--- a/tools/perf/Build
+++ b/tools/perf/Build
@@ -41,6 +41,7 @@ CFLAGS_perf.o += -DPERF_HTML_PATH="BUILD_STR($(htmldir_SQ))" \
41 -DPREFIX="BUILD_STR($(prefix_SQ))" \ 41 -DPREFIX="BUILD_STR($(prefix_SQ))" \
42 -include $(OUTPUT)PERF-VERSION-FILE 42 -include $(OUTPUT)PERF-VERSION-FILE
43CFLAGS_builtin-trace.o += -DSTRACE_GROUPS_DIR="BUILD_STR($(STRACE_GROUPS_DIR_SQ))" 43CFLAGS_builtin-trace.o += -DSTRACE_GROUPS_DIR="BUILD_STR($(STRACE_GROUPS_DIR_SQ))"
44CFLAGS_builtin-report.o += -DTIPDIR="BUILD_STR($(tipdir_SQ))"
44 45
45libperf-y += util/ 46libperf-y += util/
46libperf-y += arch/ 47libperf-y += arch/
diff --git a/tools/perf/Documentation/tips.txt b/tools/perf/Documentation/tips.txt
new file mode 100644
index 000000000000..a1c10e360db5
--- /dev/null
+++ b/tools/perf/Documentation/tips.txt
@@ -0,0 +1,14 @@
1For a higher level overview, try: perf report --sort comm,dso
2Sample related events with: perf record -e '{cycles,instructions}:S'
3Compare performance results with: perf diff [<old file> <new file>]
4Boolean options have negative forms, e.g.: perf report --no-children
5Customize output of perf script with: perf script -F event,ip,sym
6Generate a script for your data: perf script -g <lang>
7Save output of perf stat using: perf stat record <target workload>
8Create an archive with symtabs to analyse on other machine: perf archive
9Search options using a keyword: perf report -h <keyword>
10Use parent filter to see specific call path: perf report -p <regex>
11List events using substring match: perf list <keyword>
12To see list of saved events and attributes: perf evlist -v
13Use --symfs <dir> if your symbol files are in non-standard locations
14To see callchains in a more compact form: perf report -g folded
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 1025ea79b90b..0a22407e1d7d 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -567,6 +567,9 @@ endif
567 $(call QUIET_INSTALL, perf_completion-script) \ 567 $(call QUIET_INSTALL, perf_completion-script) \
568 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(sysconfdir_SQ)/bash_completion.d'; \ 568 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(sysconfdir_SQ)/bash_completion.d'; \
569 $(INSTALL) perf-completion.sh '$(DESTDIR_SQ)$(sysconfdir_SQ)/bash_completion.d/perf' 569 $(INSTALL) perf-completion.sh '$(DESTDIR_SQ)$(sysconfdir_SQ)/bash_completion.d/perf'
570 $(call QUIET_INSTALL, perf-tip) \
571 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(tip_instdir_SQ)'; \
572 $(INSTALL) Documentation/tips.txt -t '$(DESTDIR_SQ)$(tip_instdir_SQ)'
570 573
571install-tests: all install-gtk 574install-tests: all install-gtk
572 $(call QUIET_INSTALL, tests) \ 575 $(call QUIET_INSTALL, tests) \
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index f10c663af996..d5a42ee12529 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -433,7 +433,7 @@ static int report__browse_hists(struct report *rep)
433 int ret; 433 int ret;
434 struct perf_session *session = rep->session; 434 struct perf_session *session = rep->session;
435 struct perf_evlist *evlist = session->evlist; 435 struct perf_evlist *evlist = session->evlist;
436 const char *help = "For a higher level overview, try: perf report --sort comm,dso"; 436 const char *help = perf_tip(TIPDIR);
437 437
438 switch (use_browser) { 438 switch (use_browser) {
439 case 1: 439 case 1:
diff --git a/tools/perf/config/Makefile b/tools/perf/config/Makefile
index 18b2f96d0941..254d06e39bea 100644
--- a/tools/perf/config/Makefile
+++ b/tools/perf/config/Makefile
@@ -691,6 +691,7 @@ sharedir = $(prefix)/share
691template_dir = share/perf-core/templates 691template_dir = share/perf-core/templates
692STRACE_GROUPS_DIR = share/perf-core/strace/groups 692STRACE_GROUPS_DIR = share/perf-core/strace/groups
693htmldir = share/doc/perf-doc 693htmldir = share/doc/perf-doc
694tipdir = share/doc/perf-tip
694ifeq ($(prefix),/usr) 695ifeq ($(prefix),/usr)
695sysconfdir = /etc 696sysconfdir = /etc
696ETC_PERFCONFIG = $(sysconfdir)/perfconfig 697ETC_PERFCONFIG = $(sysconfdir)/perfconfig
@@ -717,6 +718,7 @@ infodir_SQ = $(subst ','\'',$(infodir))
717perfexecdir_SQ = $(subst ','\'',$(perfexecdir)) 718perfexecdir_SQ = $(subst ','\'',$(perfexecdir))
718template_dir_SQ = $(subst ','\'',$(template_dir)) 719template_dir_SQ = $(subst ','\'',$(template_dir))
719htmldir_SQ = $(subst ','\'',$(htmldir)) 720htmldir_SQ = $(subst ','\'',$(htmldir))
721tipdir_SQ = $(subst ','\'',$(tipdir))
720prefix_SQ = $(subst ','\'',$(prefix)) 722prefix_SQ = $(subst ','\'',$(prefix))
721sysconfdir_SQ = $(subst ','\'',$(sysconfdir)) 723sysconfdir_SQ = $(subst ','\'',$(sysconfdir))
722libdir_SQ = $(subst ','\'',$(libdir)) 724libdir_SQ = $(subst ','\'',$(libdir))
@@ -724,12 +726,15 @@ libdir_SQ = $(subst ','\'',$(libdir))
724ifneq ($(filter /%,$(firstword $(perfexecdir))),) 726ifneq ($(filter /%,$(firstword $(perfexecdir))),)
725perfexec_instdir = $(perfexecdir) 727perfexec_instdir = $(perfexecdir)
726STRACE_GROUPS_INSTDIR = $(STRACE_GROUPS_DIR) 728STRACE_GROUPS_INSTDIR = $(STRACE_GROUPS_DIR)
729tip_instdir = $(tipdir)
727else 730else
728perfexec_instdir = $(prefix)/$(perfexecdir) 731perfexec_instdir = $(prefix)/$(perfexecdir)
729STRACE_GROUPS_INSTDIR = $(prefix)/$(STRACE_GROUPS_DIR) 732STRACE_GROUPS_INSTDIR = $(prefix)/$(STRACE_GROUPS_DIR)
733tip_instdir = $(prefix)/$(tipdir)
730endif 734endif
731perfexec_instdir_SQ = $(subst ','\'',$(perfexec_instdir)) 735perfexec_instdir_SQ = $(subst ','\'',$(perfexec_instdir))
732STRACE_GROUPS_INSTDIR_SQ = $(subst ','\'',$(STRACE_GROUPS_INSTDIR)) 736STRACE_GROUPS_INSTDIR_SQ = $(subst ','\'',$(STRACE_GROUPS_INSTDIR))
737tip_instdir_SQ = $(subst ','\'',$(tip_instdir))
733 738
734# If we install to $(HOME) we keep the traceevent default: 739# If we install to $(HOME) we keep the traceevent default:
735# $(HOME)/.traceevent/plugins 740# $(HOME)/.traceevent/plugins
@@ -770,6 +775,7 @@ $(call detected_var,ETC_PERFCONFIG_SQ)
770$(call detected_var,STRACE_GROUPS_DIR_SQ) 775$(call detected_var,STRACE_GROUPS_DIR_SQ)
771$(call detected_var,prefix_SQ) 776$(call detected_var,prefix_SQ)
772$(call detected_var,perfexecdir_SQ) 777$(call detected_var,perfexecdir_SQ)
778$(call detected_var,tipdir_SQ)
773$(call detected_var,LIBDIR) 779$(call detected_var,LIBDIR)
774$(call detected_var,GTK_CFLAGS) 780$(call detected_var,GTK_CFLAGS)
775$(call detected_var,PERL_EMBED_CCOPTS) 781$(call detected_var,PERL_EMBED_CCOPTS)
diff --git a/tools/perf/perf.c b/tools/perf/perf.c
index cb1d2499c45c..a929618b8eb6 100644
--- a/tools/perf/perf.c
+++ b/tools/perf/perf.c
@@ -19,6 +19,8 @@
19#include "util/debug.h" 19#include "util/debug.h"
20#include <api/fs/tracing_path.h> 20#include <api/fs/tracing_path.h>
21#include <pthread.h> 21#include <pthread.h>
22#include <stdlib.h>
23#include <time.h>
22 24
23const char perf_usage_string[] = 25const char perf_usage_string[] =
24 "perf [--version] [--help] [OPTIONS] COMMAND [ARGS]"; 26 "perf [--version] [--help] [OPTIONS] COMMAND [ARGS]";
@@ -542,6 +544,8 @@ int main(int argc, const char **argv)
542 if (!cmd) 544 if (!cmd)
543 cmd = "perf-help"; 545 cmd = "perf-help";
544 546
547 srandom(time(NULL));
548
545 /* get debugfs/tracefs mount point from /proc/mounts */ 549 /* get debugfs/tracefs mount point from /proc/mounts */
546 tracing_path_mount(); 550 tracing_path_mount();
547 551
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
index aff0cfd83662..88b8f8d21f58 100644
--- a/tools/perf/util/util.c
+++ b/tools/perf/util/util.c
@@ -16,6 +16,8 @@
16#include <linux/kernel.h> 16#include <linux/kernel.h>
17#include <unistd.h> 17#include <unistd.h>
18#include "callchain.h" 18#include "callchain.h"
19#include "strlist.h"
20#include <subcmd/exec-cmd.h>
19 21
20struct callchain_param callchain_param = { 22struct callchain_param callchain_param = {
21 .mode = CHAIN_GRAPH_ABS, 23 .mode = CHAIN_GRAPH_ABS,
@@ -663,3 +665,28 @@ fetch_kernel_version(unsigned int *puint, char *str,
663 *puint = (version << 16) + (patchlevel << 8) + sublevel; 665 *puint = (version << 16) + (patchlevel << 8) + sublevel;
664 return 0; 666 return 0;
665} 667}
668
669const char *perf_tip(const char *dirpath)
670{
671 struct strlist *tips;
672 struct str_node *node;
673 char *tip = NULL;
674 struct strlist_config conf = {
675 .dirname = system_path(dirpath) ,
676 };
677
678 tips = strlist__new("tips.txt", &conf);
679 if (tips == NULL || strlist__nr_entries(tips) == 1) {
680 tip = (char *)"Cannot find tips.txt file";
681 goto out;
682 }
683
684 node = strlist__entry(tips, random() % strlist__nr_entries(tips));
685 if (asprintf(&tip, "Tip: %s", node->s) < 0)
686 tip = (char *)"Tip: get more memory! ;-)";
687
688out:
689 strlist__delete(tips);
690
691 return tip;
692}
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index 4b519c59bdc3..fe915e616f9b 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -342,4 +342,6 @@ int fetch_kernel_version(unsigned int *puint,
342#define KVER_FMT "%d.%d.%d" 342#define KVER_FMT "%d.%d.%d"
343#define KVER_PARAM(x) KVER_VERSION(x), KVER_PATCHLEVEL(x), KVER_SUBLEVEL(x) 343#define KVER_PARAM(x) KVER_VERSION(x), KVER_PATCHLEVEL(x), KVER_SUBLEVEL(x)
344 344
345const char *perf_tip(const char *dirpath);
346
345#endif /* GIT_COMPAT_UTIL_H */ 347#endif /* GIT_COMPAT_UTIL_H */