uftrace
uftrace copied to clipboard
Incorrect help message when uftrace fails to trace kernel functions
I tried to trace kernel functions with uftrace using the following command: sudo uftrace record -k ./a.out
.
It failed to trace kernel function, saying that:
WARN: kernel tracing disabled due to an error
is CONFIG_FUNCTION_GRAPH_TRACER enabled in the kernel?
However, it seemed that the config was enabled for my setting (Debian 10 running inside a Docker container on MacOS Monterey 12.0.1 host on M1 pro chip):
vscode ➜ /com.docker.devenvironments.code/samples (master ✗) $ zcat /proc/config.gz | rg -i graph_tracer
CONFIG_HAVE_FUNCTION_GRAPH_TRACER=y
CONFIG_FUNCTION_GRAPH_TRACER=y
vscode ➜ /com.docker.devenvironments.code/samples (master ✗) $ uname -r
5.10.104-linuxkit
After looking at more verbose logs, I concluded that the root cause was prolly the absence of tracing_on
file on proper path:
vscode ➜ /com.docker.devenvironments.code/samples (master ✗) $ sudo uftrace record -vv -k ./a.out
uftrace: running uftrace v0.12-43-g5f03a ( aarch64 dwarf python luajit tui perf sched dynamic )
uftrace: checking binary ./a.out
uftrace: removing uftrace.data.old directory
kernel: cannot open tracing file: tracing_on: No such file or directory
kernel: failed to reset tracing files
WARN: kernel tracing disabled due to an error
is CONFIG_FUNCTION_GRAPH_TRACER enabled in the kernel?
uftrace: skipping perf event due to error: Operation not permitted
uftrace: creating 2 thread(s) for recording
uftrace: start writer thread 1
uftrace: using /usr/local/lib/libmcount.so library for tracing
uftrace: start writer thread 0
mcount: initializing mcount library
Imho the error message would better be refined to provide better suggestions (e.g, mount debugfs, etc.).
Maybe related to #797
Hi @shpark, thanks for the report. Could you please send a PR by detecting mount point of debugfs? There is a nice example at https://stackoverflow.com/questions/9280759/linux-function-to-get-mount-points.
#include <stdio.h>
#include <stdlib.h>
#include <mntent.h>
int main(void)
{
struct mntent *ent;
FILE *aFile;
aFile = setmntent("/proc/mounts", "r");
if (aFile == NULL) {
perror("setmntent");
exit(1);
}
while (NULL != (ent = getmntent(aFile))) {
printf("%s %s\n", ent->mnt_fsname, ent->mnt_dir);
}
endmntent(aFile);
}
If that is difficult, then you can make a workaround based on my previous comment?
If so, can we just try /sys/kernel/tracing/ again if /sys/kernel/debug/tracing/ doesn't exist? I know using mount is the right way, but it's just to simply handle the problem.
https://github.com/namhyung/uftrace/issues/797#issuecomment-528738208
SG Let me work on this issue. I will soon send a PR 😄
I just worried if mntent.h
is available in android, but it's included in android bionic as well.
https://cs.android.com/android/platform/superproject/+/master:bionic/libc/include/mntent.h;drc=master
So we can go ahead with it. @shpark Please send a PR then :)
It could check the error code and display warnings based on it. It might do additional checks like if tracefs is mounted or if kernel config has a specific feature.
This issue is resolved by #1762 so I will close it.