def testHasThreadTimestamps(self): # No thread_start and no thread_duration event_1 = event.TimelineEvent('test', 'foo', 0, 10) # Has thread_start but no thread_duration event_2 = event.TimelineEvent('test', 'foo', 0, 10, 2) # Has thread_duration but no thread_start event_3 = event.TimelineEvent('test', 'foo', 0, 10, None, 4) # Has thread_start and thread_duration event_4 = event.TimelineEvent('test', 'foo', 0, 10, 2, 4) self.assertFalse(event_1.has_thread_timestamps) self.assertFalse(event_2.has_thread_timestamps) self.assertFalse(event_3.has_thread_timestamps) self.assertTrue(event_4.has_thread_timestamps)
def MakeNetworkTimelineEvent( url, response_headers, body=None, base64_encoded_body=False, served_from_cache=False, request_headers=None, status=200, remote_port=None): if not request_headers: request_headers = {} e = event.TimelineEvent('network', 'HTTPResponse', 0, 0) e.args = {} e.args['requestId'] = 0 e.args['response'] = { 'status': status, 'url': url, 'headers': response_headers, 'requestHeaders': request_headers, 'remotePort': remote_port, } e.args['body'] = body e.args['base64_encoded_body'] = base64_encoded_body e.args['served_from_cache'] = served_from_cache return e
def AddEvent(self, event_name, start, duration=None): event = timeline_event.TimelineEvent('my_category', event_name, start, duration) self.events.append(event)
def SetTraceBufferOverflowTimestamp(self, timestamp): # TODO: use instant event for trace_buffer_overflow_event self._trace_buffer_overflow_event = event_module.TimelineEvent( "TraceBufferInfo", "trace_buffer_overflowed", timestamp, 0)
def analyze_trace_and_append_actions(self, project, trace_info, process, bounds, extended_info): threads = self.get_threads(process) renderer_thread = self.get_thread_by_name(process, 'CrRendererMain') time_ranges = self.get_time_ranges(renderer_thread) labels = extended_info['labels'] secret = extended_info['secret'] status = '' records_imported = [] if project == None: status = "No project found with secret %s" % secret return None # If a single label is provided... if (self.is_single_label(labels)): labels = self.wrap_labels_in_list_if_needed(labels) #...and the Action of that label is for a Load Action, the trace is # considered to match entirely to the Action. If the Action is not a # Load Action, then only the ranges will be matched. if (self.label_is_for_load_action(project, labels)): status = 'Single label (%s), label is for load action' % labels[ 0] # Ignore time ranges and reset to the whole window time_ranges = [ trace_event.TimelineEvent(category='Load', name=labels[0], start=bounds.min, duration=(bounds.max - bounds.min)) ] records_imported = self.create_action_details_from_trace( project, labels, time_ranges, threads, trace_info, extended_info) # If the Action of that label is not a Load Action, then look for # time ranges of that label. else: status = 'Single label (%s), label is not for a Load Action' % labels[ 0] records_imported = self.create_action_details_from_trace( project, labels, time_ranges, threads, trace_info, extended_info) # If multiple labels are provided and the trace contains ranges, # those ranges will be mapped to existing Actions in the Project # with those labels. elif (self.is_multi_label(labels) and len(time_ranges) > 0): status = 'Multiple labels, trace contains ranges' records_imported = self.create_action_details_from_trace( project, labels, time_ranges, threads, trace_info, extended_info) # If multiple labels are provided and the trace does not contain ranges, # no Actions will be findable, so the import will be a no-op. elif (self.is_multi_label(labels) and len(time_ranges) == 0): # If, however, only one of the labels provided is for a Load Action, # then the trace will be assumed to match to that Action. action = self.get_single_load_action_from_multi_label( project, labels) # Only go ahead if we found a single Load Action if (action != None): status = ('Multiple labels, trace contains no ranges. ' 'Single Load Action label found.') # Ignore time ranges and reset to the whole window time_ranges = [ trace_event.TimelineEvent(category=action.name, name=action.label, start=bounds.min, duration=(bounds.max - bounds.min)) ] records_imported = self.create_action_details_from_trace( project, [action.name], time_ranges, threads, trace_info, extended_info) # If no labels are provided.. elif (len(labels) == 0): # ...and no ranges exist, then a match will be assumed if and # only if there is one Load Action in the Project. if (len(time_ranges) == 0): action = self.get_single_load_action_from_project(project) if (action != None): status = ('No labels, trace contains no ranges. ' 'Single Load Action in project found.') time_ranges = [ trace_event.TimelineEvent(category=action.name, name=action.label, start=bounds.min, duration=(bounds.max - bounds.min)) ] records_imported = self.create_action_details_from_trace( project, [action.name], time_ranges, threads, trace_info, extended_info) else: status = ('No labels, trace contains no ranges. ' 'Zero or multiple Load Actions found.') # If time ranges do exist, then Actions will be created for those time # ranges as necessary during the import. elif (len(time_ranges) > 0): status = ('No labels, trace contains ranges. ' 'Actions will be created on demand.') records_imported = self.create_action_details_from_trace( project, [], time_ranges, threads, trace_info, extended_info) else: status = 'Unknown import error.' self.log(project, trace_info, extended_info, status, len(records_imported)) return records_imported