2

I am working with a user-space C++ application and using the Linux trace tool kit, which provides tracepoints (provider, name, etc.).

I want to place in my source code a

- tracepoint(provider, name, ...)

statement at every function entry and exit point.

Is it possible to automate this by some means? It is very cumbersome to place all of these manually.

I want to do this some way other than aspect programming.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574

1 Answers1

3

You can use the liblttng-ust-cyg-profile.so helper library to obtain LTTng-UST tracepoints from every function entry and exit.

  • Recompile the program with -g -finstrument-functions.
  • Run it by preloading the helper library:
    • LD_PRELOAD=/path/to/liblttng-ust-cyg-profile.so ./myApp

This will generate trace events for every instrumented function entry and exit. Note that the tracepoints will only contain the function addresses, not the names. This is a limitation of cyg-profile. To map these back to function names, you can use a utility like addr2line.

See the Function Tracing part of the documentation for more details.

Depending on the amount of instrumented functions, this may have a non-negligible performance impact. Also, -finstrument-functions should technically work with C++ applications, but it can be finicky. I've had it fail compiling with large, non-trivial C++ applications. Your mileage may vary.

alexmonthy
  • 103
  • 6
  • you say that liblttng-ust-cyg-profile.so can be used - - to obtain tracepoints from every function entry and exit. I want to be able to insert my tracepoint statements at function entry and exit – Source Code Aug 12 '15 at 07:52