Code

ProfilingDjango: runserver-profiler2.2.diff

File runserver-profiler2.2.diff, 1.2 KB (added by LawrenceOluyede, 7 years ago)

updated the patch against the latest revision and made the path configurable

Line 
1Index: management.py
2===================================================================
3--- management.py       (revision 4669)
4+++ management.py       (working copy)
5@@ -7,6 +7,17 @@
6 from optparse import OptionParser
7 from django.utils import termcolors
8 
9+PROF_PATH = '/tmp'
10+
11+import hotshot, time, os
12+def make_profiler_handler(inner_handler):
13+    def handler(environ, start_response):
14+        profname = "%s.%.3f.prof" % (environ['PATH_INFO'].strip("/").replace('/', '.'), time.time())
15+        profname = os.path.join(PROF_PATH, profname)
16+        prof = hotshot.Profile(profname)
17+        return prof.runcall(inner_handler, environ, start_response)
18+    return handler
19+
20 # For Python 2.3
21 if not hasattr(__builtins__, 'set'):
22     from sets import Set as set
23@@ -1188,7 +1199,7 @@
24         try:
25             import django
26             path = admin_media_dir or django.__path__[0] + '/contrib/admin/media'
27-            handler = AdminMediaHandler(WSGIHandler(), path)
28+            handler = make_profiler_handler(AdminMediaHandler(WSGIHandler(), path))
29             run(addr, int(port), handler)
30         except WSGIServerException, e:
31             # Use helpful error messages instead of ugly tracebacks.