9

Kcachegrind serves as a wonderful utility to visually represent the hotspot to the source line level when profiling code. I found it pretty useful when micro optimizing my C++ code base. For my latest python project I started using Kcachegrind to process the output from profilestats. Kcachegrind is a linux only utility but various unofficial ports are available and one I am using is qcachegrind. Generally it works to a large extent and suffices for most issues except I am having a hard time getting the source annotation work.

On the source Tab I am being greeted with the familiar source missing message

There is no source available for the following function:
   'main C:\Projects\module\src\source.py:397'
This is because no debug information is present
Recompile source and redo the profile run.
The function is located in the ELF Object:
  '(unknown)'

Using the option

Settings -> Configure -> Source Annotation 

and adding the Source Base Directory was not useful.

I have a feeling that the utility wants an ELF Object which is not relevant for Python. Any help in this regard would be useful.

Relevant Information:

  • Python 2.7
  • profilestats (2.0)
  • QCachegrind 0.7.4
  • Windows 2012R2
Abhijit
  • 62,056
  • 18
  • 131
  • 204
  • Seems like `profilestats` may not be including the relevant data in its output. Have you tried saving the profiling output in the "Python format" and converting it using [`pyprof2calltree`](https://pypi.python.org/pypi/pyprof2calltree/)? – taleinat Jul 09 '15 at 08:11

1 Answers1

1

I second @taleniat comment. I am an OSX user. I was having some trouble getting qcachegrind to work so I ended up using pyprof2calltree and it works perfectly, source code tab included. YMMV.

First run your script with cProfile

python -m cProfile -o report.profile report.py

Then you can use pyprof2calltree to launch qcachegrind (no need for intermediate conversion).

pyprof2calltree -k -i report.profile

by the way, Python 2.7.10 and qcachegrind 0.7.4 installed via homebrew on OSX 10.11

Josep Valls
  • 5,483
  • 2
  • 33
  • 67