Matched stop and start calls in perf middleware.
This commit is contained in:
@@ -5,17 +5,21 @@ from django.conf import settings
|
||||
|
||||
tmpfile = None
|
||||
prof = None
|
||||
isRunning = False
|
||||
|
||||
def restart_profile():
|
||||
global prof, tmpfile
|
||||
global prof, tmpfile, isRunning
|
||||
try:
|
||||
oldname = tmpfile.name
|
||||
except:
|
||||
oldname = ""
|
||||
if prof != None:
|
||||
if isRunning:
|
||||
prof.stop()
|
||||
prof.close()
|
||||
tmpfile = tempfile.NamedTemporaryFile(prefix='prof',delete=False)
|
||||
prof = hotshot.Profile(tmpfile.name)
|
||||
prof = hotshot.Profile(tmpfile.name, lineevents=1)
|
||||
isRunning = False
|
||||
print "Filename", tmpfile.name
|
||||
return (tmpfile.name, oldname)
|
||||
|
||||
@@ -23,13 +27,19 @@ restart_profile()
|
||||
|
||||
class ProfileMiddleware:
|
||||
def process_request (self, request):
|
||||
prof.start()
|
||||
global isRunning
|
||||
if not isRunning:
|
||||
prof.start()
|
||||
isRunning = True
|
||||
else:
|
||||
print "Profiler was already running. Results may be unpredictable"
|
||||
|
||||
print "Process request"
|
||||
|
||||
def process_response (self, request, response):
|
||||
try:
|
||||
global isRunning
|
||||
if isRunning:
|
||||
prof.stop()
|
||||
except:
|
||||
print "Profiler not active. If you didn't just restart, this is an error"
|
||||
isRunning = False
|
||||
print "Process response"
|
||||
return response
|
||||
|
||||
Reference in New Issue
Block a user