0

My main program is written by C. The C code calls an interpreter language, say python, by its C APIs. Then the interpreter language calls back to other C APIs. All the C code are debuggable, the interpreter language's C interface is also debuggable.

I found callgrind cannot profile the C code called by the interpreter language. Its call tree stops at the C code that calls the interpreter language.

Is this any known limitation of callgrind? Oracle Solaris Studio works at the case.

Joe C
  • 2,757
  • 2
  • 26
  • 46

1 Answers1

1

callgrind logic maintains the stack incrementally. This implies that it has to understand the calling convention of all what is on the stack, detect the calls and the returns.

You might compare with the valgrind unwinder and the gdb unwinder using gdb+vgdb.

Start valgrind with: valgrind --vgdb-error=0 --vgdb=full ....

Put a breakpoint in the C code called by the interpreter language, and continue the execution.

When breakpoint is encountered, compare the result of the 2 following gdb commands:

  • backtrace
  • monitor v.info scheduler

The above will show if gdb and/or valgrind unwinders are working properly.

You can try to understand what callgrind does by using some valgrind debugging options, e.g.

valgrind --tool=callgrind -v -v -v -d -d -d --ct-verbose=3

(adjust the nr of -v/-d/verbosity to your taste).

And of course, in case you have an old version of valgrind, you might try with the last release or even the git repository, even if I doubt something recently changed in this area.

phd
  • 3,669
  • 1
  • 11
  • 12
  • does it mean this is a limitation of callgrind and it has no way to profile the C APIs? – Joe C May 19 '18 at 16:04
  • unless we understand what is happening, we do not know if this is a bug or a limitation. The above might help telling what is the cause. I am quite sure callgrind can follow e.g. C code calling 'JIT code' calling C code, so, IMO there is no inherent limitation. But this might all depend what the middle interpreter does/arrange the stack. If you have a small reproducer easy to compile, you might submit a bug report on valgrind bugzilla. Also, looking at the above, this seems to be on Solaris. You might test on linux to see if this is a platform specific bug. – phd May 20 '18 at 06:54
  • Oracle Solaris Studio works for linux. I run it on RHEL6. – Joe C May 20 '18 at 21:00
  • Ok. So, it is probably not a platform specific bug. Now, the suggested trials might clarify what is happening. – phd May 21 '18 at 07:42