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

more issues in kernel function support #11

Closed
honggyukim opened this issue Oct 7, 2016 · 7 comments
Closed

more issues in kernel function support #11

honggyukim opened this issue Oct 7, 2016 · 7 comments

Comments

@honggyukim
Copy link
Collaborator

honggyukim commented Oct 7, 2016

@namhyung I've tested some features for kernel function tracing and have some comments as follows:

  1. time filter for kernel functions in record command doesn't filter-out kernel functions that spent less time than threshold. (maybe already aware of it)
  2. 'trace' trigger is not working for kernel functions
  3. graph command result seems to include kernel functions out of main function by default and --kernel-skip-out option is not working with graph command. This is tested when kernel function is given as last argument. (e.g. __do_page_fault)

Please have a look at it.

@namhyung
Copy link
Owner

namhyung commented Oct 9, 2016

  1. Yep, it should be supported by kernel. In fact kernel has an option for this but it only shows "exit" records so I decided not use it for now.
  2. it needs to be implemented in kernel. Did you mean at replay?
  3. it looks like a bug. I'll take a look it.

@honggyukim
Copy link
Collaborator Author

honggyukim commented Oct 9, 2016

2 . Yes, I mean 'trace' trigger support for replay command.

@namhyung
Copy link
Owner

For item 2, it was because filter address requires full 64 bit address but file format only saves 48 bit to reduce space. We need to sign-extend the address before giving it to filters. Does below patch fixes the issue?

diff --git a/utils/kernel.c b/utils/kernel.c
index d886cc0..4c8052c 100644
--- a/utils/kernel.c
+++ b/utils/kernel.c
@@ -872,13 +872,16 @@ static int read_kernel_cpu(struct ftrace_file_handle *handle, int cpu)
                        if (delta < handle->time_filter) {
                                struct ftrace_session *sess = first_session;
                                struct ftrace_trigger tr = {};
+                               unsigned long real_addr;

+                               /* filter match needs full (64-bit) address */
+                               real_addr = get_real_address(curr->addr);
                                /*
                                 * it might set TRACE trigger, which shows
                                 * function even if it's less than the time filter.
                                 */
                                ftrace_match_filter(&sess->filters,
-                                                   curr->addr, &tr);
+                                                   real_addr, &tr);
                                if (tr.flags & TRIGGER_FL_TRACE) {
                                        add_to_rstack_list(rstack_list, curr, NULL);
                                        break;

@honggyukim
Copy link
Collaborator Author

honggyukim commented Oct 11, 2016

It works fine with above patch. Thanks!

@namhyung
Copy link
Owner

For item 3, I think below patch should fix it.

diff --git a/cmd-graph.c b/cmd-graph.c
index 49460a5..fc207fd 100644
--- a/cmd-graph.c
+++ b/cmd-graph.c
@@ -394,6 +394,12 @@ static int build_graph(struct opts *opts, struct ftrace_file_handle *handle, cha
                struct sym *sym = NULL;
                char *name;

+               if (opts->kernel_skip_out) {
+                       /* skip kernel functions outside user functions */
+                       if (!task->user_stack_count && is_kernel_address(frs->addr))
+                               continue;
+               }
+
                if (!fstack_check_filter(task))
                        continue;

@namhyung
Copy link
Owner

@honggyukim can you please check the current code and close this issue if it's done?

@honggyukim
Copy link
Collaborator Author

@namhyung Yeap, I tested it and found that all the issues are resolved now. Sorry for the late answer.

namhyung pushed a commit that referenced this issue Jul 13, 2021
Sometimes it's useful to print backtrace or stacktrace by explicitly
write a request inside source code.

This patch implements stacktrace() function for this.  It's implemented
in two different versions.  In debug mode, it uses an external libunwind
library and it's output looks as follows.

  Stack trace:
    #1  0x000000449ef9 parse_argspec + 0x5d6
    #2  0x00000044b76c parse_argument_spec + 0x70
    #3  0x00000044bf58 setup_trigger_action + 0x146
    #4  0x0000004329e5 find_dwarf_argspec + 0x153
    #5  0x000000432b18 find_auto_argspec + 0x4c
    #6  0x00000044b102 add_filter + 0x87
    #7  0x00000044c1bf add_trigger_entry + 0x15c
    #8  0x00000044c61f setup_trigger + 0x413
    #9  0x00000044c85b uftrace_setup_argument + 0x59
    #10 0x00000044e053 build_arg_spec + 0x4f
    #11 0x00000042a6fe walk_sessions + 0x4a
    #12 0x00000044e12d setup_fstack_args + 0x7d
    #13 0x00000043a353 open_data_file + 0x3ff
    #14 0x0000004171a5 command_replay + 0x7a
    #15 0x000000407ba9 main + 0x4c3
    #16 0x7f4e1df33840 __libc_start_main + 0xf0
    #17 0x000000405499 _start + 0x29

In release mode, it's better not to rely on an external library, so it
just uses builtin backtrace() function, but it can't print static
functions.  The example output looks as follows.

  Stack trace:
    #1  uftrace(parse_argspec+0x4d1) [0x43dd01]
    #2  uftrace() [0x43e44c]
    #3  uftrace(setup_trigger_action+0xb0) [0x43f4e0]
    #4  uftrace() [0x42a933]
    #5  uftrace(find_auto_argspec+0x29) [0x42aff9]
    #6  uftrace() [0x43f2f7]
    #7  uftrace() [0x43fa20]
    #8  uftrace() [0x440140]
    #9  uftrace(walk_sessions+0x39) [0x4248a9]
    #10 uftrace(setup_fstack_args+0xa6) [0x440bb6]
    #11 uftrace(open_data_file+0x16f) [0x43012f]
    #12 uftrace(command_replay+0x59) [0x415ee9]
    #13 uftrace(main+0x544) [0x40adc4]
    #14 /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0) [0x7f8e3d944840]
    #15 uftrace(_start+0x29) [0x40aef9]

Signed-off-by: Honggyu Kim <honggyu.kp@gmail.com>
clementguidi pushed a commit to clementguidi/uftrace that referenced this issue Mar 6, 2023
Fix unit tests not compiling due to incompatible C standard and incomplete refactoring.

    Move index declaration outside of for statements
    Update function name and arguments in test cases

Reason: PFTOOLS-5439

* commit 'adbdf3ce30a6f8b80a5805754f047277a54b63ed':
  unittest: Fix trace on/off unit test
  unittest: Fix c99 compiler error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants