~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/middleware/profile.py

  • Committer: Matt Nordhoff
  • Date: 2009-06-25 09:19:36 UTC
  • mfrom: (374 trunk-rich)
  • mto: This revision was merged to the branch mainline in revision 377.
  • Revision ID: mnordhoff@mattnordhoff.com-20090625091936-n6nj8jljpui2vmzg
Merge trunk, resolving NEWS

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
"""Profiling middleware for Paste."""
2
 
 
 
1
'''Profiling middleware for paste.'''
 
2
import cgi
 
3
import logging
 
4
import sys
3
5
import threading
4
6
 
5
7
from bzrlib.lsprof import profile
6
 
 
 
8
from guppy import hpy
7
9
 
8
10
class LSProfMiddleware(object):
9
 
    """Paste middleware for profiling with lsprof."""
 
11
    '''Paste middleware for profiling with lsprof.'''
10
12
 
11
13
    def __init__(self, app, global_conf=None):
12
14
        self.app = app
27
29
        try:
28
30
            ret, stats = profile(self.__run_app, environ, start_response)
29
31
            self.__count += 1
30
 
            stats.save("%d-stats.callgrind" % (self.__count,), format="callgrind")
 
32
            stats.save("%d-stats.callgrind" % self.__count, format="callgrind")
31
33
            return ret
32
34
        finally:
33
35
            self.lock.release()
 
36
 
 
37