135
135
def assertCleanProfilerState(self, message='something did not clean up'):
136
136
"""Check whether profiler thread local is clean."""
137
for name in ('profiler', 'actions'):
137
for name in ('profiler', 'actions', 'memory_profile_start'):
139
139
getattr(profile._profilers, name, None), None,
140
140
'Profiler state (%s) is dirty; %s.' % (name, message))
159
159
profile._profilers.profiler.stop()
160
160
profile._profilers.profiler = None
161
161
profile._profilers.actions = None
162
profile._profilers.memory_profile_start = None
162
163
profile._profilers.profiling = False
163
164
super(TestCleanupProfiler, self).tearDown()
186
187
self.pushProfilingConfig(profiling_allowed='True')
187
188
profile.start_request(self._get_start_event('/'))
188
self.assertFalse(profile._profilers.profiling)
189
self.assertEqual(profile._profilers.actions, {})
189
190
self.assertIs(getattr(profile._profilers, 'profiler', None), None)
191
getattr(profile._profilers, 'actions', None), None)
192
getattr(profile._profilers, 'memory_profile_start', None), None)
193
194
def test_optional_profiling_with_show_request_starts_profiling(self):
194
195
# If profiling is allowed and a request with the "show" marker
196
197
self.pushProfilingConfig(profiling_allowed='True')
197
198
profile.start_request(self._get_start_event('/++profile++show/'))
198
199
self.assertIsInstance(profile._profilers.profiler, profile.Profiler)
201
getattr(profile._profilers, 'memory_profile_start', None),
199
203
self.assertEquals(set(profile._profilers.actions), set(('show', )))
201
205
def test_optional_profiling_with_callgrind_request_starts_profiling(self):
204
208
self.pushProfilingConfig(profiling_allowed='True')
205
209
profile.start_request(self._get_start_event('/++profile++callgrind/'))
206
210
self.assertIsInstance(profile._profilers.profiler, profile.Profiler)
212
getattr(profile._profilers, 'memory_profile_start', None),
207
214
self.assertEquals(
208
215
set(profile._profilers.actions), set(('callgrind', )))
213
220
self.pushProfilingConfig(profiling_allowed='True')
214
221
profile.start_request(self._get_start_event('/++profile++log/'))
215
222
self.assertIsInstance(profile._profilers.profiler, profile.Profiler)
224
getattr(profile._profilers, 'memory_profile_start', None),
216
226
self.assertEquals(
217
227
set(profile._profilers.actions), set(('callgrind', )))
223
233
profile.start_request(
224
234
self._get_start_event('/++profile++callgrind&show/'))
225
235
self.assertIsInstance(profile._profilers.profiler, profile.Profiler)
237
getattr(profile._profilers, 'memory_profile_start', None),
226
239
self.assertEquals(
227
240
set(profile._profilers.actions), set(('callgrind', 'show')))
236
249
profile.start_request(
237
250
self._get_start_event('/++profile++show&callgrind'))
238
251
self.assertIsInstance(profile._profilers.profiler, profile.Profiler)
253
getattr(profile._profilers, 'memory_profile_start', None),
239
255
self.assertEquals(
240
256
set(profile._profilers.actions), set(('callgrind', 'show')))
247
263
self._get_start_event('/++profile++pstats/'))
248
264
self.assertIsInstance(profile._profilers.profiler,
249
265
profile.Profiler)
267
getattr(profile._profilers, 'memory_profile_start', None),
250
269
self.assertEquals(set(profile._profilers.actions), set(('pstats',)))
252
271
def test_optional_profiling_with_log_pstats(self):
257
276
profile.start_request(
258
277
self._get_start_event('/++profile++log&pstats/'))
259
278
self.assertIsInstance(profile._profilers.profiler, profile.Profiler)
280
getattr(profile._profilers, 'memory_profile_start', None),
260
282
self.assertEquals(
261
283
set(profile._profilers.actions), set(('callgrind', 'pstats',)))
269
291
self._get_start_event('/++profile++pstats&callgrind/'))
270
292
self.assertIsInstance(profile._profilers.profiler,
271
293
profile.Profiler)
295
getattr(profile._profilers, 'memory_profile_start', None),
272
297
self.assertEquals(
273
298
set(profile._profilers.actions), set(('pstats', 'callgrind')))
278
303
profiling_allowed='True', profile_all_requests='True')
279
304
profile.start_request(self._get_start_event('/'))
280
305
self.assertIsInstance(profile._profilers.profiler, profile.Profiler)
307
getattr(profile._profilers, 'memory_profile_start', None),
281
309
self.assertEquals(
282
310
set(profile._profilers.actions), set(('callgrind', )))
287
315
self.pushProfilingConfig(profiling_allowed='True')
288
316
profile.start_request(self._get_start_event('/++profile++/'))
289
317
self.assertIs(getattr(profile._profilers, 'profiler', None), None)
319
getattr(profile._profilers, 'memory_profile_start', None),
290
321
self.assertEquals(set(profile._profilers.actions), set(('help', )))
292
323
def test_forced_profiling_with_wrong_request_helps(self):
296
327
profiling_allowed='True', profile_all_requests='True')
297
328
profile.start_request(self._get_start_event('/++profile++/'))
298
329
self.assertIsInstance(profile._profilers.profiler, profile.Profiler)
331
getattr(profile._profilers, 'memory_profile_start', None),
299
333
self.assertEquals(
300
334
set(profile._profilers.actions), set(('help', 'callgrind')))
304
338
profiling_allowed='True', memory_profile_log='.')
305
339
profile.start_request(self._get_start_event('/'))
306
340
self.assertIs(getattr(profile._profilers, 'profiler', None), None)
307
actions = profile._profilers.actions
308
self.assertEqual(set(actions), set(['memory_profile_start']))
309
self.assertIsInstance(actions['memory_profile_start'], tuple)
310
self.assertEqual(len(actions['memory_profile_start']), 2)
341
self.assertIsInstance(profile._profilers.memory_profile_start, tuple)
342
self.assertEqual(len(profile._profilers.memory_profile_start), 2)
343
self.assertEqual(profile._profilers.actions, {})
312
345
def test_combo_memory_and_profile_start(self):
313
346
self.pushProfilingConfig(
314
347
profiling_allowed='True', memory_profile_log='.')
315
348
profile.start_request(self._get_start_event('/++profile++show/'))
316
349
self.assertIsInstance(profile._profilers.profiler, profile.Profiler)
317
actions = profile._profilers.actions
318
self.assertEqual(set(actions), set(['memory_profile_start', 'show']))
319
self.assertIsInstance(actions['memory_profile_start'], tuple)
320
self.assertEqual(len(actions['memory_profile_start']), 2)
350
self.assertIsInstance(profile._profilers.memory_profile_start, tuple)
351
self.assertEqual(len(profile._profilers.memory_profile_start), 2)
352
self.assertEquals(set(profile._profilers.actions), set(('show', )))
322
354
def test_sqltrace_start(self):
323
355
self.pushProfilingConfig(profiling_allowed='True')
680
712
self.assertIsInstance(
681
713
profile._profilers.profiler, profile.Profiler)
682
714
self.assertEquals(
683
set(('show', 'callgrind', 'memory_profile_start')),
684
set(profile._profilers.actions))
715
set(('show', 'callgrind')), set(profile._profilers.actions))
687
718
class TestInlineProfiling(BaseRequestEndHandlerTest):