Code

ProfilingDjango: runserver-profiler2.diff

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

updated the patch against the latest revision

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