app/django/core/handlers/profiler-hotshot.py
changeset 54 03e267d67478
equal deleted inserted replaced
53:57b4279d8c4e 54:03e267d67478
       
     1 import hotshot, time, os
       
     2 from django.core.handlers.modpython import ModPythonHandler
       
     3 
       
     4 PROFILE_DATA_DIR = "/var/log/cmsprofile"
       
     5 
       
     6 def handler(req):
       
     7     '''
       
     8     Handler that uses hotshot to store profile data.
       
     9 
       
    10     Stores profile data in PROFILE_DATA_DIR.  Since hotshot has no way (that I
       
    11     know of) to append profile data to a single file, each request gets its own
       
    12     profile.  The file names are in the format <url>.<n>.prof where <url> is
       
    13     the request path with "/" replaced by ".", and <n> is a timestamp with
       
    14     microseconds to prevent overwriting files.
       
    15 
       
    16     Use the gather_profile_stats.py script to gather these individual request
       
    17     profiles into aggregated profiles by request path.
       
    18     '''
       
    19     profname = "%s.%.3f.prof" % (req.uri.strip("/").replace('/', '.'), time.time())
       
    20     profname = os.path.join(PROFILE_DATA_DIR, profname)
       
    21     prof = hotshot.Profile(profname)
       
    22     return prof.runcall(ModPythonHandler(), req)