[wingide-users] Profile a python script from within WingIde

Wingware Support support at wingware.com
Mon Sep 9 10:27:44 EDT 2013


Werner F. Bruhin wrote:
> Is there a way of profiling a Python script in WingIDE and getting 
> statistics displayed in a way which is easy to analyse?

Wing doesn't yet have integrated profiling support.  It's something 
we'ld like to add eventually although it's lower priority since it's 
pretty easy to profile Python w/o IDE support.  Also, it's often a good 
idea to have a way to start/stop profiling in the shipped code for the 
inevitable cases where something runs slowly only in the field.

In case it's useful, here is a quick example of using cProfile and 
pstats to profile a call.  This forms the basis of the 
internal-profile-start and internal-profile-stop commands in Wing, which 
let us get profiles from users (in our case the function passed to 
runcall is a nested GUI event loop):

       import cProfile, pstats

       profiler = cProfile.Profile()
       profiler.runcall(function_or_method_to_profile)

       stats = pstats.Stats(profiler)
       stats.strip_dirs()
       stats.sort_stats('cumulative', 'calls')
       stats.print_stats(40)
       stats.sort_stats('time', 'calls')
       stats.print_stats(40)

Showing both 'cumulative' and 'time' stats helps reveal hotspots in more 
cases.

I hope this is useful...

-- 

Stephan Deibel
Wingware | Python IDE
Advancing Software Development

www.wingware.com


More information about the wingide-users mailing list