def _process_response(self, request, response): Logger.debug('Process response') with silk_meta_profiler(): collector = DataCollector() collector.stop_python_profiler() silk_request = collector.request if silk_request: silk_request = self.edit_request_model_function(silk_request, request) silk_response = ResponseModelFactory(response).construct_response_model() silk_response.save() silk_request.end_time = timezone.now() collector.finalise() else: Logger.error( 'No request model was available when processing response. ' 'Did something go wrong in process_request/process_view?' '\n' + str(request) + '\n\n' + str(response) ) # Need to save the data outside the silk_meta_profiler # Otherwise the meta time collected in the context manager # is not taken in account if silk_request: silk_request.save() Logger.debug('Process response done.')
def process_request(self, request): if _should_intercept(request): DataCollector().configure() with silk_meta_profiler(): request.silk_is_intercepted = True self._apply_dynamic_mappings() wrap_cursor_execute() request_model = RequestModelFactory(request).construct_request_model() request_model.save() DataCollector().request = request_model
def process_request(self, request): if _should_intercept(request): DataCollector().configure() with silk_meta_profiler(): request.silk_is_intercepted = True self._apply_dynamic_mappings() wrap_cursor_execute() request_model = RequestModelFactory( request).construct_request_model() request_model.save() DataCollector().request = request_model
def _process_response(self, response): with silk_meta_profiler(): collector = DataCollector() silk_request = collector.request if silk_request: silk_response = ResponseModelFactory(response).construct_response_model() silk_response.save() silk_request.end_time = timezone.now() collector.finalise() silk_request.save() else: Logger.error('No request model was available when processing response. Did something go wrong in process_request/process_view?')
def _process_response(self, request, response): with silk_meta_profiler(): collector = DataCollector() collector.stop_python_profiler() silk_request = collector.request if silk_request: silk_request.end_time = timezone.now() collector.finalise() if response.accepted_media_type == 'application/json': response['num_sql_queries'] = silk_request.num_sql_queries response[ 'time_spent_on_sql_queries'] = silk_request.time_spent_on_sql_queries response['time_taken'] = silk_request.time_taken
def _process_response(self, response): with silk_meta_profiler(): collector = DataCollector() collector.stop_python_profiler() silk_request = collector.request if silk_request: silk_response = ResponseModelFactory( response).construct_response_model() silk_response.save() silk_request.end_time = timezone.now() collector.finalise() silk_request.save() else: Logger.error( 'No request model was available when processing response. Did something go wrong in process_request/process_view?' )
def _process_response(self, response): with silk_meta_profiler(): collector = DataCollector() collector.stop_python_profiler() silk_request = collector.request if silk_request: try: silk_response = ResponseModelFactory(response).construct_response_model() except IntegrityError: raise #collector.finalise() else: silk_response.save() silk_request.end_time = datetime.datetime.now() collector.finalise() silk_request.save() else: Logger.error('No request model was available when processing response. Did something go wrong in process_request/process_view?')
def _process_response(self, response): Logger.debug('Process response') with silk_meta_profiler(): collector = DataCollector() collector.stop_python_profiler() silk_request = collector.request if silk_request: silk_response = ResponseModelFactory(response).construct_response_model() silk_response.save() else: Logger.error( 'No request model was available when processing response. Did something go wrong in process_request/process_view?') # Need to save the data outside the silk_meta_profiler # Otherwise the meta time collected in the context manager # is not taken in account if silk_request: silk_request.save() Logger.debug('Process response done.')
def _get_query_timing(self, request): try: from silk.collector import DataCollector from silk.profiling.profiler import silk_meta_profiler, silk_profile except ModuleNotFoundError: return if not hasattr(request, 'silk_is_intercepted'): return with silk_meta_profiler(): collector = DataCollector() silk_request = collector.request if silk_request: TimedService( name="sql", description="DB Queries", duration=sum( [s.time_taken for s in silk_request.queries.all()]), )