示例#1
0
 def test_optional_profiling_with_show_request_starts_profiling(self):
     # If profiling is allowed and a request with the "show" marker
     # URL segment is made, profiling starts.
     self.pushProfilingConfig(profiling_allowed='True')
     profile.start_request(self._get_start_event('/++profile++show/'))
     self.assertIsInstance(profile._profilers.profiler, profile.Profiler)
     self.assertEquals(set(profile._profilers.actions), set(('show', )))
示例#2
0
 def test_optional_profiling_with_wrong_request_helps(self):
     # If profiling is allowed and a request with the marker URL segment
     # is made incorrectly, profiling does not start and help is an action.
     self.pushProfilingConfig(profiling_allowed='True')
     profile.start_request(self._get_start_event('/++profile++/'))
     self.assertIs(getattr(profile._profilers, 'profiler', None), None)
     self.assertEqual(set(profile._profilers.actions), set(('help', )))
示例#3
0
 def test_optional_profiling_with_show_request_starts_profiling(self):
     # If profiling is allowed and a request with the "show" marker
     # URL segment is made, profiling starts.
     self.pushProfilingConfig(profiling_allowed='True')
     profile.start_request(self._get_start_event('/++profile++show/'))
     self.assertIsInstance(profile._profilers.profiler, profile.Profiler)
     self.assertEqual(set(profile._profilers.actions), set(('show', )))
示例#4
0
 def test_optional_profiling_with_wrong_request_helps(self):
     # If profiling is allowed and a request with the marker URL segment
     # is made incorrectly, profiling does not start and help is an action.
     self.pushProfilingConfig(profiling_allowed='True')
     profile.start_request(self._get_start_event('/++profile++/'))
     self.assertIs(getattr(profile._profilers, 'profiler', None), None)
     self.assertEquals(set(profile._profilers.actions), set(('help', )))
示例#5
0
 def test_optional_profiling_with_pstats_request_starts_profiling(self):
     # If profiling is allowed and a request with the "pstats" marker,
     # profiling starts with the pstats profiler.
     self.pushProfilingConfig(profiling_allowed='True')
     profile.start_request(self._get_start_event('/++profile++pstats/'))
     self.assertIsInstance(profile._profilers.profiler, profile.Profiler)
     self.assertEquals(set(profile._profilers.actions), set(('pstats', )))
示例#6
0
 def test_optional_profiling_with_log_request_starts_profiling(self):
     # If profiling is allowed and a request with the "log" marker URL
     # segment is made, profiling starts as a callgrind profile request.
     self.pushProfilingConfig(profiling_allowed='True')
     profile.start_request(self._get_start_event('/++profile++log/'))
     self.assertIsInstance(profile._profilers.profiler, profile.Profiler)
     self.assertEqual(
         set(profile._profilers.actions), set(('callgrind', )))
示例#7
0
 def test_forced_profiling_registers_action(self):
     # profile_all_requests should register as a callgrind action.
     self.pushProfilingConfig(
         profiling_allowed='True', profile_all_requests='True')
     profile.start_request(self._get_start_event('/'))
     self.assertIsInstance(profile._profilers.profiler, profile.Profiler)
     self.assertEquals(
         set(profile._profilers.actions), set(('callgrind', )))
示例#8
0
 def test_forced_profiling_registers_action(self):
     # profile_all_requests should register as a callgrind action.
     self.pushProfilingConfig(
         profiling_allowed='True', profile_all_requests='True')
     profile.start_request(self._get_start_event('/'))
     self.assertIsInstance(profile._profilers.profiler, profile.Profiler)
     self.assertEqual(
         set(profile._profilers.actions), set(('callgrind', )))
示例#9
0
 def test_optional_profiling_with_log_request_starts_profiling(self):
     # If profiling is allowed and a request with the "log" marker URL
     # segment is made, profiling starts as a callgrind profile request.
     self.pushProfilingConfig(profiling_allowed='True')
     profile.start_request(self._get_start_event('/++profile++log/'))
     self.assertIsInstance(profile._profilers.profiler, profile.Profiler)
     self.assertEquals(
         set(profile._profilers.actions), set(('callgrind', )))
示例#10
0
 def test_optional_profiling_without_marked_request_has_no_profile(self):
     # Even if profiling is allowed, it does not happen with a normal
     # request.
     self.pushProfilingConfig(profiling_allowed='True')
     profile.start_request(self._get_start_event('/'))
     self.assertFalse(profile._profilers.profiling)
     self.assertIs(getattr(profile._profilers, 'profiler', None), None)
     self.assertIs(getattr(profile._profilers, 'actions', None), None)
示例#11
0
 def test_optional_profiling_with_combined_request_starts_profiling(self):
     # If profiling is allowed and a request with the "callgrind" and
     # "show" marker URL segment is made, profiling starts.
     self.pushProfilingConfig(profiling_allowed='True')
     profile.start_request(
         self._get_start_event('/++profile++callgrind&show/'))
     self.assertIsInstance(profile._profilers.profiler, profile.Profiler)
     self.assertEquals(set(profile._profilers.actions),
                       set(('callgrind', 'show')))
示例#12
0
 def test_config_stops_profiling(self):
     """The ``profiling_allowed`` configuration should disable all
     profiling, even if it is requested"""
     self.pushProfilingConfig(
         profiling_allowed='False', profile_all_requests='True',
         memory_profile_log='.')
     profile.start_request(self._get_start_event(
         '/++profile++show&callgrind'))
     self.assertCleanProfilerState('config was ignored')
示例#13
0
 def test_config_stops_profiling(self):
     """The ``profiling_allowed`` configuration should disable all
     profiling, even if it is requested"""
     self.pushProfilingConfig(
         profiling_allowed='False', profile_all_requests='True',
         memory_profile_log='.')
     profile.start_request(self._get_start_event(
         '/++profile++show&callgrind'))
     self.assertCleanProfilerState('config was ignored')
示例#14
0
 def test_combo_memory_and_profile_start(self):
     self.pushProfilingConfig(
         profiling_allowed='True', memory_profile_log='.')
     profile.start_request(self._get_start_event('/++profile++show/'))
     self.assertIsInstance(profile._profilers.profiler, profile.Profiler)
     actions = profile._profilers.actions
     self.assertEqual(set(actions), set(['memory_profile_start', 'show']))
     self.assertIsInstance(actions['memory_profile_start'], tuple)
     self.assertEqual(len(actions['memory_profile_start']), 2)
示例#15
0
 def test_memory_profile_start(self):
     self.pushProfilingConfig(
         profiling_allowed='True', memory_profile_log='.')
     profile.start_request(self._get_start_event('/'))
     self.assertIs(getattr(profile._profilers, 'profiler', None), None)
     actions = profile._profilers.actions
     self.assertEqual(set(actions), set(['memory_profile_start']))
     self.assertIsInstance(actions['memory_profile_start'], tuple)
     self.assertEqual(len(actions['memory_profile_start']), 2)
示例#16
0
 def test_forced_profiling_with_wrong_request_helps(self):
     # If profiling is forced and a request with the marker URL segment
     # is made incorrectly, profiling starts and help is an action.
     self.pushProfilingConfig(
         profiling_allowed='True', profile_all_requests='True')
     profile.start_request(self._get_start_event('/++profile++/'))
     self.assertIsInstance(profile._profilers.profiler, profile.Profiler)
     self.assertEqual(
         set(profile._profilers.actions), set(('help', 'callgrind')))
示例#17
0
 def test_optional_profiling_without_marked_request_has_no_profile(self):
     # Even if profiling is allowed, it does not happen with a normal
     # request.
     self.pushProfilingConfig(profiling_allowed='True')
     profile.start_request(self._get_start_event('/'))
     self.assertFalse(profile._profilers.profiling)
     self.assertIs(getattr(profile._profilers, 'profiler', None), None)
     self.assertIs(
         getattr(profile._profilers, 'actions', None), None)
示例#18
0
 def test_sqltrace_filtered_start(self):
     self.pushProfilingConfig(profiling_allowed='True')
     profile.start_request(self._get_start_event(
         '/++profile++sqltrace:includes bugsubscription/'))
     self.assertIs(getattr(profile._profilers, 'profiler', None), None)
     self.assertEqual(set(profile._profilers.actions), set(('sql', )))
     data = profile._profilers.actions['sql']
     self.assertTrue(data['condition']('SELECT BUGSUBSCRIPTION FROM FOO'))
     self.assertEqual([], da.stop_sql_logging())
示例#19
0
 def test_sqltrace_filtered_start(self):
     self.pushProfilingConfig(profiling_allowed='True')
     profile.start_request(self._get_start_event(
         '/++profile++sqltrace:includes bugsubscription/'))
     self.assertIs(getattr(profile._profilers, 'profiler', None), None)
     self.assertEquals(set(profile._profilers.actions), set(('sql', )))
     data = profile._profilers.actions['sql']
     self.assertTrue(data['condition']('SELECT BUGSUBSCRIPTION FROM FOO'))
     self.assertEqual([], da.stop_sql_logging())
示例#20
0
 def test_combo_memory_and_profile_start(self):
     self.pushProfilingConfig(
         profiling_allowed='True', memory_profile_log='.')
     profile.start_request(self._get_start_event('/++profile++show/'))
     self.assertIsInstance(profile._profilers.profiler, profile.Profiler)
     actions = profile._profilers.actions
     self.assertEqual(set(actions), set(['memory_profile_start', 'show']))
     self.assertIsInstance(actions['memory_profile_start'], tuple)
     self.assertEqual(len(actions['memory_profile_start']), 2)
示例#21
0
 def test_forced_profiling_with_wrong_request_helps(self):
     # If profiling is forced and a request with the marker URL segment
     # is made incorrectly, profiling starts and help is an action.
     self.pushProfilingConfig(
         profiling_allowed='True', profile_all_requests='True')
     profile.start_request(self._get_start_event('/++profile++/'))
     self.assertIsInstance(profile._profilers.profiler, profile.Profiler)
     self.assertEquals(
         set(profile._profilers.actions), set(('help', 'callgrind')))
示例#22
0
 def test_memory_profile_start(self):
     self.pushProfilingConfig(
         profiling_allowed='True', memory_profile_log='.')
     profile.start_request(self._get_start_event('/'))
     self.assertIs(getattr(profile._profilers, 'profiler', None), None)
     actions = profile._profilers.actions
     self.assertEqual(set(actions), set(['memory_profile_start']))
     self.assertIsInstance(actions['memory_profile_start'], tuple)
     self.assertEqual(len(actions['memory_profile_start']), 2)
示例#23
0
 def test_optional_profiling_with_pstats_request_starts_profiling(self):
     # If profiling is allowed and a request with the "pstats" marker,
     # profiling starts with the pstats profiler.
     self.pushProfilingConfig(profiling_allowed='True')
     profile.start_request(
         self._get_start_event('/++profile++pstats/'))
     self.assertIsInstance(profile._profilers.profiler,
                           profile.Profiler)
     self.assertEquals(set(profile._profilers.actions), set(('pstats',)))
示例#24
0
 def test_optional_profiling_with_callgrind_pstats(self):
     # If profiling is allowed and a request with both the "pstats" and
     # "callgrind" markers, profiling starts with the bzr/callgrind
     # profiler.
     self.pushProfilingConfig(profiling_allowed='True')
     profile.start_request(
         self._get_start_event('/++profile++pstats&callgrind/'))
     self.assertIsInstance(profile._profilers.profiler, profile.Profiler)
     self.assertEquals(set(profile._profilers.actions),
                       set(('pstats', 'callgrind')))
示例#25
0
 def test_optional_profiling_with_callgrind_pstats(self):
     # If profiling is allowed and a request with both the "pstats" and
     # "callgrind" markers, profiling starts with the bzr/callgrind
     # profiler.
     self.pushProfilingConfig(profiling_allowed='True')
     profile.start_request(
         self._get_start_event('/++profile++pstats&callgrind/'))
     self.assertIsInstance(profile._profilers.profiler,
                           profile.Profiler)
     self.assertEquals(
         set(profile._profilers.actions), set(('pstats', 'callgrind')))
示例#26
0
 def test_optional_profiling_with_reversed_request_starts_profiling(self):
     # If profiling is allowed and a request with the "show" and the
     # "callgrind" marker URL segment is made, profiling starts.
     self.pushProfilingConfig(profiling_allowed='True')
     # The fact that this is reversed from the previous request is the only
     # difference from the previous test.  Also, it doesn't have a
     # trailing slash. :-P
     profile.start_request(
         self._get_start_event('/++profile++show&callgrind'))
     self.assertIsInstance(profile._profilers.profiler, profile.Profiler)
     self.assertEquals(
         set(profile._profilers.actions), set(('callgrind', 'show')))
示例#27
0
 def test_optional_profiling_with_reversed_request_starts_profiling(self):
     # If profiling is allowed and a request with the "show" and the
     # "callgrind" marker URL segment is made, profiling starts.
     self.pushProfilingConfig(profiling_allowed='True')
     # The fact that this is reversed from the previous request is the only
     # difference from the previous test.  Also, it doesn't have a
     # trailing slash. :-P
     profile.start_request(
         self._get_start_event('/++profile++show&callgrind'))
     self.assertIsInstance(profile._profilers.profiler, profile.Profiler)
     self.assertEqual(
         set(profile._profilers.actions), set(('callgrind', 'show')))
示例#28
0
 def endRequest(self, path='/', exception=None, pageid=None, work=None):
     start_event = self._get_start_event(path)
     da.set_request_started()
     profile.start_request(start_event)
     request = start_event.request
     if pageid is not None:
         request.setInWSGIEnvironment('launchpad.pageid', pageid)
     if work is not None:
         work()
     request.response.setResult(EXAMPLE_HTML)
     context = object()
     event = EndRequestEvent(context, request)
     if exception is not None:
         self.eru.raising((type(exception), exception, None), event.request)
     profile.end_request(event)
     da.clear_request_started()
     return event.request
示例#29
0
 def endRequest(self, path='/', exception=None, pageid=None, work=None):
     start_event = self._get_start_event(path)
     da.set_request_started()
     profile.start_request(start_event)
     request = start_event.request
     if pageid is not None:
         request.setInWSGIEnvironment('launchpad.pageid', pageid)
     if work is not None:
         work()
     request.response.setResult(EXAMPLE_HTML)
     context = object()
     event = EndRequestEvent(context, request)
     if exception is not None:
         self.eru.raising(
             (type(exception), exception, None), event.request)
     profile.end_request(event)
     da.clear_request_started()
     return event.request
示例#30
0
 def test_sql_start(self):
     self.pushProfilingConfig(profiling_allowed='True')
     profile.start_request(self._get_start_event('/++profile++sql/'))
     self.assertIs(getattr(profile._profilers, 'profiler', None), None)
     self.assertEquals(profile._profilers.actions, dict(sql=False))
     self.assertEqual([], da.stop_sql_logging())
示例#31
0
 def test_sql_start(self):
     self.pushProfilingConfig(profiling_allowed='True')
     profile.start_request(self._get_start_event('/++profile++sql/'))
     self.assertIs(getattr(profile._profilers, 'profiler', None), None)
     self.assertEqual(profile._profilers.actions, dict(sql=False))
     self.assertEqual([], da.stop_sql_logging())