How to collect hotshot (profiler) results and view it in kcachegrind

I use hotshot to profile my Python program. Is there a way to aggregate profiles and see the overall result in Kcachegrind?

After some research, I used pstats to aggregate profiles in the manner below, and used pyprof2calltree to convert the result to kcachegrind format

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

pyprof2calltree gave me such an error.

  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?

+4
source share
2 answers

I had the same problem in the past, and in the end I gave up kcachegrind. When I finally got the result, it was less useful than I had hoped. If you just want to show the profile graphically, I would recommend you take a look at gprof2dot . It uses graphviz to get results, and is still the best tool I have found for this.

0
source

Have you looked at runnakerun? In my opinion, this is the best profiler for python, and you do not need to use pyprof2calltree to view the results. http://www.vrplumber.com/programming/runsnakerun/

0
source

Source: https://habr.com/ru/post/1400529/


All Articles