move profile out of module scope

This commit is contained in:
David Rose 2008-10-23 17:57:56 +00:00
parent 95d0df7a7d
commit 43a8a5ac7a

View File

@ -48,8 +48,6 @@ import gc
#if __debug__: #if __debug__:
import traceback import traceback
import __builtin__ import __builtin__
import profile
import pstats
from StringIO import StringIO from StringIO import StringIO
import marshal import marshal
@ -1128,6 +1126,10 @@ def _removeProfileCustomFuncs(filename):
# del __builtin__.func # del __builtin__.func
# #
def _profileWithoutGarbageLeak(cmd, filename): def _profileWithoutGarbageLeak(cmd, filename):
# The profile module isn't necessarily installed on every Python
# installation, so we import it here, instead of in the module
# scope.
import profile
# this is necessary because the profile module creates a memory leak # this is necessary because the profile module creates a memory leak
Profile = profile.Profile Profile = profile.Profile
statement = cmd statement = cmd
@ -1177,6 +1179,7 @@ def printProfile(filename=PyUtilProfileDefaultFilename,
lines=PyUtilProfileDefaultLines, lines=PyUtilProfileDefaultLines,
sorts=PyUtilProfileDefaultSorts, sorts=PyUtilProfileDefaultSorts,
callInfo=1): callInfo=1):
import pstats
s = pstats.Stats(filename) s = pstats.Stats(filename)
s.strip_dirs() s.strip_dirs()
for sort in sorts: for sort in sorts:
@ -3466,6 +3469,7 @@ if __debug__:
assert obj2count[4] == 4 * 3 assert obj2count[4] == 4 * 3
def quickProfile(name="unnamed"): def quickProfile(name="unnamed"):
import pstats
def profileDecorator(f): def profileDecorator(f):
if(not config.GetBool("use-profiler",0)): if(not config.GetBool("use-profiler",0)):
return f return f