Reputation: 153
I am trying to get into C language and looking for a profiler or tracer tool that supports timeline view representation with every function calls. Something like tracing via PHP xDebug. Where all function calls placed approximately at exact time they were called in the stack.
My research so far is:
So far I found that valgrind --tool=callgrind ./myscript
is the closest one I can use.
However the visualization is a flamegraph that samples the C function calls.
In my case it is a good start for reverse engineering but I would like to have detailed timeline with actual calls timiestamps.
I also checked the gprofng
however the textual visualization is not that easy to read and it seems to be same sampled flamegraph
I also tried to do something via perf
but it looks like perf
recording only system/linux calls without timestamps, at least that what is visible in the speedscope.
Maybe I am not using perf
correctly but that is what I got after trying different commands from https://www.brendangregg.com/perf.html
I understand some basics that the app must be compiled with -g
or that tracing adds some overhead and timings might be not 100% accurate but I found it difficult to get a tool that can visualize calltree as timeline in C language.
Upvotes: 3
Views: 867
Reputation: 153
For now the best thing that solves my case is uftrace profiler https://github.com/namhyung/uftrace
Upvotes: 1
Reputation: 6946
Callgrind doesn't really provide any meaningful timing information. It's main advantage is that since it is instruction-accurate, the results are precise and close to repeatable.
perf
, in this mode, is sampling the callstack. It runs your application at full speed, and 100 times a second (configurable) stops it, captures the callstack and restarts it. That's fairly low overhead - a few percent in my experience. perf has 3 ways of getting the callstacks, I don't know much about the third one so I'll leave that. The first one is walking the stack base pointer. That's the default with perf (and can be explicitly specified with --call-graph=fp
). In order for that to function you need to build your exe either without optimization or with -fno-omit-frame-pointer
. It might also work at low level optimization -O1
. The second method is to use DWARF debuginfo. That means building your exe with -g
and running perf record
with --call-graph=dwarf
. That will generate a large data file.
I haven't yet used gprofng
, but I'm fairly excited about its recent release. I used to use its precedessor Sun/Solaris Studio collect a lot. I think that there are plans to release the GUI, which should make viewing the results a lot easier. I don't know if the new tool is compatible with the old analyzer
tool.
Upvotes: 1