Commit 82cbb9a1 by Bridger Maxwell

Matched stop and start calls in perf middleware.

parent 6e9e9c76
......@@ -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):
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment