ProfilingDjango: runserver-profiler3.diff
File runserver-profiler3.diff, 2.3 KB (added by , 16 years ago) |
---|
-
runserver.py
old new class Command(BaseCommand): 9 9 help='Tells Django to NOT use the auto-reloader.'), 10 10 make_option('--adminmedia', dest='admin_media_path', default='', 11 11 help='Specifies the directory from which to serve admin media.'), 12 make_option('--profile', action='store_true', dest='profile', 13 help='Enable profiling. Write profiles into systems temporary directory.'), 12 14 ) 13 15 help = "Starts a lightweight Web server for development." 14 16 args = '[optional port number, or ipaddr:port]' … … class Command(BaseCommand): 39 41 use_reloader = options.get('use_reloader', True) 40 42 admin_media_path = options.get('admin_media_path', '') 41 43 shutdown_message = options.get('shutdown_message', '') 44 profile = options.get('profile', False) 42 45 quit_command = (sys.platform == 'win32') and 'CTRL-BREAK' or 'CONTROL-C' 43 46 44 47 def inner_run(): … … class Command(BaseCommand): 50 53 print "Quit the server with %s." % quit_command 51 54 try: 52 55 path = admin_media_path or django.__path__[0] + '/contrib/admin/media' 53 handler = AdminMediaHandler(WSGIHandler(), path) 56 if profile: 57 import hotshot, time, tempfile 58 def make_profiler_handler(inner_handler): 59 def handler(environ, start_response): 60 path = environ['PATH_INFO'].strip("/").replace('/', '.') 61 fd, profname = tempfile.mkstemp('.prof', '%s.%3f' % (path, time.time())) 62 os.close(fd) 63 prof = hotshot.Profile(profname) 64 return prof.runcall(inner_handler, environ, start_response) 65 return handler 66 handler = make_profiler_handler(AdminMediaHandler(WSGIHandler(), path)) 67 else: 68 handler = AdminMediaHandler(WSGIHandler(), path) 54 69 run(addr, int(port), handler) 55 70 except WSGIServerException, e: 56 71 # Use helpful error messages instead of ugly tracebacks.