Skip to content

Commit 34b7b0f

Browse files
namhyungacmel
authored andcommitted
perf tools: Fallback to srcdir/Documentation/tips.txt
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 <[email protected]> Cc: Andi Kleen <[email protected]> Cc: David Ahern <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Wang Nan <[email protected]> Link: http://lkml.kernel.org/r/[email protected] [ Make perf_tip() return NULL for ENOENT, making the fallback to really take place ] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 090cff3 commit 34b7b0f

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

tools/perf/builtin-report.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "util/tool.h"
2929

3030
#include <subcmd/parse-options.h>
31+
#include <subcmd/exec-cmd.h>
3132
#include "util/parse-events.h"
3233

3334
#include "util/thread.h"
@@ -433,7 +434,14 @@ static int report__browse_hists(struct report *rep)
433434
int ret;
434435
struct perf_session *session = rep->session;
435436
struct perf_evlist *evlist = session->evlist;
436-
const char *help = perf_tip(TIPDIR);
437+
const char *help = perf_tip(system_path(TIPDIR));
438+
439+
if (help == NULL) {
440+
/* fallback for people who don't install perf ;-) */
441+
help = perf_tip(DOCDIR);
442+
if (help == NULL)
443+
help = "Cannot load tips.txt file, please install perf!";
444+
}
437445

438446
switch (use_browser) {
439447
case 1:

tools/perf/util/util.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include <unistd.h>
1818
#include "callchain.h"
1919
#include "strlist.h"
20-
#include <subcmd/exec-cmd.h>
2120

2221
struct callchain_param callchain_param = {
2322
.mode = CHAIN_GRAPH_ABS,
@@ -672,14 +671,16 @@ const char *perf_tip(const char *dirpath)
672671
struct str_node *node;
673672
char *tip = NULL;
674673
struct strlist_config conf = {
675-
.dirname = system_path(dirpath) ,
674+
.dirname = dirpath,
675+
.file_only = true,
676676
};
677677

678678
tips = strlist__new("tips.txt", &conf);
679-
if (tips == NULL || strlist__nr_entries(tips) == 1) {
680-
tip = (char *)"Cannot find tips.txt file";
679+
if (tips == NULL)
680+
return errno == ENOENT ? NULL : "Tip: get more memory! ;-p";
681+
682+
if (strlist__nr_entries(tips) == 0)
681683
goto out;
682-
}
683684

684685
node = strlist__entry(tips, random() % strlist__nr_entries(tips));
685686
if (asprintf(&tip, "Tip: %s", node->s) < 0)

0 commit comments

Comments
 (0)