bbangert /
dozer
WSGI middleware fork of Robert Brewer's Dowser
Clone URL : http://bitbucket.org/bbangert/dozer/ (size: 146.1 KB)
| commit 24: | 9c7f31a852ba |
| parent 23: | 16982f11f336 |
| branch: | trunk |
More accurate profiler call.
Changed (Δ297 bytes):
raw changeset »
dozer/profile.py (17 lines added, 5 lines removed)
Up to file-list dozer/profile.py:
| … | … | @@ -76,10 +76,22 @@ class Profiler(object): |
76 |
76 |
def run_profile(self, environ, start_response): |
77 |
77 |
"""Run the profile over the request and save it""" |
78 |
78 |
prof = cProfile.Profile() |
79 |
globs = globals() |
|
80 |
local = {'environ':environ, 'start_response':start_response, |
|
81 |
'self':self} |
|
82 |
prof.runctx('content = self.app(environ, start_response)', globs, local) |
|
79 |
response_body = [] |
|
80 |
||
81 |
def catching_start_response(status, headers, exc_info=None): |
|
82 |
start_response(status, headers, exc_info) |
|
83 |
return response_body.append |
|
84 |
||
85 |
def runapp(): |
|
86 |
appiter = self.app(environ, catching_start_response) |
|
87 |
try: |
|
88 |
response_body.extend(appiter) |
|
89 |
finally: |
|
90 |
if hasattr(appiter, 'close'): |
|
91 |
appiter.close() |
|
92 |
||
93 |
prof.runcall(runapp) |
|
94 |
body = ''.join(response_body) |
|
83 |
95 |
results = prof.getstats() |
84 |
96 |
tree = buildtree(results) |
85 |
97 |
|
| … | … | @@ -99,7 +111,7 @@ class Profiler(object): |
99 |
111 |
dir_name = self.profile_path or '' |
100 |
112 |
cPickle.dump(profile_run, open(os.path.join(dir_name, fname), 'wb')) |
101 |
113 |
del results, tree, profile_run |
102 |
return |
|
114 |
return [body] |
|
103 |
115 |
|
104 |
116 |
|
105 |
117 |
def label(code): |
