Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect help message when uftrace fails to trace kernel functions #1471

Closed
shpark opened this issue Jul 10, 2022 · 5 comments
Closed

Incorrect help message when uftrace fails to trace kernel functions #1471

shpark opened this issue Jul 10, 2022 · 5 comments
Labels

Comments

@shpark
Copy link
Contributor

shpark commented Jul 10, 2022

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

@honggyukim
Copy link
Collaborator

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.

#797 (comment)

@shpark
Copy link
Contributor Author

shpark commented Jul 10, 2022

SG Let me work on this issue. I will soon send a PR 😄

@honggyukim
Copy link
Collaborator

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 :)

@namhyung
Copy link
Owner

namhyung commented Aug 1, 2022

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.

@honggyukim
Copy link
Collaborator

This issue is resolved by #1762 so I will close it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants