Commit dee6778b authored by nednguyen@google.com's avatar nednguyen@google.com

Replace loading_resources with is_respsonsive. Add repr for...

Replace loading_resources with is_respsonsive. Add repr for timeline_interaction_record. This is a partial land of https://codereview.chromium.org/273103003/

TBR=nduca@chromium.org

BUG=345922

Review URL: https://codereview.chromium.org/311833003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@274610 0039d316-1c4b-4281-b951-d872f2087c98
parent eff8b90c
......@@ -33,7 +33,7 @@ class TimelineBasedMetricsTests(unittest.TestCase):
start_thread=renderer_thread, end_thread=renderer_thread,
thread_start=5, thread_duration=15))
renderer_thread.async_slices.append(async_slice.AsyncSlice(
'cat', 'Interaction.LogicalName2/is_loading_resources',
'cat', 'Interaction.LogicalName2/is_responsive',
timestamp=25, duration=5,
start_thread=renderer_thread, end_thread=renderer_thread,
thread_start=25, thread_duration=5))
......@@ -51,7 +51,7 @@ class TimelineBasedMetricsTests(unittest.TestCase):
self.assertEquals(0, interactions[0].start)
self.assertEquals(20, interactions[0].end)
self.assertTrue(interactions[1].is_loading_resources)
self.assertTrue(interactions[1].is_responsive)
self.assertEquals(25, interactions[1].start)
self.assertEquals(30, interactions[1].end)
......@@ -73,7 +73,7 @@ class TimelineBasedMetricsTests(unittest.TestCase):
res = []
if interaction.is_smooth:
res.append(FakeSmoothMetric())
if interaction.is_loading_resources:
if interaction.is_responsive:
res.append(FakeLoadingMetric())
return res
......
......@@ -9,11 +9,11 @@ import telemetry.core.timeline.bounds as timeline_bounds
IS_SMOOTH = 'is_smooth'
IS_LOADING_RESOURCES = 'is_loading_resources'
IS_RESPONSIVE = 'is_responsive'
FLAGS = [
IS_SMOOTH,
IS_LOADING_RESOURCES
IS_RESPONSIVE
]
......@@ -22,6 +22,9 @@ class ThreadTimeRangeOverlappedException(Exception):
with other events.
"""
class NoThreadTimeDataException(ThreadTimeRangeOverlappedException):
"""Exception that can be thrown if there is not sufficient thread time data
to compute the overlapped thread time range."""
def IsTimelineInteractionRecord(event_name):
return event_name.startswith('Interaction.')
......@@ -52,7 +55,7 @@ class TimelineInteractionRecord(object):
is currently done by pushing markers into the console.time/timeEnd API: this
for instance can be issued in JS:
var str = 'Interaction.SendEmail/is_smooth,is_loading_resources';
var str = 'Interaction.SendEmail/is_smooth,is_responsive';
console.time(str);
setTimeout(function() {
console.timeEnd(str);
......@@ -71,7 +74,7 @@ class TimelineInteractionRecord(object):
self.start = start
self.end = end
self.is_smooth = False
self.is_loading_resources = False
self.is_responsive = False
self._async_event = async_event
# TODO(nednguyen): After crbug.com/367175 is marked fixed, we should be able
......@@ -84,6 +87,9 @@ class TimelineInteractionRecord(object):
async_event: An instance of
telemetry.core.timeline.async_slices.AsyncSlice
"""
assert async_event.start_thread == async_event.end_thread, (
'Start thread of this record\'s async event is not the same as its '
'end thread')
m = re.match('Interaction\.(.+)\/(.+)', async_event.name)
if m:
logical_name = m.group(1)
......@@ -104,7 +110,7 @@ class TimelineInteractionRecord(object):
raise Exception(
'Unrecognized flag in timeline Interaction record: %s' % f)
record.is_smooth = IS_SMOOTH in flags
record.is_loading_resources = IS_LOADING_RESOURCES in flags
record.is_responsive = IS_RESPONSIVE in flags
return record
def GetResultNameFor(self, result_name):
......@@ -169,16 +175,12 @@ class TimelineInteractionRecord(object):
if not self._async_event:
raise ThreadTimeRangeOverlappedException(
'This record was not constructed from async event')
if self._async_event.start_thread != self._async_event.end_thread:
raise ThreadTimeRangeOverlappedException(
'Start thread of this record\'s async event is not the same as its '
'end thread')
if not self._async_event.has_thread_timestamps:
raise ThreadTimeRangeOverlappedException(
raise NoThreadTimeDataException(
'This record\'s async_event does not contain thread time data. '
'Event data: %s' % repr(self._async_event))
if not timeline_slice.has_thread_timestamps:
raise ThreadTimeRangeOverlappedException(
raise NoThreadTimeDataException(
'slice does not contain thread time data')
if timeline_slice.parent_thread == self._async_event.start_thread:
......@@ -210,3 +212,19 @@ class TimelineInteractionRecord(object):
self._async_event.thread_duration / float(self._async_event.duration))
return (overlapped_walltime_duration * timeline_slice_scheduled_ratio *
record_scheduled_ratio)
def __repr__(self):
flags = []
if self.is_smooth:
flags.append(IS_SMOOTH)
elif self.is_responsive:
flags.append(IS_RESPONSIVE)
flags_str = ','.join(flags)
return ('TimelineInteractionRecord(logical_name=\'%s\', start=%f, end=%f,' +
' flags=%s, async_event=%s)') % (
self.logical_name,
self.start,
self.end,
flags_str,
repr(self._async_event))
......@@ -40,32 +40,32 @@ class TimelineInteractionRecordTests(unittest.TestCase):
r = self.CreateSimpleRecordWithName('Interaction.LogicalName')
self.assertEquals('LogicalName', r.logical_name)
self.assertEquals(False, r.is_smooth)
self.assertEquals(False, r.is_loading_resources)
self.assertEquals(False, r.is_responsive)
r = self.CreateSimpleRecordWithName('Interaction.LogicalName/is_smooth')
self.assertEquals('LogicalName', r.logical_name)
self.assertEquals(True, r.is_smooth)
self.assertEquals(False, r.is_loading_resources)
self.assertEquals(False, r.is_responsive)
r = self.CreateSimpleRecordWithName(
'Interaction.LogicalNameWith/Slash/is_smooth')
self.assertEquals('LogicalNameWith/Slash', r.logical_name)
self.assertEquals(True, r.is_smooth)
self.assertEquals(False, r.is_loading_resources)
self.assertEquals(False, r.is_responsive)
r = self.CreateSimpleRecordWithName(
'Interaction.LogicalNameWith/Slash/is_smooth,is_loading_resources')
'Interaction.LogicalNameWith/Slash/is_smooth,is_responsive')
self.assertEquals('LogicalNameWith/Slash', r.logical_name)
self.assertEquals(True, r.is_smooth)
self.assertEquals(True, r.is_loading_resources)
self.assertEquals(True, r.is_responsive)
def testGetJavascriptMarker(self):
smooth_marker = tir_module.TimelineInteractionRecord.GetJavascriptMarker(
'LogicalName', [tir_module.IS_SMOOTH])
self.assertEquals('Interaction.LogicalName/is_smooth', smooth_marker)
slr_marker = tir_module.TimelineInteractionRecord.GetJavascriptMarker(
'LogicalName', [tir_module.IS_SMOOTH, tir_module.IS_LOADING_RESOURCES])
self.assertEquals('Interaction.LogicalName/is_smooth,is_loading_resources',
'LogicalName', [tir_module.IS_SMOOTH, tir_module.IS_RESPONSIVE])
self.assertEquals('Interaction.LogicalName/is_smooth,is_responsive',
slr_marker)
def testGetOverlappedThreadTimeForSliceInSameThread(self):
......@@ -101,6 +101,25 @@ class TimelineInteractionRecordTests(unittest.TestCase):
s5 = self.CreateTestSliceFromTimeRanges(renderer_main, 0, 100, 50, 90)
self.assertEquals(10, record.GetOverlappedThreadTimeForSlice(s5))
def testRepr(self):
# Create a renderer thread.
model = model_module.TimelineModel()
renderer_main = model.GetOrCreateProcess(1).GetOrCreateThread(2)
model.FinalizeImport()
s = async_slice.AsyncSlice(
'cat', 'Interaction.Test/is_smooth',
timestamp=0, duration=200, start_thread=renderer_main,
end_thread=renderer_main, thread_start=30, thread_duration=30)
record = tir_module.TimelineInteractionRecord.FromAsyncEvent(s)
expected_repr = (
'TimelineInteractionRecord(logical_name=\'Test\', '
'start=0.000000, end=200.000000, flags=is_smooth, '
'async_event=TimelineEvent(name=\'Interaction.Test/is_smooth\','
' start=0.000000, duration=200, thread_start=30, thread_duration=30))')
self.assertEquals(expected_repr, repr(record))
def testGetOverlappedThreadTimeForSliceInDifferentThread(self):
# Create a renderer thread and another thread.
model = model_module.TimelineModel()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment