Fix the debug module (profiling code) for current python libraries

This commit is contained in:
prculley 2017-01-05 14:32:03 -06:00 committed by Nick Hall
parent 40fbdae481
commit b7155b47ed

View File

@ -23,6 +23,10 @@
""" """
Debugging utilities Debugging utilities
""" """
import cProfile
import pstats
import sys
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -30,15 +34,13 @@ Debugging utilities
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
def profile(func, *args, **kwargs): def profile(func, *args, **kwargs):
import hotshot.stats
prf = hotshot.Profile('mystats.profile') prf = cProfile.Profile()
print("Start") print("Start")
r = prf.runcall(func, *args, **kwargs) r = prf.runcall(func, *args, **kwargs)
print("Finished") print("Finished")
prf.close()
print("Loading profile") print("Loading profile")
stats = hotshot.stats.load('mystats.profile') stats = pstats.Stats(prf, stream=sys.stdout)
print("done") print("done")
stats.strip_dirs() stats.strip_dirs()
stats.sort_stats('time', 'calls') stats.sort_stats('time', 'calls')