diff options
Diffstat (limited to 'tools/perf/util/util.c')
-rw-r--r-- | tools/perf/util/util.c | 56 |
1 files changed, 4 insertions, 52 deletions
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c index f7adf1203df1..d33c34196a5a 100644 --- a/tools/perf/util/util.c +++ b/tools/perf/util/util.c | |||
@@ -34,6 +34,7 @@ bool test_attr__enabled; | |||
34 | bool perf_host = true; | 34 | bool perf_host = true; |
35 | bool perf_guest = false; | 35 | bool perf_guest = false; |
36 | 36 | ||
37 | char tracing_path[PATH_MAX + 1] = "/sys/kernel/debug/tracing"; | ||
37 | char tracing_events_path[PATH_MAX + 1] = "/sys/kernel/debug/tracing/events"; | 38 | char tracing_events_path[PATH_MAX + 1] = "/sys/kernel/debug/tracing/events"; |
38 | 39 | ||
39 | void event_attr_init(struct perf_event_attr *attr) | 40 | void event_attr_init(struct perf_event_attr *attr) |
@@ -391,6 +392,8 @@ void set_term_quiet_input(struct termios *old) | |||
391 | 392 | ||
392 | static void set_tracing_events_path(const char *tracing, const char *mountpoint) | 393 | static void set_tracing_events_path(const char *tracing, const char *mountpoint) |
393 | { | 394 | { |
395 | snprintf(tracing_path, sizeof(tracing_path), "%s/%s", | ||
396 | mountpoint, tracing); | ||
394 | snprintf(tracing_events_path, sizeof(tracing_events_path), "%s/%s%s", | 397 | snprintf(tracing_events_path, sizeof(tracing_events_path), "%s/%s%s", |
395 | mountpoint, tracing, "events"); | 398 | mountpoint, tracing, "events"); |
396 | } | 399 | } |
@@ -440,62 +443,11 @@ void perf_debugfs_set_path(const char *mntpt) | |||
440 | set_tracing_events_path("tracing/", mntpt); | 443 | set_tracing_events_path("tracing/", mntpt); |
441 | } | 444 | } |
442 | 445 | ||
443 | static const char *find_tracefs(void) | ||
444 | { | ||
445 | const char *path = __perf_tracefs_mount(NULL); | ||
446 | |||
447 | return path; | ||
448 | } | ||
449 | |||
450 | static const char *find_debugfs(void) | ||
451 | { | ||
452 | const char *path = __perf_debugfs_mount(NULL); | ||
453 | |||
454 | if (!path) | ||
455 | fprintf(stderr, "Your kernel does not support the debugfs filesystem"); | ||
456 | |||
457 | return path; | ||
458 | } | ||
459 | |||
460 | /* | ||
461 | * Finds the path to the debugfs/tracing | ||
462 | * Allocates the string and stores it. | ||
463 | */ | ||
464 | const char *find_tracing_dir(void) | ||
465 | { | ||
466 | const char *tracing_dir = ""; | ||
467 | static char *tracing; | ||
468 | static int tracing_found; | ||
469 | const char *debugfs; | ||
470 | |||
471 | if (tracing_found) | ||
472 | return tracing; | ||
473 | |||
474 | debugfs = find_tracefs(); | ||
475 | if (!debugfs) { | ||
476 | tracing_dir = "/tracing"; | ||
477 | debugfs = find_debugfs(); | ||
478 | if (!debugfs) | ||
479 | return NULL; | ||
480 | } | ||
481 | |||
482 | if (asprintf(&tracing, "%s%s", debugfs, tracing_dir) < 0) | ||
483 | return NULL; | ||
484 | |||
485 | tracing_found = 1; | ||
486 | return tracing; | ||
487 | } | ||
488 | |||
489 | char *get_tracing_file(const char *name) | 446 | char *get_tracing_file(const char *name) |
490 | { | 447 | { |
491 | const char *tracing; | ||
492 | char *file; | 448 | char *file; |
493 | 449 | ||
494 | tracing = find_tracing_dir(); | 450 | if (asprintf(&file, "%s/%s", tracing_path, name) < 0) |
495 | if (!tracing) | ||
496 | return NULL; | ||
497 | |||
498 | if (asprintf(&file, "%s/%s", tracing, name) < 0) | ||
499 | return NULL; | 451 | return NULL; |
500 | 452 | ||
501 | return file; | 453 | return file; |