diff options
author | Jason Baron <jbaron@redhat.com> | 2009-07-21 14:16:29 -0400 |
---|---|---|
committer | Peter Zijlstra <a.p.zijlstra@chello.nl> | 2009-07-22 12:05:57 -0400 |
commit | 5beeded123c5befa21f1c6e16219f2a3eb7dd197 (patch) | |
tree | 4ac812126910994516300c53171c7267b97f6f5d /tools/perf/perf.c | |
parent | f6bdafef2ab911f03321fa83d8da1df99878009e (diff) |
perf_counter: Detect debugfs location
If "/sys/kernel/debug" is not a debugfs mount point, search for the debugfs
filesystem in /proc/mounts, but also allows the user to specify
'--debugfs-dir=blah' or set the environment variable: 'PERF_DEBUGFS_DIR'
Signed-off-by: Jason Baron <jbaron@redhat.com>
[ also made it probe "/debug" by default ]
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
LKML-Reference: <20090721181629.GA3094@redhat.com>
Diffstat (limited to 'tools/perf/perf.c')
-rw-r--r-- | tools/perf/perf.c | 77 |
1 files changed, 76 insertions, 1 deletions
diff --git a/tools/perf/perf.c b/tools/perf/perf.c index c5656784c61d..31982ad064b4 100644 --- a/tools/perf/perf.c +++ b/tools/perf/perf.c | |||
@@ -12,6 +12,8 @@ | |||
12 | #include "util/cache.h" | 12 | #include "util/cache.h" |
13 | #include "util/quote.h" | 13 | #include "util/quote.h" |
14 | #include "util/run-command.h" | 14 | #include "util/run-command.h" |
15 | #include "util/parse-events.h" | ||
16 | #include "util/string.h" | ||
15 | 17 | ||
16 | const char perf_usage_string[] = | 18 | const char perf_usage_string[] = |
17 | "perf [--version] [--help] COMMAND [ARGS]"; | 19 | "perf [--version] [--help] COMMAND [ARGS]"; |
@@ -25,6 +27,8 @@ struct pager_config { | |||
25 | int val; | 27 | int val; |
26 | }; | 28 | }; |
27 | 29 | ||
30 | static char debugfs_mntpt[MAXPATHLEN]; | ||
31 | |||
28 | static int pager_command_config(const char *var, const char *value, void *data) | 32 | static int pager_command_config(const char *var, const char *value, void *data) |
29 | { | 33 | { |
30 | struct pager_config *c = data; | 34 | struct pager_config *c = data; |
@@ -56,6 +60,15 @@ static void commit_pager_choice(void) { | |||
56 | } | 60 | } |
57 | } | 61 | } |
58 | 62 | ||
63 | static void set_debugfs_path(void) | ||
64 | { | ||
65 | char *path; | ||
66 | |||
67 | path = getenv(PERF_DEBUGFS_ENVIRONMENT); | ||
68 | snprintf(debugfs_path, MAXPATHLEN, "%s/%s", path ?: debugfs_mntpt, | ||
69 | "tracing/events"); | ||
70 | } | ||
71 | |||
59 | static int handle_options(const char*** argv, int* argc, int* envchanged) | 72 | static int handle_options(const char*** argv, int* argc, int* envchanged) |
60 | { | 73 | { |
61 | int handled = 0; | 74 | int handled = 0; |
@@ -122,6 +135,22 @@ static int handle_options(const char*** argv, int* argc, int* envchanged) | |||
122 | setenv(PERF_WORK_TREE_ENVIRONMENT, cmd + 12, 1); | 135 | setenv(PERF_WORK_TREE_ENVIRONMENT, cmd + 12, 1); |
123 | if (envchanged) | 136 | if (envchanged) |
124 | *envchanged = 1; | 137 | *envchanged = 1; |
138 | } else if (!strcmp(cmd, "--debugfs-dir")) { | ||
139 | if (*argc < 2) { | ||
140 | fprintf(stderr, "No directory given for --debugfs-dir.\n"); | ||
141 | usage(perf_usage_string); | ||
142 | } | ||
143 | strncpy(debugfs_mntpt, (*argv)[1], MAXPATHLEN); | ||
144 | debugfs_mntpt[MAXPATHLEN - 1] = '\0'; | ||
145 | if (envchanged) | ||
146 | *envchanged = 1; | ||
147 | (*argv)++; | ||
148 | (*argc)--; | ||
149 | } else if (!prefixcmp(cmd, "--debugfs-dir=")) { | ||
150 | strncpy(debugfs_mntpt, cmd + 14, MAXPATHLEN); | ||
151 | debugfs_mntpt[MAXPATHLEN - 1] = '\0'; | ||
152 | if (envchanged) | ||
153 | *envchanged = 1; | ||
125 | } else { | 154 | } else { |
126 | fprintf(stderr, "Unknown option: %s\n", cmd); | 155 | fprintf(stderr, "Unknown option: %s\n", cmd); |
127 | usage(perf_usage_string); | 156 | usage(perf_usage_string); |
@@ -228,6 +257,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv) | |||
228 | if (use_pager == -1 && p->option & USE_PAGER) | 257 | if (use_pager == -1 && p->option & USE_PAGER) |
229 | use_pager = 1; | 258 | use_pager = 1; |
230 | commit_pager_choice(); | 259 | commit_pager_choice(); |
260 | set_debugfs_path(); | ||
231 | 261 | ||
232 | status = p->fn(argc, argv, prefix); | 262 | status = p->fn(argc, argv, prefix); |
233 | if (status) | 263 | if (status) |
@@ -346,6 +376,49 @@ static int run_argv(int *argcp, const char ***argv) | |||
346 | return done_alias; | 376 | return done_alias; |
347 | } | 377 | } |
348 | 378 | ||
379 | /* mini /proc/mounts parser: searching for "^blah /mount/point debugfs" */ | ||
380 | static void get_debugfs_mntpt(void) | ||
381 | { | ||
382 | FILE *file; | ||
383 | char fs_type[100]; | ||
384 | char debugfs[MAXPATHLEN]; | ||
385 | |||
386 | /* | ||
387 | * try the standard location | ||
388 | */ | ||
389 | if (valid_debugfs_mount("/sys/kernel/debug/") == 0) { | ||
390 | strcpy(debugfs_mntpt, "/sys/kernel/debug/"); | ||
391 | return; | ||
392 | } | ||
393 | |||
394 | /* | ||
395 | * try the sane location | ||
396 | */ | ||
397 | if (valid_debugfs_mount("/debug/") == 0) { | ||
398 | strcpy(debugfs_mntpt, "/debug/"); | ||
399 | return; | ||
400 | } | ||
401 | |||
402 | /* | ||
403 | * give up and parse /proc/mounts | ||
404 | */ | ||
405 | file = fopen("/proc/mounts", "r"); | ||
406 | if (file == NULL) | ||
407 | return; | ||
408 | |||
409 | while (fscanf(file, "%*s %" | ||
410 | STR(MAXPATHLEN) | ||
411 | "s %99s %*s %*d %*d\n", | ||
412 | debugfs, fs_type) == 2) { | ||
413 | if (strcmp(fs_type, "debugfs") == 0) | ||
414 | break; | ||
415 | } | ||
416 | fclose(file); | ||
417 | if (strcmp(fs_type, "debugfs") == 0) { | ||
418 | strncpy(debugfs_mntpt, debugfs, MAXPATHLEN); | ||
419 | debugfs_mntpt[MAXPATHLEN - 1] = '\0'; | ||
420 | } | ||
421 | } | ||
349 | 422 | ||
350 | int main(int argc, const char **argv) | 423 | int main(int argc, const char **argv) |
351 | { | 424 | { |
@@ -354,7 +427,8 @@ int main(int argc, const char **argv) | |||
354 | cmd = perf_extract_argv0_path(argv[0]); | 427 | cmd = perf_extract_argv0_path(argv[0]); |
355 | if (!cmd) | 428 | if (!cmd) |
356 | cmd = "perf-help"; | 429 | cmd = "perf-help"; |
357 | 430 | /* get debugfs mount point from /proc/mounts */ | |
431 | get_debugfs_mntpt(); | ||
358 | /* | 432 | /* |
359 | * "perf-xxxx" is the same as "perf xxxx", but we obviously: | 433 | * "perf-xxxx" is the same as "perf xxxx", but we obviously: |
360 | * | 434 | * |
@@ -377,6 +451,7 @@ int main(int argc, const char **argv) | |||
377 | argc--; | 451 | argc--; |
378 | handle_options(&argv, &argc, NULL); | 452 | handle_options(&argv, &argc, NULL); |
379 | commit_pager_choice(); | 453 | commit_pager_choice(); |
454 | set_debugfs_path(); | ||
380 | if (argc > 0) { | 455 | if (argc > 0) { |
381 | if (!prefixcmp(argv[0], "--")) | 456 | if (!prefixcmp(argv[0], "--")) |
382 | argv[0] += 2; | 457 | argv[0] += 2; |