ProfilingDjango: profiler-cprofile.py

File profiler-cprofile.py, 547 bytes (added by chrisj, 16 years ago)

Adapted profile handler to use cProfile module. Place in django/core/handlers and set PythonHandler in apache conf

Line 
1import cProfile, time, os
2from django.core.handlers.modpython import ModPythonHandler
3
4PROFILE_DATA_DIR = "/var/log/cmsprofile"
5
6def handler(req):
7 '''
8 Handler that uses cProfile to store profile data.
9
10 Adapted from django/core/handlers/profiler-hotshot.py
11 '''
12 profname = "%s.%.3f.prof" % (req.uri.strip("/").replace('/', '.'), time.time())
13 profname = os.path.join(PROFILE_DATA_DIR, profname)
14 prof = cProfile.Profile()
15 results = prof.runcall(ModPythonHandler(), req)
16 prof.dump_stats(profname)
17 return results
Back to Top