Esempio n. 1
0
  def AddRawEventToThreadRecursive(thread, raw_inspector_event):
    pending_slice = None
    if ('startTime' in raw_inspector_event and
        'type' in raw_inspector_event):
      args = {}
      for x in raw_inspector_event:
        if x in ('startTime', 'endTime', 'children'):
          continue
        args[x] = raw_inspector_event[x]
      if len(args) == 0:
        args = None
      start_time = raw_inspector_event['startTime']
      end_time = raw_inspector_event.get('endTime', start_time)

      pending_slice = tracing_slice.Slice(
        thread, 'inspector',
        raw_inspector_event['type'],
        start_time,
        thread_timestamp=None,
        args=args)

    for child in raw_inspector_event.get('children', []):
      InspectorTimelineImporter.AddRawEventToThreadRecursive(
          thread, child)

    if pending_slice:
      pending_slice.duration = end_time - pending_slice.start
      thread.PushSlice(pending_slice)
Esempio n. 2
0
  def _GenerateResultsFromMockedIdleData(self):
    data = self._GenerateDataForEmptyPageSet()

    # Make a slice that looks like an idle task parent.
    slice_start_time = 0
    slow_slice_duration = 1000
    fast_slice_duration = 250
    parent_slice = data.AddSlice(
        task_execution_time.TaskExecutionTime.IDLE_SECTION_TRIGGER,
        slice_start_time,
        slow_slice_duration)
    # Add a sub-slice, this should be reported back as occuring in idle time.
    sub_slice = slice_data.Slice(
        None,
        'category',
        'slow_sub_slice',
        slice_start_time,
        slow_slice_duration,
        slice_start_time,
        slow_slice_duration,
        [])
    parent_slice.sub_slices.append(sub_slice)

    # Add a non-idle task.
    data.AddSlice('not_idle', slice_start_time, fast_slice_duration)

    # Run the code we are testing.
    self._measurement._AddResults(data.results)

    return data
Esempio n. 3
0
    def BeginSlice(self,
                   category,
                   name,
                   timestamp,
                   thread_timestamp=None,
                   args=None):
        """Opens a new slice for the thread.
    Calls to beginSlice and endSlice must be made with
    non-monotonically-decreasing timestamps.

    * category: Category to which the slice belongs.
    * name: Name of the slice to add.
    * timestamp: The timetsamp of the slice, in milliseconds.
    * thread_timestamp: Thread specific clock (scheduled) timestamp of the
                        slice, in milliseconds.
    * args: Arguments associated with

    Returns newly opened slice
    """
        if len(self._open_slices
               ) > 0 and timestamp < self._open_slices[-1].start:
            raise ValueError(
                'Slices must be added in increasing timestamp order')
        new_slice = tracing_slice.Slice(self,
                                        category,
                                        name,
                                        timestamp,
                                        thread_timestamp=thread_timestamp,
                                        args=args)
        self._open_slices.append(new_slice)
        new_slice.did_not_finish = True
        self.PushSlice(new_slice)
        return new_slice
 def AddEvent(self, process_name, event_category, event_name,
              start, duration, thread_start, thread_duration):
   thread = self.GetThreadForProcessName(process_name)
   record = slice_module.Slice(thread,
                            event_category,
                            event_name,
                            start, duration, thread_start, thread_duration)
   thread.PushSlice(record)
Esempio n. 5
0
 def _CreateEvent(self, event_name, ts, duration):
     event = tracing_slice.Slice(
         None,
         'cc,benchmark',
         event_name,
         ts,
         duration=duration,
         args={'begin_frame_id': self._begin_frame_id})
     self._events.append(event)
     return event
Esempio n. 6
0
 def AddAsyncSlice(self, name, timestamp, duration, args):
   new_slice = slice_data.Slice(
       None,
       'category',
       name,
       timestamp,
       duration,
       timestamp,
       duration,
       args)
   self._renderer_thread.async_slices.append(new_slice)
   return new_slice
Esempio n. 7
0
def _CreateGPUSlices(parent_thread, name, start_time, duration, offset=0):
  args = {'gl_category': gpu_timeline.TOPLEVEL_GL_CATEGORY}
  return (slice_module.Slice(parent_thread,
                             gpu_timeline.TOPLEVEL_SERVICE_CATEGORY,
                             name, start_time,
                             args=args,
                             duration=duration,
                             thread_duration=duration),
          async_slice_module.AsyncSlice(gpu_timeline.TOPLEVEL_DEVICE_CATEGORY,
                             name, start_time + offset,
                             args=args,
                             duration=duration))
Esempio n. 8
0
 def AddSlice(self, name, timestamp, duration):
   new_slice = slice_data.Slice(
       None,
       'category',
       name,
       timestamp,
       duration,
       timestamp,
       duration,
       [])
   self._renderer_thread.all_slices.append(new_slice)
   return new_slice
Esempio n. 9
0
 def PushCompleteSlice(self, category, name, timestamp, duration,
                       thread_timestamp, thread_duration, args=None):
   new_slice = slice_module.Slice(self, category, name, timestamp,
                                  thread_timestamp=thread_timestamp,
                                  args=args)
   if duration == None:
     new_slice.did_not_finish = True
   else:
     new_slice.duration = duration
     new_slice.thread_duration = thread_duration
   self.PushSlice(new_slice)
   return new_slice
Esempio n. 10
0
    def testFrameEventMissingBeginFrameId(self):
        timeline = model.TimelineModel()
        process = timeline.GetOrCreateProcess(pid=1)
        main_thread = process.GetOrCreateThread(tid=11)
        timeline_range = timeline_bounds.Bounds()

        # Create an event without the begin_frame_id argument
        event = tracing_slice.Slice(None, 'cc,benchmark',
                                    RenderingFrame.begin_main_frame_event, 0)
        main_thread.PushSlice(event)
        process.FinalizeImport()
        self.assertRaises(Exception, GetFrameEventsInsideRange, process,
                          timeline_range)
Esempio n. 11
0
def _CreateFrameEndSlices(parent_thread, start_time, duration, offset=0):
    args = {'gl_category': gpu_timeline.TOPLEVEL_GL_CATEGORY}
    return (slice_module.Slice(parent_thread,
                               SERVICE_FRAME_END_CATEGORY,
                               SERVICE_FRAME_END_NAME,
                               start_time,
                               args=args,
                               duration=duration,
                               thread_duration=duration),
            async_slice_module.AsyncSlice(DEVICE_FRAME_END_CATEGORY,
                                          DEVICE_FRAME_END_NAME,
                                          start_time + offset,
                                          args=args,
                                          duration=duration))
Esempio n. 12
0
 def PushMarkSlice(self,
                   category,
                   name,
                   timestamp,
                   thread_timestamp,
                   args=None):
     new_slice = slice_module.Slice(self,
                                    category,
                                    name,
                                    timestamp,
                                    thread_timestamp=thread_timestamp,
                                    args=args)
     self.PushSlice(new_slice)
     return new_slice
Esempio n. 13
0
    def testIdleTasksAreReported(self):
        task_execution_time_metric = task_execution_time.TaskExecutionTime()
        ps = self.CreateEmptyPageSet()
        page = TestTaskExecutionTimePage(ps, ps.base_dir)
        ps.AddUserStory(page)

        # Get the name of a thread used by task_execution_time metric and set up
        # some dummy execution data pretending to be from that thread & process.
        first_thread_name = task_execution_time_metric._RENDERER_THREADS[0]
        data = TaskExecutionTestData(first_thread_name)
        task_execution_time_metric._renderer_process = data._renderer_process

        # Pretend we're about to run the tests to silence lower level asserts.
        data.results.WillRunPage(page)

        # Make a slice that looks like an idle task parent.
        slice_start_time = 0
        slice_duration = 1000
        parent_slice = data.AddSlice(
            task_execution_time_metric.IDLE_SECTION_TRIGGER, slice_start_time,
            slice_duration)
        # Add a sub-slice, this should be reported back as occuring in idle time.
        sub_slice = slice_data.Slice(None, 'category', 'slow_sub_slice',
                                     slice_start_time, slice_duration)
        parent_slice.sub_slices.append(sub_slice)

        # Add a non-idle task.
        data.AddSlice('not_idle', slice_start_time, slice_duration)

        # Run the code we are testing.
        task_execution_time_metric.ValidateAndMeasurePage(
            None, None, data.results)

        # The 'slow_sub_slice' should be inside the Idle section and therefore
        # removed from the results.
        for result in data.results.all_page_specific_values:
            if 'slow_sub_slice' in result.name:
                self.fail('Tasks within idle section should not be reported')

        # The 'not_idle' slice should not have the IDLE_SECTION added to its name
        # and should exist.
        for result in data.results.all_page_specific_values:
            if 'not_idle' in result.name:
                self.assertTrue(
                    task_execution_time_metric.IDLE_SECTION not in result.name)
                break
        else:
            self.fail('Task was incorrectly marked as Idle')
Esempio n. 14
0
 def AddEvent(self,
              process_name,
              event_category,
              event_name,
              start,
              duration,
              thread_start=None,
              thread_duration=None):
     thread = self.GetThreadForProcessName(process_name)
     record = slice_module.Slice(
         thread, event_category, event_name, start, duration,
         start if thread_start is None else thread_start,
         duration if thread_duration is None else thread_duration)
     thread.PushSlice(record)
     if self.parent_slice is not None:
         record.parent_slice = self.parent_slice
         self.parent_slice.AddSubSlice(record)
     return SliceContext(self, record)
 def CreateTestSliceFromTimeRanges(
     self, parent_thread, time_start, time_end, thread_start, thread_end):
   duration = time_end - time_start
   thread_duration = thread_end - thread_start
   return slice_module.Slice(parent_thread, 'Test', 'foo', time_start,
                             duration, thread_start, thread_duration)