Skip to content

Commit

Permalink
utils: Add logic to check for hardcoded tracefs paths first
Browse files Browse the repository at this point in the history
The logic added before was to use '/proc/mounts' to find
the tracefs path.

However, we can get faster performance by checking the
default tracefs path given in torvalds/linux@cc31004
before checking the previously added logic.

Signed-off-by: Gichoel Choi <gichoel3101@gmail.com>
  • Loading branch information
gichoel committed Aug 6, 2023
1 parent 9e03c5d commit c3c5df3
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion utils/tracefs.c
@@ -1,23 +1,32 @@
#include <fcntl.h>
#include <linux/magic.h>
#include <mntent.h>
#include <stdio.h>
#include <string.h>
#include <mntent.h>
#include <sys/vfs.h>

#include "utils/tracefs.h"
#include "utils/utils.h"

#define PROC_MOUNTS_DIR_PATH "/proc/mounts"
#define TRACEFS_DIR_PATH "/sys/kernel/tracing"

static char *TRACING_DIR = NULL;

static bool find_tracing_dir(void)
{
FILE *fp;
struct mntent *ent;
struct statfs fs;

if (TRACING_DIR)
return true;

if (!statfs(TRACEFS_DIR_PATH, &fs) && fs.f_type == TRACEFS_MAGIC) {
xasprintf(&TRACING_DIR, "%s", TRACEFS_DIR_PATH);
return true;
}

fp = setmntent(PROC_MOUNTS_DIR_PATH, "r");
if (fp == NULL)
return false;
Expand Down

0 comments on commit c3c5df3

Please sign in to comment.