2

I'm using hotshot to profile my Python program, Is there any way to aggregated the profiles and see a total result in Kcachegrind?

After some research I used pstats to aggregate the profiles in the way given below and used pyprof2calltree to convert the result into kcachegrind format

>>> pf = pstats.Stats("profile1.prof")
>>> p2 = pf.add("profile2.prof")
>>> p2.dump_stats("aggregated.prof")

pyprof2calltree gave me an error like this.

  File "/usr/local/bin/pyprof2calltree", line 9, in <module>
    load_entry_point('pyprof2calltree==1.1.0', 'console_scripts', 'pyprof2calltree')()
  File "/usr/local/lib/python2.7/dist-packages/pyprof2calltree.py", line 240, in main
    kg.output(file(outfile, 'wb'))
  File "/usr/local/lib/python2.7/dist-packages/pyprof2calltree.py", line 106, in output
    self._entry(entry)
  File "/usr/local/lib/python2.7/dist-packages/pyprof2calltree.py", line 167, in _entry
    self._subentry(lineno, subentry, call_info)
  File "/usr/local/lib/python2.7/dist-packages/pyprof2calltree.py", line 178, in _subentry
    print >> out_file, 'calls=%d %d' % (call_info[0], co_firstlineno)
TypeError: 'int' object is not subscriptable

Am I doing something wrong here or is there any other way to do this?

Eby
  • 2,769
  • 4
  • 23
  • 30

2 Answers2

0

Have you looked at runsnakerun? In my opinion it's the best profiler for python and you don't have to use pyprof2calltree to view the results. http://www.vrplumber.com/programming/runsnakerun/

Matthew Talbert
  • 5,998
  • 35
  • 38
0

I've had the same problem in the past, and in the end I gave up on kcachegrind. When I finally got the resulting into it, it was less useful than I'd hoped. If you just want to show the profile graphically, then I would recommend you have a look at gprof2dot. It uses graphviz to draw the results and so far its the best tool I've found to do this.

aquavitae
  • 17,414
  • 11
  • 63
  • 106