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

uftrace for uftrace #12

Open
honggyukim opened this issue Jul 14, 2019 · 1 comment
Open

uftrace for uftrace #12

honggyukim opened this issue Jul 14, 2019 · 1 comment

Comments

@honggyukim
Copy link
Owner

$ uftrace -P. -t 30ms ./uftrace record t-abc
# DURATION     TID     FUNCTION
            [189150] | main() {
            [189150] |   command_record() {
            [189150] |     create_directory() {
            [189150] |       can_remove_directory() {
            [189150] |         read() {
  81.503 ms [189150] |           /* linux:schedule */
  81.532 ms [189150] |         } /* read */
  81.555 ms [189150] |       } /* can_remove_directory */
            [189150] |       remove_directory() {
            [189150] |         readdir() {
  96.656 ms [189150] |           /* linux:schedule */
  96.746 ms [189150] |         } /* readdir */
 123.680 ms [189150] |       } /* remove_directory */
 205.425 ms [189150] |     } /* create_directory */
            [189150] |     do_main_loop() {
            [189164] | } /* fork */
            [189164] | do_child_exec() {
            [189164] |   execv() {
            [189150] |       finish_writers() {
  85.261 ms [189150] |         scandir();
  88.278 ms [189150] |       } /* finish_writers */
            [189150] |       load_module_symtabs() {
  56.185 ms [189150] |         load_module_symtab();
  97.776 ms [189150] |       } /* load_module_symtabs */
 216.023 ms [189150] |     } /* do_main_loop */
 422.099 ms [189150] |   } /* command_record */
 422.242 ms [189150] | } /* main */
@honggyukim
Copy link
Owner Author

$ uftrace -P. -t 25ms -a ./uftrace record t-abc ;
# DURATION     TID     FUNCTION
            [190030] | main(3, 0x7ffdb5bbb7b8) {
            [190030] |   command_record(1, 0x7ffdb5bbb7c8, 0x7ffdb5bbb570) {
            [190030] |     do_main_loop(4, 0x7ffdb5bbb570, 0x2e659) {
            [190041] | } = 0; /* fork */
            [190041] | do_child_exec(4, 0x7ffdb5bbb570, 1, 0x7ffdb5bbb7c8) {
            [190042] | writer_thread(0x2520790) {
            [190042] |   /* linux:task-name (name=WriterThread) */
            [190042] |   handle_pollfd(0x7f8d48116900, 0x2520790, 1, 1, 0, 1000) {
            [190042] |     poll(0x7f8d48116900, 5, 1000) {
            [190042] |       /* linux:sched-out */
            [190043] | writer_thread(0x2520ad0) {
            [190043] |   /* linux:task-name (name=WriterThread) */
            [190041] |   execv("t-abc") {
  25.152 ms [190042] |       /* linux:sched-in */
  25.283 ms [190042] |     } = 4; /* poll */
  25.290 ms [190042] |   } = 0; /* handle_pollfd */
            [190030] |       finish_writers(0x7ffdb5bbb190, 0x7ffdb5bbb570) {
  25.162 ms [190043] | } = 0; /* writer_thread */
  25.504 ms [190042] | } = 0; /* writer_thread */
 101.071 ms [190030] |         scandir();
 104.237 ms [190030] |       } /* finish_writers */
            [190030] |       load_module_symtabs(0x7ffdb5bbb150) {
  79.944 ms [190030] |         load_module_symtab(0x7ffdb5bbb150, "/lib/x86_64-linux-gnu/libc-2.23.so") = 0x25519f0;
 137.825 ms [190030] |       } /* load_module_symtabs */
 279.637 ms [190030] |     } = 0; /* do_main_loop */
 282.197 ms [190030] |   } = 0; /* command_record */
 282.716 ms [190030] | } = 0; /* main */

honggyukim added a commit that referenced this issue Jul 11, 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 <[email protected]>
honggyukim added a commit that referenced this issue Jul 11, 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 <[email protected]>
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

1 participant