From c3c5df3a80c0ae40a618fd1e127a87e40c8ca9fa Mon Sep 17 00:00:00 2001 From: Gichoel Choi Date: Sun, 6 Aug 2023 22:52:06 +0900 Subject: [PATCH] utils: Add logic to check for hardcoded tracefs paths first 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 --- utils/tracefs.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/utils/tracefs.c b/utils/tracefs.c index f2270fe1d..08ab073e1 100644 --- a/utils/tracefs.c +++ b/utils/tracefs.c @@ -1,12 +1,15 @@ #include +#include +#include #include #include -#include +#include #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; @@ -14,10 +17,16 @@ 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;