Skip to content

Commit

Permalink
libbpf-tools: fallback to tracefs mount point if debugfs is not mounted
Browse files Browse the repository at this point in the history
Change-Id: Icab8356f9b43b4f28ad77fa4b21e826f74a25be8
Signed-off-by: Mickey Zhu <[email protected]>
  • Loading branch information
michael-chuh authored and chenhengqi committed Jul 9, 2023
1 parent 8422cd4 commit 71b5141
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions libbpf-tools/trace_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -1074,6 +1074,30 @@ bool fentry_can_attach(const char *name, const char *mod)
return id > 0 && fentry_try_attach(id);
}

#define DEBUGFS "/sys/kernel/debug/tracing"
#define TRACEFS "/sys/kernel/tracing"

static bool use_debugfs(void)
{
static int has_debugfs = -1;

if (has_debugfs < 0)
has_debugfs = faccessat(AT_FDCWD, DEBUGFS, F_OK, AT_EACCESS) == 0;

return has_debugfs == 1;
}

static const char *tracefs_path(void)
{
return use_debugfs() ? DEBUGFS : TRACEFS;
}

static const char *tracefs_available_filter_functions(void)
{
return use_debugfs() ? DEBUGFS"/available_filter_functions" :
TRACEFS"/available_filter_functions";
}

bool kprobe_exists(const char *name)
{
char addr_range[256];
Expand Down Expand Up @@ -1101,7 +1125,7 @@ bool kprobe_exists(const char *name)
fclose(f);

avail_filter:
f = fopen("/sys/kernel/debug/tracing/available_filter_functions", "r");
f = fopen(tracefs_available_filter_functions(), "r");
if (!f)
goto slow_path;

Expand Down Expand Up @@ -1149,7 +1173,7 @@ bool tracepoint_exists(const char *category, const char *event)
{
char path[PATH_MAX];

snprintf(path, sizeof(path), "/sys/kernel/debug/tracing/events/%s/%s/format", category, event);
snprintf(path, sizeof(path), "%s/events/%s/%s/format", tracefs_path(), category, event);
if (!access(path, F_OK))
return true;
return false;
Expand Down

0 comments on commit 71b5141

Please sign in to comment.