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

Changeset 1194

Show
Ignore:
Timestamp:
07/10/06 13:24:52
Author:
fumanchu
Message:

New ProfileAggregator? class.

Files:

Legend:

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

    r1193 r1194  
    2121 
    2222 
     23You can also turn on profiling for all requests 
     24using the make_app function as WSGI middleware. 
     25 
     26 
    2327CherryPy developers 
    2428=================== 
    2529 
    26 This module can be used whenever you make changes to CherryPy, to get a 
    27 quick sanity-check on overall CP performance. Set the config entry: 
    28 "profiling.on = True" to turn on profiling. Then, use the serve() 
     30This module can be used whenever you make changes to CherryPy, 
     31to get a quick sanity-check on overall CP performance. Use the 
     32"--profile" flag when running the test suite. Then, use the serve() 
    2933function to browse the results in a web browser. If you run this 
    3034module from the command line, it will call serve() for you. 
     
    6367 
    6468 
     69_count = 0 
     70 
    6571class Profiler(object): 
    6672     
     
    7177        if not os.path.exists(path): 
    7278            os.makedirs(path) 
    73         self.count = 0 
    7479     
    7580    def run(self, func, *args): 
    7681        """run(func, *args). Run func, dumping profile data into self.path.""" 
    77         self.count += 1 
    78         path = os.path.join(self.path, "cp_%04d.prof" % self.count) 
     82        global _count 
     83        c = _count = _count + 1 
     84        path = os.path.join(self.path, "cp_%04d.prof" % c) 
    7985        prof = profile.Profile() 
    8086        result = prof.runcall(func, *args) 
     
    129135 
    130136 
     137class ProfileAggregator(Profiler): 
     138     
     139    def __init__(self, path=None): 
     140        Profiler.__init__(self, path) 
     141        global _count 
     142        self.count = _count = _count + 1 
     143        self.profiler = profile.Profile() 
     144     
     145    def run(self, func, *args): 
     146        path = os.path.join(self.path, "cp_%04d.prof" % self.count) 
     147        result = self.profiler.runcall(func, *args) 
     148        self.profiler.dump_stats(path) 
     149        return result 
     150 
     151 
    131152class make_app: 
    132     def __init__(self, nextapp, path=None): 
     153    def __init__(self, nextapp, path=None, aggregate=False): 
    133154        """Make a WSGI middleware app which wraps 'nextapp' with profiling.""" 
    134155        self.nextapp = nextapp 
    135         self.profiler = Profiler(path) 
     156        self.aggregate = aggregate 
     157        if aggregate: 
     158            self.profiler = ProfileAggregator(path) 
     159        else: 
     160            self.profiler = Profiler(path) 
    136161     
    137162    def __call__(self, environ, start_response): 
  • trunk/cherrypy/test/helper.py

    r1193 r1194  
    124124            if conf.get("profiling.on", False): 
    125125                apps.append((base, profiler.make_app(_cpwsgi.wsgiApp))) 
     126##                apps.append((base, profiler.make_app(_cpwsgi.wsgiApp, aggregate=True))) 
    126127            else: 
    127128                apps.append((base, _cpwsgi.wsgiApp)) 

Hosted by WebFaction

Log in as guest/cpguest to create tickets