generating a dynamic callgraph with llvm-prof

One can use “-insert-edge-profiling” with opt to collect general metrics (frequency of function execution, frequency of basic block execution). But I’d like to record all call information. So every time a function call is made, I’d like to record [calling function name, callee function name]

Is this feasible with with llvm-prof and any of the existing profiling options?

Dear Eric,

Swarup and I wrote a dynamic slicing system called Giri several years ago that recorded the execution of every call instruction. It's not in the LLVM tree, and I don't think it works with the latest version of LLVM, but it'll give you what you want.

Swarup, is that code publicly available somewhere?

Regards,

John Criswell

Yes, the latest version can be downloaded from here https://github.com/liuml07/giri . The LLVM instrumentation code is in TracingNoGiri.cpp file and runtime code in Tracing.cpp.

You may need to delete other unnecessary instrumentation code which you don’t need.

Thanks,
Swarup.

Thank you. I’ve compiled giri, and looked through the source code. It seems like it should do exactly what I want (record each basic block execution)

By inspecting the test Makefiles, I can see how to generate an instrumented binary, “example.trace.exe”, and running the instrumented binary produces a trace file “example.trace”.

Presumably, the basic block execution profile is stored in these trace files. But it’s not entirely clear to me how to interpret the resulting .trace file. EntryCache doesn’t provide any methods for actually reading cache contents.

Could you point me in the right direction for how to extract basic block execution profile information from a trace file?

thank you for the help!

Dear Eric,

This file has code which prints the trace in readable format.
https://github.com/liuml07/giri/blob/master/tools/PrintTrace/PrintTrace.cpp

You can additional details from TraceFile.cpp (and Giri.cpp) about how we read and use Basic Block information. Hope this will help you.

Thanks,
Swarup.