~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/services/profile/tests.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-10-03 15:22:48 UTC
  • mfrom: (8758.4.18 garbo-lockfile)
  • Revision ID: launchpad@pqm.canonical.com-20111003152248-cv30fo2i8p0mu5mb
[r=lifeless][bug=553254] Regularly prune LoginToken rows

Show diffs side-by-side

added added

removed removed

Lines of Context:
134
134
 
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'):
138
138
            self.assertIs(
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()
164
165
 
185
186
        # request.
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)
190
191
        self.assertIs(
191
 
            getattr(profile._profilers, 'actions', None), None)
 
192
            getattr(profile._profilers, 'memory_profile_start', None), None)
192
193
 
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)
 
200
        self.assertIs(
 
201
            getattr(profile._profilers, 'memory_profile_start', None),
 
202
            None)
199
203
        self.assertEquals(set(profile._profilers.actions), set(('show', )))
200
204
 
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)
 
211
        self.assertIs(
 
212
            getattr(profile._profilers, 'memory_profile_start', None),
 
213
            None)
207
214
        self.assertEquals(
208
215
            set(profile._profilers.actions), set(('callgrind', )))
209
216
 
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)
 
223
        self.assertIs(
 
224
            getattr(profile._profilers, 'memory_profile_start', None),
 
225
            None)
216
226
        self.assertEquals(
217
227
            set(profile._profilers.actions), set(('callgrind', )))
218
228
 
223
233
        profile.start_request(
224
234
            self._get_start_event('/++profile++callgrind&show/'))
225
235
        self.assertIsInstance(profile._profilers.profiler, profile.Profiler)
 
236
        self.assertIs(
 
237
            getattr(profile._profilers, 'memory_profile_start', None),
 
238
            None)
226
239
        self.assertEquals(
227
240
            set(profile._profilers.actions), set(('callgrind', 'show')))
228
241
 
236
249
        profile.start_request(
237
250
            self._get_start_event('/++profile++show&callgrind'))
238
251
        self.assertIsInstance(profile._profilers.profiler, profile.Profiler)
 
252
        self.assertIs(
 
253
            getattr(profile._profilers, 'memory_profile_start', None),
 
254
            None)
239
255
        self.assertEquals(
240
256
            set(profile._profilers.actions), set(('callgrind', 'show')))
241
257
 
247
263
            self._get_start_event('/++profile++pstats/'))
248
264
        self.assertIsInstance(profile._profilers.profiler,
249
265
                              profile.Profiler)
 
266
        self.assertIs(
 
267
            getattr(profile._profilers, 'memory_profile_start', None),
 
268
            None)
250
269
        self.assertEquals(set(profile._profilers.actions), set(('pstats',)))
251
270
 
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)
 
279
        self.assertIs(
 
280
            getattr(profile._profilers, 'memory_profile_start', None),
 
281
            None)
260
282
        self.assertEquals(
261
283
            set(profile._profilers.actions), set(('callgrind', 'pstats',)))
262
284
 
269
291
            self._get_start_event('/++profile++pstats&callgrind/'))
270
292
        self.assertIsInstance(profile._profilers.profiler,
271
293
                              profile.Profiler)
 
294
        self.assertIs(
 
295
            getattr(profile._profilers, 'memory_profile_start', None),
 
296
            None)
272
297
        self.assertEquals(
273
298
            set(profile._profilers.actions), set(('pstats', 'callgrind')))
274
299
 
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)
 
306
        self.assertIs(
 
307
            getattr(profile._profilers, 'memory_profile_start', None),
 
308
            None)
281
309
        self.assertEquals(
282
310
            set(profile._profilers.actions), set(('callgrind', )))
283
311
 
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)
 
318
        self.assertIs(
 
319
            getattr(profile._profilers, 'memory_profile_start', None),
 
320
            None)
290
321
        self.assertEquals(set(profile._profilers.actions), set(('help', )))
291
322
 
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)
 
330
        self.assertIs(
 
331
            getattr(profile._profilers, 'memory_profile_start', None),
 
332
            None)
299
333
        self.assertEquals(
300
334
            set(profile._profilers.actions), set(('help', 'callgrind')))
301
335
 
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, {})
311
344
 
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', )))
321
353
 
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))
685
716
 
686
717
 
687
718
class TestInlineProfiling(BaseRequestEndHandlerTest):