Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Changeset 1193

Show
Ignore:
Timestamp:
07/10/06 01:25:49
Author:
fumanchu
Message:

Moved profiling into WSGI middleware.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cherrypy/_cprequest.py

    r1188 r1193  
    99from cherrypy import _cpcgifs 
    1010from cherrypy._cperror import format_exc, bare_error 
    11 from cherrypy.lib import http, profiler 
     11from cherrypy.lib import http 
    1212 
    1313 
     
    139139        self.handler = None 
    140140         
    141         # Set up the profiler if requested. 
    142         conf = cherrypy.config.get 
    143         if conf("profiling.on", False): 
    144             p = getattr(cherrypy, "profiler", None) 
    145             if p is None: 
    146                 ppath = conf("profiling.path", "") 
    147                 p = cherrypy.profiler = profiler.Profiler(ppath) 
    148             cherrypy.profiler.run(self._run) 
    149         else: 
    150             self._run() 
    151          
    152         if self.method == "HEAD": 
    153             # HEAD requests MUST NOT return a message-body in the response. 
    154             cherrypy.response.body = [] 
    155          
    156         log_access = cherrypy.config.get("log_access", cherrypy.log_access) 
    157         if log_access: 
    158             log_access() 
    159          
    160         return cherrypy.response 
    161      
    162     def _run(self): 
    163141        try: 
    164142            self.process_request_line() 
     
    198176                raise 
    199177            self.handle_error(sys.exc_info()) 
     178         
     179        if self.method == "HEAD": 
     180            # HEAD requests MUST NOT return a message-body in the response. 
     181            cherrypy.response.body = [] 
     182         
     183        log_access = cherrypy.config.get("log_access", cherrypy.log_access) 
     184        if log_access: 
     185            log_access() 
     186         
     187        return cherrypy.response 
    200188     
    201189    def respond(self, path_info): 
  • trunk/cherrypy/lib/profiler.py

    r1095 r1193  
    7878        path = os.path.join(self.path, "cp_%04d.prof" % self.count) 
    7979        prof = profile.Profile() 
    80         prof.runcall(func, *args) 
     80        result = prof.runcall(func, *args) 
    8181        prof.dump_stats(path) 
     82        return result 
    8283     
    8384    def statfiles(self): 
     
    128129 
    129130 
     131class make_app: 
     132    def __init__(self, nextapp, path=None): 
     133        """Make a WSGI middleware app which wraps 'nextapp' with profiling.""" 
     134        self.nextapp = nextapp 
     135        self.profiler = Profiler(path) 
     136     
     137    def __call__(self, environ, start_response): 
     138        def gather(): 
     139            result = [] 
     140            for line in self.nextapp(environ, start_response): 
     141                result.append(line) 
     142            return result 
     143        return self.profiler.run(gather) 
     144 
     145 
    130146def serve(path=None, port=8080): 
    131147    import cherrypy 
  • trunk/cherrypy/test/helper.py

    r1188 r1193  
    2424 
    2525import cherrypy 
    26 from cherrypy.lib import http 
     26from cherrypy.lib import http, profiler 
    2727import webtest 
    2828 
     
    122122            if base == "/": 
    123123                base = "" 
    124             apps.append((base, _cpwsgi.wsgiApp)) 
     124            if conf.get("profiling.on", False): 
     125                apps.append((base, profiler.make_app(_cpwsgi.wsgiApp))) 
     126            else: 
     127                apps.append((base, _cpwsgi.wsgiApp)) 
    125128##            # We could use the following line, but it breaks test_tutorials 
    126129##            apps.append((base, _cpwsgi.make_app(app))) 

Hosted by WebFaction

Log in as guest/cpguest to create tickets