Basic block execution over time

Hello All,

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?

Regards, Raul.


I believe the easiest way to do this is using the new trace_pc functionality from SanitizerCoverage. See for some documentation about that.

In short:

  • Compile your program with the -fsanitize-coverage=trace-pc flag.
  • 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.


-- Dean