1 | import cProfile, 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 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
|
---|