1
0
mirror of https://github.com/django/django.git synced 2025-10-26 15:16:09 +00:00

Moved django.bin.profiling.handler to django.core.handlers.profiler-hotshot

git-svn-id: http://code.djangoproject.com/svn/django/trunk@170 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty
2005-07-18 06:34:34 +00:00
parent ca3d89b70f
commit 86d9ae269d

View File

@@ -0,0 +1,22 @@
import hotshot, time, os
from django.core.handlers.modpython import ModPythonHandler
PROFILE_DATA_DIR = "/var/log/cmsprofile/"
def handler(req):
'''
Handler that uses hotshot to store profile data.
Stores profile data in PROFILE_DATA_DIR. Since hotshot has no way (that I
know of) to append profile data to a single file, each request gets its own
profile. The file names are in the format <url>.<n>.prof where <url> is
the request path with "/" replaced by ".", and <n> is a timestamp with
microseconds to prevent overwriting files.
Use the gather_profile_stats.py script to gather these individual request
profiles into aggregated profiles by request path.
'''
profname = "%s.%.3f.prof" % (req.uri.strip("/").replace('/', '.'), time.time())
profname = os.path.join(PROFILE_DATA_DIR, profname)
prof = hotshot.Profile(profname)
return prof.runcall(ModPythonHandler(), req)