Skip to contentSkip to conversation

get function names with lttng-ust-cyg-profile

DISCUSSION Liu, Changcheng via lttng-dev 1 participant 8 messages Jun 23, 2020 – Jun 27, 2020

lore
Share & tools
lore
#0 lore raw

Hi all,
I'm trying to use lttng-ust-cyg-profile to trace program.
Does anyone know how to get function names and offset through lttng-ust-cyg-profile?

   In below example, the babeltrace could only get the function entry/exit value.
   1. Source program: instrument.c
         1 #include <stdio.h>
         2 
         3 int add3(int val) {
         4         return val + 3;
         5 }
         6 
         7 int main(int argc, char **argv) {
         8     int x = 4;
         9     
        10     puts("Press Enter to continue...");
        11     getchar();
        12     
        13     x = add3(x);
        14     
        15     return 0;
        16 }

2. build source code:

        $ gcc -g -finstrument-functions instrument.c -o instrument

3. run program:

       $ LD_PRELOAD=/usr/lib/x86_64-linux-gnu/liblttng-ust-cyg-profile.so ./instrument

4. start trace process:

       trace@trace:~/cc$ sudo lttng create instrument
       Session instrument created.
       Traces will be output to /root/lttng-traces/instrument-20200623-222917
       trace@trace:~/cc$ sudo lttng enable-channel user_func_trace --userspace
       UST channel user_func_trace enabled for session instrument
       trace@trace:~/cc$ sudo lttng enable-event --userspace lttng_ust_cyg_profile:func_entry --channel user_func_trace
       UST event lttng_ust_cyg_profile:func_entry created in channel user_func_trace
       trace@trace:~/cc$ sudo lttng enable-event --userspace lttng_ust_cyg_profile:func_exit --channel user_func_trace
       UST event lttng_ust_cyg_profile:func_exit created in channel user_func_trace
       trace@trace:~/cc$ sudo lttng start
       Tracing started for session instrument
       trace@trace:~/cc$ sudo lttng destroy
       Destroying session instrument..
       Session instrument destroyed
       trace@trace:~/cc$ sudo babeltrace /root/lttng-traces/instrument-20200623-222917
       [22:29:55.388607059] (+?.?????????) trace lttng_ust_cyg_profile:func_entry: { cpu_id = 2 }, { addr = 0x5625C88B01A9, call_site = 0x5625C88B0237 }
       [22:29:55.388612293] (+0.000005234) trace lttng_ust_cyg_profile:func_exit: { cpu_id = 2 }, { addr = 0x5625C88B01A9, call_site = 0x5625C88B0237 }
       [22:29:55.388613215] (+0.000000922) trace lttng_ust_cyg_profile:func_exit: { cpu_id = 2 }, { addr = 0x5625C88B01EE, call_site = 0x7FE40BD5C0B3 }

B.R.
Changcheng

#1 lore raw

Hi,

You have the pointers that are traced. Babeltrace is doing exactly what it should as far as I know.

You could use the command 'nm' to get your symbols and look them up. I am sure Babeltrace can do this from a python level. You could also use a GUI based trace viewer to get the information.

Hope that helps.
Matthew
________________________________
From: lttng-dev <[email protected]> on behalf of Liu, Changcheng via lttng-dev <[email protected]>
Sent: Tuesday, June 23, 2020 10:37 AM
To: [email protected] <[email protected]>
Cc: [email protected] <[email protected]>
Subject: [lttng-dev] get function names with lttng-ust-cyg-profile

Hi all,
I'm trying to use lttng-ust-cyg-profile to trace program.
Does anyone know how to get function names and offset through lttng-ust-cyg-profile?

   In below example, the babeltrace could only get the function entry/exit value.
   1. Source program: instrument.c
         1 #include <stdio.h>
         2
         3 int add3(int val) {
         4         return val + 3;
         5 }
         6
         7 int main(int argc, char **argv) {
         8     int x = 4;
         9
        10     puts("Press Enter to continue...");
        11     getchar();
        12
        13     x = add3(x);
        14
        15     return 0;
        16 }

2. build source code:

        $ gcc -g -finstrument-functions instrument.c -o instrument

3. run program:

       $ LD_PRELOAD=/usr/lib/x86_64-linux-gnu/liblttng-ust-cyg-profile.so ./instrument

4. start trace process:

       trace@trace:~/cc$ sudo lttng create instrument
       Session instrument created.
       Traces will be output to /root/lttng-traces/instrument-20200623-222917
       trace@trace:~/cc$ sudo lttng enable-channel user_func_trace --userspace
       UST channel user_func_trace enabled for session instrument
       trace@trace:~/cc$ sudo lttng enable-event --userspace lttng_ust_cyg_profile:func_entry --channel user_func_trace
       UST event lttng_ust_cyg_profile:func_entry created in channel user_func_trace
       trace@trace:~/cc$ sudo lttng enable-event --userspace lttng_ust_cyg_profile:func_exit --channel user_func_trace
       UST event lttng_ust_cyg_profile:func_exit created in channel user_func_trace
       trace@trace:~/cc$ sudo lttng start
       Tracing started for session instrument
       trace@trace:~/cc$ sudo lttng destroy
       Destroying session instrument..
       Session instrument destroyed
       trace@trace:~/cc$ sudo babeltrace /root/lttng-traces/instrument-20200623-222917
       [22:29:55.388607059] (+?.?????????) trace lttng_ust_cyg_profile:func_entry: { cpu_id = 2 }, { addr = 0x5625C88B01A9, call_site = 0x5625C88B0237 }
       [22:29:55.388612293] (+0.000005234) trace lttng_ust_cyg_profile:func_exit: { cpu_id = 2 }, { addr = 0x5625C88B01A9, call_site = 0x5625C88B0237 }
       [22:29:55.388613215] (+0.000000922) trace lttng_ust_cyg_profile:func_exit: { cpu_id = 2 }, { addr = 0x5625C88B01EE, call_site = 0x7FE40BD5C0B3 }

B.R.
Changcheng
_______________________________________________
lttng-dev mailing list
[email protected]
https://protect2.fireeye.com/v1/url?k=98478753-c6e73d3d-9847c7c8-869a14f4b08c-41638b2508ab85dd&q=1&e=703483a0-63a9-4269-ac8e-c1fc5a57edad&u=https%3A%2F%2Flists.lttng.org%2Fcgi-bin%2Fmailman%2Flistinfo%2Flttng-dev

_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

#2 lore raw

Hi,

Babeltrace is doing exactly what it should as far as I know.

Quoted 1 line

yes, but babeltrace *can* provide the information if:

* ip and vpid contexts are enabled (for userspace), e.g.

$ lttng add-context --userspace --type=ip --type=vpid

* LTTng state dump events are enabled, e.g.

$ lttng enable-event --userspace 'lttng_ust_statedump:*'

see this (from bt2 but it also applies to bt1):
https://babeltrace.org/docs/v2.0/man7/babeltrace2-filter.lttng-utils.debug-info.7/#doc-lttng-prereq

Note that the Python bindings for babeltrace don't provide/expose this debug info.

Christophe

Quoted 95 lines · Matthew Khouzam via lttng-dev

Hi,

You have the pointers that are traced. Babeltrace is doing exactly what it should as far as I know.

You could use the command 'nm' to get your symbols and look them up. I am sure Babeltrace can do this from a python level. You could also use a GUI based trace viewer to get the information.

Hope that helps.
Matthew
------------------------------
*From:* lttng-dev <[email protected]> on behalf of Liu, Changcheng via lttng-dev <[email protected]>
*Sent:* Tuesday, June 23, 2020 10:37 AM
*To:* [email protected] <[email protected]> *Cc:* [email protected] <[email protected]> *Subject:* [lttng-dev] get function names with lttng-ust-cyg-profile

Hi all,
I'm trying to use lttng-ust-cyg-profile to trace program. Does anyone know how to get function names and offset through
lttng-ust-cyg-profile?

In below example, the babeltrace could only get the function entry/exit
value.
1. Source program: instrument.c

         1 #include <stdio.h>
         2
         3 int add3(int val) {
         4         return val + 3;
         5 }
         6
         7 int main(int argc, char **argv) {
         8     int x = 4;
         9
        10     puts("Press Enter to continue...");
        11     getchar();
        12
        13     x = add3(x);
        14
        15     return 0;
        16 }

2. build source code:

        $ gcc -g -finstrument-functions instrument.c -o instrument

3. run program:

       $ LD_PRELOAD=/usr/lib/x86_64-linux-gnu/liblttng-ust-cyg-profile.so
./instrument

4. start trace process:

       trace@trace:~/cc$ sudo lttng create instrument
       Session instrument created.
       Traces will be output to
/root/lttng-traces/instrument-20200623-222917
       trace@trace:~/cc$ sudo lttng enable-channel user_func_trace
--userspace
       UST channel user_func_trace enabled for session instrument
       trace@trace:~/cc$ sudo lttng enable-event --userspace
lttng_ust_cyg_profile:func_entry --channel user_func_trace
       UST event lttng_ust_cyg_profile:func_entry created in channel
user_func_trace
       trace@trace:~/cc$ sudo lttng enable-event --userspace
lttng_ust_cyg_profile:func_exit --channel user_func_trace
       UST event lttng_ust_cyg_profile:func_exit created in channel
user_func_trace
       trace@trace:~/cc$ sudo lttng start
       Tracing started for session instrument
       trace@trace:~/cc$ sudo lttng destroy
       Destroying session instrument..
       Session instrument destroyed
       trace@trace:~/cc$ sudo babeltrace
/root/lttng-traces/instrument-20200623-222917
       [22:29:55.388607059] (+?.?????????) trace
lttng_ust_cyg_profile:func_entry: { cpu_id = 2 }, { addr = 0x5625C88B01A9,
call_site = 0x5625C88B0237 }
       [22:29:55.388612293] (+0.000005234) trace
lttng_ust_cyg_profile:func_exit: { cpu_id = 2 }, { addr = 0x5625C88B01A9,
call_site = 0x5625C88B0237 }
       [22:29:55.388613215] (+0.000000922) trace
lttng_ust_cyg_profile:func_exit: { cpu_id = 2 }, { addr = 0x5625C88B01EE,
call_site = 0x7FE40BD5C0B3 }

B.R.
Changcheng
_______________________________________________
lttng-dev mailing list
[email protected]

Quoted 6 lines

https://protect2.fireeye.com/v1/url?k=98478753-c6e73d3d-9847c7c8-869a14f4b08c-41638b2508ab85dd&q=1&e=703483a0-63a9-4269-ac8e-c1fc5a57edad&u=https%3A%2F%2Flists.lttng.org%2Fcgi-bin%2Fmailman%2Flistinfo%2Flttng-dev
_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

#3 lore raw
Quoted 3 lines

You could use the command 'nm' to get your symbols and look them up. I am sure Babeltrace can do this from a python level. You could also use a GUI based trace viewer to get the information.

nm only shows the linked address, but the traced address are the loaded address in memory. So, they're different.
For example:
trace@trace:~/cc$ nm instrument | grep 'add3\|main' 00000000000011a9 T add3
00000000000011ee T main

@Christophe:
Do you mean that babeltrace2 can help get the function name and call site offset?

B.R.
Changcheng

Quoted 94 lines · Christophe Bédard

Hi,

Babeltrace is doing exactly what it should as far as I know.

yes, but babeltrace can provide the information if:
* ip and vpid contexts are enabled (for userspace), e.g.

   $ lttng add-context --userspace --type=ip --type=vpid

* LTTng state dump events are enabled, e.g.

   $ lttng enable-event --userspace 'lttng_ust_statedump:*'

see this (from bt2 but it also applies to
bt1): [1]https://babeltrace.org/docs/v2.0/man7/babeltrace2-filter.lttng -utils.debug-info.7/#doc-lttng-prereq
Note that the Python bindings for babeltrace don't provide/expose this debug info.
Christophe
On Tue, 23 Jun 2020 at 11:12, Matthew Khouzam via lttng-dev <[2][email protected]> wrote:

Hi,
You have the pointers that are traced. Babeltrace is doing exactly what it should as far as I know.
You could use the command 'nm' to get your symbols and look them up. I am sure Babeltrace can do this from a python level. You could also use a GUI based trace viewer to get the information.
Hope that helps.
Matthew

     __________________________________________________________________
   From: lttng-dev <[3][email protected]> on behalf of
   Liu, Changcheng via lttng-dev <[4][email protected]>
   Sent: Tuesday, June 23, 2020 10:37 AM
   To: [5][email protected] <[6][email protected]>
   Cc: [7][email protected] <[8][email protected]>
   Subject: [lttng-dev] get function names with lttng-ust-cyg-profile

   Hi all,
      I'm trying to use lttng-ust-cyg-profile to trace program.
      Does anyone know how to get function names and offset through
   lttng-ust-cyg-profile?
      In below example, the babeltrace could only get the function
   entry/exit value.
      1. Source program: instrument.c
            1 #include <stdio.h>
            2
            3 int add3(int val) {
            4         return val + 3;
            5 }
            6
            7 int main(int argc, char **argv) {
            8     int x = 4;
            9
           10     puts("Press Enter to continue...");
           11     getchar();
           12
           13     x = add3(x);
           14
           15     return 0;
           16 }
      2. build source code:
           $ gcc -g -finstrument-functions instrument.c -o instrument
      3. run program:
          $
   LD_PRELOAD=/usr/lib/x86_64-linux-gnu/liblttng-ust-cyg-profile.so
   ./instrument
      4. start trace process:
          trace@trace:~/cc$ sudo lttng create instrument
          Session instrument created.
          Traces will be output to
   /root/lttng-traces/instrument-20200623-222917
          trace@trace:~/cc$ sudo lttng enable-channel user_func_trace
   --userspace
          UST channel user_func_trace enabled for session instrument
          trace@trace:~/cc$ sudo lttng enable-event --userspace
   lttng_ust_cyg_profile:func_entry --channel user_func_trace
          UST event lttng_ust_cyg_profile:func_entry created in channel
   user_func_trace
          trace@trace:~/cc$ sudo lttng enable-event --userspace
   lttng_ust_cyg_profile:func_exit --channel user_func_trace
          UST event lttng_ust_cyg_profile:func_exit created in channel
   user_func_trace
          trace@trace:~/cc$ sudo lttng start
          Tracing started for session instrument
          trace@trace:~/cc$ sudo lttng destroy
          Destroying session instrument..
          Session instrument destroyed
          trace@trace:~/cc$ sudo babeltrace
   /root/lttng-traces/instrument-20200623-222917
          [22:29:55.388607059] (+?.?????????) trace
   lttng_ust_cyg_profile:func_entry: { cpu_id = 2 }, { addr =
   0x5625C88B01A9, call_site = 0x5625C88B0237 }
Quoted 8 lines
          [22:29:55.388612293] (+0.000005234) trace
   lttng_ust_cyg_profile:func_exit: { cpu_id = 2 }, { addr =
   0x5625C88B01A9, call_site = 0x5625C88B0237 }
          [22:29:55.388613215] (+0.000000922) trace
   lttng_ust_cyg_profile:func_exit: { cpu_id = 2 }, { addr =
   0x5625C88B01EE, call_site = 0x7FE40BD5C0B3 }
   B.R.
   Changcheng

_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

#4 lore raw
In reply to Christophe Bédard via lttng-dev
Quoted 4 lines · Christophe Bédard

Hi,

Babeltrace is doing exactly what it should as far as I know.

Quoted 8 lines

yes, but babeltrace can provide the information if:
* ip and vpid contexts are enabled (for userspace), e.g.

   $ lttng add-context --userspace --type=ip --type=vpid

* LTTng state dump events are enabled, e.g.

   $ lttng enable-event --userspace 'lttng_ust_statedump:*'

Thanks Christophe. I works now that the function entry name could be got after 1) add ip&vpid context 2) enable state dump

Do you know how to print the call site function_name/offset? For example:

            11     getchar();
            12
            13     x = add3(x);

Currently, it only shows call_site address instead of function name with offset.

func_entry: { cpu_id = 2 }, { ip = 0x55CFA4F5C1EE, debug_info = { bin = "instrument+0x11ee", func = "main+0", src = "instrument.c:7" }, vpid = 8523 }, { addr = 0x55CFA4F5C1EE, call_site = 0x7F27C4B1E0B3 }
func_entry: { cpu_id = 1 }, { ip = 0x55CFA4F5C1A9, debug_info = { bin = "instrument+0x11a9", func = "add3+0", src = "instrument.c:3" }, vpid = 8523 }, { addr = 0x55CFA4F5C1A9, call_site = 0x55CFA4F5C237 }
func_exit: { cpu_id = 1 }, { ip = 0x55CFA4F5C1A9, debug_info = { bin = "instrument+0x11a9", func = "add3+0", src = "instrument.c:3" }, vpid = 8523 }, { addr = 0x55CFA4F5C1A9, call_site = 0x55CFA4F5C237 }
func_exit: { cpu_id = 1 }, { ip = 0x55CFA4F5C1EE, debug_info = { bin = "instrument+0x11ee", func = "main+0", src = "instrument.c:7" }, vpid = 8523 }, { addr = 0x55CFA4F5C1EE, call_site = 0x7F27C4B1E0B3 }

B.R.
Changcheng

Quoted 7 lines

see this (from bt2 but it also applies to
bt1): [1]https://babeltrace.org/docs/v2.0/man7/babeltrace2-filter.lttng -utils.debug-info.7/#doc-lttng-prereq
Note that the Python bindings for babeltrace don't provide/expose this debug info.
Christophe

_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

#5 lore raw

Hi,

Quoted 8 lines · Changcheng

Do you know how to print the call site function_name/offset? For example:

            11     getchar();
            12
            13     x = add3(x);

Currently, it only shows call_site address instead of function name with offset.

Quoted 13 lines

func_entry: { cpu_id = 2 }, { ip = 0x55CFA4F5C1EE, debug_info = { bin = "instrument+0x11ee", func = "main+0", src = "instrument.c:7" }, vpid = 8523 }, { addr = 0x55CFA4F5C1EE, call_site = 0x7F27C4B1E0B3 }
func_entry: { cpu_id = 1 }, { ip = 0x55CFA4F5C1A9, debug_info = { bin = "instrument+0x11a9", func = "add3+0", src = "instrument.c:3" }, vpid = 8523 }, { addr = 0x55CFA4F5C1A9, call_site = 0x55CFA4F5C237 }
func_exit: { cpu_id = 1 }, { ip = 0x55CFA4F5C1A9, debug_info = { bin = "instrument+0x11a9", func = "add3+0", src = "instrument.c:3" }, vpid = 8523 }, { addr = 0x55CFA4F5C1A9, call_site = 0x55CFA4F5C237 }
func_exit: { cpu_id = 1 }, { ip = 0x55CFA4F5C1EE, debug_info = { bin = "instrument+0x11ee", func = "main+0", src = "instrument.c:7" }, vpid = 8523 }, { addr = 0x55CFA4F5C1EE, call_site = 0x7F27C4B1E0B3 }

Maybe I'm missing something, but isn't it right here? E.g.

debug_info = { bin = "instrument+0x11ee", func = "main+0", src =

Quoted 2 lines

"instrument.c:7" }

Otherwise, I don't think babeltrace can provide any more information.

Christophe

_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

#6 lore raw
Quoted 19 lines · Christophe Bédard
   Hi,
   On Tue, 23 Jun 2020 at 21:45, Liu, Changcheng
   <[1][email protected]> wrote:

     Do you know how to print the call site function_name/offset?
     For example:
                 11     getchar();
                 12
                 13     x = add3(x);
     Currently, it only shows call_site address instead of function name
     with offset.
     func_entry: { cpu_id = 2 }, { ip = 0x55CFA4F5C1EE, debug_info = {
     bin = "instrument+0x11ee", func = "main+0", src = "instrument.c:7"
     }, vpid = 8523 }, { addr = 0x55CFA4F5C1EE, call_site =
     0x7F27C4B1E0B3 }
     func_entry: { cpu_id = 1 }, { ip = 0x55CFA4F5C1A9, debug_info = {
     bin = "instrument+0x11a9", func = "add3+0", src = "instrument.c:3"
     }, vpid = 8523 }, { addr = 0x55CFA4F5C1A9, call_site =
     0x55CFA4F5C237 }
Quoted 8 lines
     func_exit: { cpu_id = 1 }, { ip = 0x55CFA4F5C1A9, debug_info = { bin
     = "instrument+0x11a9", func = "add3+0", src = "instrument.c:3" },
     vpid = 8523 }, { addr = 0x55CFA4F5C1A9, call_site = 0x55CFA4F5C237 }
     func_exit: { cpu_id = 1 }, { ip = 0x55CFA4F5C1EE, debug_info = { bin
     = "instrument+0x11ee", func = "main+0", src = "instrument.c:7" },
     vpid = 8523 }, { addr = 0x55CFA4F5C1EE, call_site = 0x7F27C4B1E0B3 }

    Maybe I'm missing something, but isn't it right here? E.g.

I'm also curious about the output here. "main+0" the function name "main" is right, but the offset "+0" isn't right.
I've run it for several times, it always shows like the above output.
So, two questions here:
1. How to show the rigth offset?
2. How to show call_site in "func/offset" format?

Quoted 10 lines
     debug_info = { bin = "instrument+0x11ee", func = "main+0", src =
     "instrument.c:7" }

Otherwise, I don't think babeltrace can provide any more information. Christophe

References

1. mailto:[email protected]

_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

#7 lore raw

Hi Christophe,
I've checked lots of examples about func_entry/exit. It seems all the address are the linked address. However, my result shows that they're the loaded running address.

Do you have some suggestions to check it further?

B.R.
Changcheng

Quoted 27 lines · Changcheng
Quoted 26 lines · Christophe Bédard
   Hi,
   On Tue, 23 Jun 2020 at 21:45, Liu, Changcheng
   <[1][email protected]> wrote:

     Do you know how to print the call site function_name/offset?
     For example:
                 11     getchar();
                 12
                 13     x = add3(x);
     Currently, it only shows call_site address instead of function name
     with offset.
     func_entry: { cpu_id = 2 }, { ip = 0x55CFA4F5C1EE, debug_info = {
     bin = "instrument+0x11ee", func = "main+0", src = "instrument.c:7"
     }, vpid = 8523 }, { addr = 0x55CFA4F5C1EE, call_site =
     0x7F27C4B1E0B3 }
     func_entry: { cpu_id = 1 }, { ip = 0x55CFA4F5C1A9, debug_info = {
     bin = "instrument+0x11a9", func = "add3+0", src = "instrument.c:3"
     }, vpid = 8523 }, { addr = 0x55CFA4F5C1A9, call_site =
     0x55CFA4F5C237 }
     func_exit: { cpu_id = 1 }, { ip = 0x55CFA4F5C1A9, debug_info = { bin
     = "instrument+0x11a9", func = "add3+0", src = "instrument.c:3" },
     vpid = 8523 }, { addr = 0x55CFA4F5C1A9, call_site = 0x55CFA4F5C237 }
     func_exit: { cpu_id = 1 }, { ip = 0x55CFA4F5C1EE, debug_info = { bin
     = "instrument+0x11ee", func = "main+0", src = "instrument.c:7" },
     vpid = 8523 }, { addr = 0x55CFA4F5C1EE, call_site = 0x7F27C4B1E0B3 }
Quoted 18 lines
Quoted 1 line

Maybe I'm missing something, but isn't it right here? E.g.

I'm also curious about the output here. "main+0" the function name "main" is right, but the offset "+0" isn't right.
I've run it for several times, it always shows like the above output.
So, two questions here:
1. How to show the rigth offset?
2. How to show call_site in "func/offset" format?

Quoted 10 lines
     debug_info = { bin = "instrument+0x11ee", func = "main+0", src =
     "instrument.c:7" }

Otherwise, I don't think babeltrace can provide any more information. Christophe

References

1. mailto:[email protected]

_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev