1 // SPDX-License-Identifier: GPL-2.0
9 #include <linux/string.h>
14 #include "tracing_path.h"
16 static char tracing_path[PATH_MAX] = "/sys/kernel/tracing";
18 static void __tracing_path_set(const char *tracing, const char *mountpoint)
20 snprintf(tracing_path, sizeof(tracing_path), "%s/%s",
24 static const char *tracing_path_tracefs_mount(void)
28 mnt = tracefs__mount();
32 __tracing_path_set("", mnt);
37 static const char *tracing_path_debugfs_mount(void)
41 mnt = debugfs__mount();
45 __tracing_path_set("tracing/", mnt);
50 const char *tracing_path_mount(void)
54 mnt = tracing_path_tracefs_mount();
58 mnt = tracing_path_debugfs_mount();
63 void tracing_path_set(const char *mntpt)
65 __tracing_path_set("tracing/", mntpt);
68 char *get_tracing_file(const char *name)
72 if (asprintf(&file, "%s/%s", tracing_path_mount(), name) < 0)
78 void put_tracing_file(char *file)
83 char *get_events_file(const char *name)
87 if (asprintf(&file, "%s/events/%s", tracing_path_mount(), name) < 0)
93 void put_events_file(char *file)
98 DIR *tracing_events__opendir(void)
101 char *path = get_tracing_file("events");
105 put_events_file(path);
111 int tracing_events__scandir_alphasort(struct dirent ***namelist)
113 char *path = get_tracing_file("events");
121 ret = scandir(path, namelist, NULL, alphasort);
122 put_events_file(path);
127 int tracing_path__strerror_open_tp(int err, char *buf, size_t size,
128 const char *sys, const char *name)
131 char filename[PATH_MAX];
133 snprintf(filename, PATH_MAX, "%s/%s", sys, name ?: "*");
138 * We will get here if we can't find the tracepoint, but one of
139 * debugfs or tracefs is configured, which means you probably
140 * want some tracepoint which wasn't compiled in your kernel.
143 if (debugfs__configured() || tracefs__configured()) {
145 if (!strncmp(filename, "sdt_", 4)) {
147 "Error:\tFile %s/events/%s not found.\n"
148 "Hint:\tSDT event cannot be directly recorded on.\n"
149 "\tPlease first use 'perf probe %s:%s' before recording it.\n",
150 tracing_path, filename, sys, name);
153 "Error:\tFile %s/events/%s not found.\n"
154 "Hint:\tPerhaps this kernel misses some CONFIG_ setting to enable this feature?.\n",
155 tracing_path, filename);
159 snprintf(buf, size, "%s",
160 "Error:\tUnable to find debugfs/tracefs\n"
161 "Hint:\tWas your kernel compiled with debugfs/tracefs support?\n"
162 "Hint:\tIs the debugfs/tracefs filesystem mounted?\n"
163 "Hint:\tTry 'sudo mount -t debugfs nodev /sys/kernel/debug'");
167 "Error:\tNo permissions to read %s/events/%s\n"
168 "Hint:\tTry 'sudo mount -o remount,mode=755 %s'\n",
169 tracing_path, filename, tracing_path_mount());
173 snprintf(buf, size, "%s", str_error_r(err, sbuf, sizeof(sbuf)));