def Stop(self): if not self._is_recording: return None responses = self._inspector_network.GetResponseData() events = [r.AsTimelineEvent() for r in list(responses)] self._inspector_network.StopMonitoringNetwork() self._is_recording = False if len(events) == 0: return None return inspector_timeline_data.InspectorTimelineData(events)
def Stop(self): """Stops recording and returns timeline event data.""" if not self._is_recording: return None request = {'method': 'Timeline.stop'} result = self._SendSyncRequest(request) self._inspector_backend.UnregisterDomain('Timeline') self._is_recording = False raw_events = result['events'] return inspector_timeline_data.InspectorTimelineData(raw_events)
def testOutOfOrderData(self): raw_event = { 'startTime': 5295.004, 'endTime': 5305.004, 'data': {}, 'type': 'Program', 'children': [{ 'startTime': 5295.004, 'data': { 'id': 0 }, 'type': 'BeginFrame', }, { 'startTime': 4492.973, 'endTime': 4493.086, 'data': { 'rootNode': -3 }, 'type': 'PaintSetup' }, { 'startTime': 5298.004, 'endTime': 5301.004, 'type': 'Paint', 'frameId': '53228.1', 'data': { 'rootNode': -3, 'clip': [0, 0, 1018, 0, 1018, 764, 0, 764], 'layerId': 10 }, 'children': [] }, { 'startTime': 5301.004, 'endTime': 5305.004, 'data': {}, 'type': 'CompositeLayers', 'children': [] }, { 'startTime': 5305.004, 'data': {}, 'type': 'MarkFirstPaint' }] } timeline_data = inspector_timeline_data.InspectorTimelineData( [raw_event]) model.TimelineModel(timeline_data=timeline_data, shift_world_to_zero=False)
def testImport(self): messages = [_BACKGROUND_MESSAGE, _SAMPLE_MESSAGE] timeline_data = inspector_timeline_data.InspectorTimelineData(messages) m = model.TimelineModel(timeline_data=timeline_data, shift_world_to_zero=False) self.assertEquals(1, len(m.processes)) process = m.processes.values()[0] threads = process.threads self.assertEquals(2, len(threads)) renderer_thread = threads[0] self.assertEquals(1, len(renderer_thread.toplevel_slices)) self.assertEquals('Program', renderer_thread.toplevel_slices[0].name) second_thread = threads['2'] self.assertEquals(1, len(second_thread.toplevel_slices)) self.assertEquals('BeginFrame', second_thread.toplevel_slices[0].name)
def Stop(self): """Stops recording and returns timeline event data.""" if not self._is_recording: return None request = {'method': 'Timeline.stop'} result = self._SendSyncRequest(request) self._inspector_backend.UnregisterDomain('Timeline') self._is_recording = False # TODO: Backward compatibility. Needs to be removed when # M38 becomes stable. if 'events' in result: raw_events = result['events'] else: # In M38 events will arrive via Timeline.stopped event. raw_events = self._raw_events self._raw_events = None return inspector_timeline_data.InspectorTimelineData(raw_events)
def _TestJsonTimelineExpectation(self, filename, viewport, expected): """Check whether the result for some timeline data is as expected. Args: filename: Filename of a json file which contains a expected: The result expected based on the WPT result. """ tab = FakeTab() impl = speedindex.PaintRectSpeedIndexImpl() file_path = os.path.join(_TEST_DIR, filename) with open(file_path) as json_file: raw_events = json.load(json_file) timeline_data = inspector_timeline_data.InspectorTimelineData(raw_events) tab.timeline_model.SetAllEvents( model.TimelineModel(timeline_data=timeline_data).GetAllEvents()) tab.SetEvaluateJavaScriptResult(viewport) actual = impl.CalculateSpeedIndex(tab) # The result might differ by 1 or more milliseconds due to rounding, # so compare to the nearest 10 milliseconds. self.assertAlmostEqual(actual, expected, places=-1)
# pylint: disable=W0212 import json import os import unittest from telemetry.core import bitmap from telemetry.timeline import inspector_timeline_data from telemetry.timeline import model from metrics import speedindex # Sample timeline data in the json format provided by devtools. # The sample events will be used in several tests below. _TEST_DIR = os.path.join(os.path.dirname(__file__), 'unittest_data') _SAMPLE_DATA = json.load(open(os.path.join(_TEST_DIR, 'sample_timeline.json'))) _SAMPLE_TIMELINE_DATA = inspector_timeline_data.InspectorTimelineData( _SAMPLE_DATA) _SAMPLE_EVENTS = model.TimelineModel( timeline_data=_SAMPLE_TIMELINE_DATA).GetAllEvents() class FakeTimelineModel(object): def __init__(self): self._events = [] def SetAllEvents(self, events): self._events = events def GetAllEvents(self): return self._events