perf tools: Fallback to srcdir/Documentation/tips.txt
authorNamhyung Kim <namhyung@kernel.org>
Sat, 9 Jan 2016 10:16:29 +0000 (19:16 +0900)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 12 Jan 2016 15:42:08 +0000 (12:42 -0300)
Some people don't install perf, but just use compiled version in the
source.  Fallback to lookup the source directory for those poor guys. :)

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/r/1452334589-8782-4-git-send-email-namhyung@kernel.org
[ Make perf_tip() return NULL for ENOENT, making the fallback to really take place ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-report.c
tools/perf/util/util.c

index d5a42ee12529b97fdcb2b0a74ece8bf2db701550..2bf537f190a026952bd63126e9c37def827e9914 100644 (file)
@@ -28,6 +28,7 @@
 #include "util/tool.h"
 
 #include <subcmd/parse-options.h>
+#include <subcmd/exec-cmd.h>
 #include "util/parse-events.h"
 
 #include "util/thread.h"
@@ -433,7 +434,14 @@ static int report__browse_hists(struct report *rep)
        int ret;
        struct perf_session *session = rep->session;
        struct perf_evlist *evlist = session->evlist;
-       const char *help = perf_tip(TIPDIR);
+       const char *help = perf_tip(system_path(TIPDIR));
+
+       if (help == NULL) {
+               /* fallback for people who don't install perf ;-) */
+               help = perf_tip(DOCDIR);
+               if (help == NULL)
+                       help = "Cannot load tips.txt file, please install perf!";
+       }
 
        switch (use_browser) {
        case 1:
index 88b8f8d21f58e6fb7c2143788528ff764b06f012..ead9509835d23e2aee29b9f3548613973a5937fb 100644 (file)
@@ -17,7 +17,6 @@
 #include <unistd.h>
 #include "callchain.h"
 #include "strlist.h"
-#include <subcmd/exec-cmd.h>
 
 struct callchain_param callchain_param = {
        .mode   = CHAIN_GRAPH_ABS,
@@ -672,14 +671,16 @@ const char *perf_tip(const char *dirpath)
        struct str_node *node;
        char *tip = NULL;
        struct strlist_config conf = {
-               .dirname = system_path(dirpath) ,
+               .dirname = dirpath,
+               .file_only = true,
        };
 
        tips = strlist__new("tips.txt", &conf);
-       if (tips == NULL || strlist__nr_entries(tips) == 1) {
-               tip = (char *)"Cannot find tips.txt file";
+       if (tips == NULL)
+               return errno == ENOENT ? NULL : "Tip: get more memory! ;-p";
+
+       if (strlist__nr_entries(tips) == 0)
                goto out;
-       }
 
        node = strlist__entry(tips, random() % strlist__nr_entries(tips));
        if (asprintf(&tip, "Tip: %s", node->s) < 0)