Skip to content

Commit

Permalink
Profiles now include elapsed milliseconds in filename with leading
Browse files Browse the repository at this point in the history
zeroes so you can sort out evil long requests.
  • Loading branch information
J.A. Roberts Tunney authored and trbs committed Oct 24, 2009
1 parent e3974fd commit 7f271a7
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion django_extensions/management/commands/runprofileserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from django.core.management.base import BaseCommand, CommandError
from optparse import make_option
from datetime import datetime
import os
import sys

Expand Down Expand Up @@ -163,20 +164,27 @@ def handler(environ, start_response):
if no_media and (path_info.startswith('/media') or path_info.startswith(settings.MEDIA_URL)):
return inner_handler(environ, start_response)
path_name = path_info.strip("/").replace('/', '.') or "root"
profname = "%s.%.3f.prof" % (path_name, time.time())
profname = "%s.%s.prof" % (path_name, datetime.now().isoformat())
profname = os.path.join(prof_path, profname)
if USE_CPROFILE:
prof = cProfile.Profile()
else:
prof = hotshot.Profile(profname)
start = datetime.now()
try:
return prof.runcall(inner_handler, environ, start_response)
finally:
# seeing how long the request took is important!
elap = datetime.now() - start
elapms = elap.seconds * 1000.0 + elap.microseconds / 1000.0
if USE_LSPROF:
kg = KCacheGrind(prof)
kg.output(file(profname, 'w'))
elif USE_CPROFILE:
prof.dump_stats(profname)
profname2 = "%s.%06dms.%s.prof" % (path_name, elapms, datetime.now().isoformat())
profname2 = os.path.join(prof_path, profname2)
os.rename(profname, profname2)
return handler

print "Validating models..."
Expand Down

0 comments on commit 7f271a7

Please sign in to comment.