Changeset 1194
- Timestamp:
- 07/10/06 13:24:52
- Files:
-
- trunk/cherrypy/lib/profiler.py (modified) (4 diffs)
- trunk/cherrypy/test/helper.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/lib/profiler.py
r1193 r1194 21 21 22 22 23 You can also turn on profiling for all requests 24 using the make_app function as WSGI middleware. 25 26 23 27 CherryPy developers 24 28 =================== 25 29 26 This module can be used whenever you make changes to CherryPy, to get a27 quick sanity-check on overall CP performance. Set the config entry: 28 " profiling.on = True" to turn on profiling. Then, use the serve()30 This module can be used whenever you make changes to CherryPy, 31 to get a quick sanity-check on overall CP performance. Use the 32 "--profile" flag when running the test suite. Then, use the serve() 29 33 function to browse the results in a web browser. If you run this 30 34 module from the command line, it will call serve() for you. … … 63 67 64 68 69 _count = 0 70 65 71 class Profiler(object): 66 72 … … 71 77 if not os.path.exists(path): 72 78 os.makedirs(path) 73 self.count = 074 79 75 80 def run(self, func, *args): 76 81 """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) 79 85 prof = profile.Profile() 80 86 result = prof.runcall(func, *args) … … 129 135 130 136 137 class 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 131 152 class make_app: 132 def __init__(self, nextapp, path=None ):153 def __init__(self, nextapp, path=None, aggregate=False): 133 154 """Make a WSGI middleware app which wraps 'nextapp' with profiling.""" 134 155 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) 136 161 137 162 def __call__(self, environ, start_response): trunk/cherrypy/test/helper.py
r1193 r1194 124 124 if conf.get("profiling.on", False): 125 125 apps.append((base, profiler.make_app(_cpwsgi.wsgiApp))) 126 ## apps.append((base, profiler.make_app(_cpwsgi.wsgiApp, aggregate=True))) 126 127 else: 127 128 apps.append((base, _cpwsgi.wsgiApp))

