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', )))
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', )))
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', )))
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', )))
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', )))
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', )))
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', )))
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', )))
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', )))
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)
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')))
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')
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)
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)
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')))
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)
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())
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())
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')))
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',)))
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')))
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')))
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')))
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')))
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
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
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())
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())