How can I keep track of the different basic blocks of a program executed over time?
Or in other words, how can I annotate the block name (block_a) and the time/cycle at which that blocs (block_a) was executed, and do this for all the blocks on a reasonable simple program?
I believe the easiest way to do this is using the new
trace_pc functionality from SanitizerCoverage. See http://clang.llvm.org/docs/SanitizerCoverage.html#tracing-pcs for some documentation about that.
- Compile your program with the
- This adds a call to a function called
__sanitizer_cov_trace_pc to every edge in the control-flow graph.
- You can define this function in any way you want (just write C code, and link it to the application)
- In particular, you can use
__builtin_return_address to find where the function was called from. You’re then free to dump that address to a file descriptor, store it in a memory buffer, …
The other option might be to see whether you could use XRay, but that might not give you basic blocks (though it will give you cycle time, thread, and function entry/exit points). The tooling for analysing the XRay trace files is under development and we're still lacking documentation -- but if you're interested I'd be happy to describe how to use it.