Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / tools / telemetry / telemetry / core / backends / chrome / inspector_timeline.py
index 9492782..c4a240a 100644 (file)
@@ -2,7 +2,8 @@
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
-from telemetry.core.timeline import model
+from telemetry.core.backends.chrome import timeline_recorder
+from telemetry.timeline import inspector_timeline_data
 
 
 class TabBackendException(Exception):
@@ -10,7 +11,7 @@ class TabBackendException(Exception):
   pass
 
 
-class InspectorTimeline(object):
+class InspectorTimeline(timeline_recorder.TimelineRecorder):
   """Implementation of dev tools timeline."""
 
   class Recorder(object):
@@ -33,17 +34,19 @@ class InspectorTimeline(object):
       self._tab.StopTimelineRecording()
 
   def __init__(self, inspector_backend):
+    super(InspectorTimeline, self).__init__()
     self._inspector_backend = inspector_backend
     self._is_recording = False
-    self._timeline_model = None
+    self._raw_events = None
 
   @property
-  def timeline_model(self):
-    return self._timeline_model
+  def is_timeline_recording_running(self):
+    return self._is_recording
 
   def Start(self):
     """Starts recording."""
     assert not self._is_recording, 'Start should only be called once.'
+    self._raw_events = None
     self._is_recording = True
     self._inspector_backend.RegisterDomain(
         'Timeline', self._OnNotification, self._OnClose)
@@ -57,16 +60,23 @@ class InspectorTimeline(object):
     self._SendSyncRequest(request)
 
   def Stop(self):
-    """Stops recording and makes a TimelineModel with the event data."""
-    assert self._is_recording, 'Stop should be called after Start.'
+    """Stops recording and returns timeline event data."""
+    if not self._is_recording:
+      return None
     request = {'method': 'Timeline.stop'}
     result = self._SendSyncRequest(request)
-    raw_events = result['events']
-    self._timeline_model = model.TimelineModel(
-        event_data=raw_events, shift_world_to_zero=False)
     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 _SendSyncRequest(self, request, timeout=60):
     """Sends a devtools remote debugging protocol request.
 
@@ -91,10 +101,10 @@ class InspectorTimeline(object):
   def _OnNotification(self, msg):
     """Handler called when a message is received."""
     # Since 'Timeline.start' was invoked with the 'bufferEvents' parameter,
-    # there will be no timeline notifications while recording.
-    pass
+    # the events will arrive in Timeline.stopped event.
+    if msg['method'] == 'Timeline.stopped' and 'events' in msg['params']:
+      self._raw_events = msg['params']['events']
 
   def _OnClose(self):
     """Handler called when a domain is unregistered."""
     pass
-