| Index: tools/telemetry/telemetry/web_perf/metrics/blob_timeline_unittest.py
|
| diff --git a/tools/telemetry/telemetry/web_perf/metrics/blob_timeline_unittest.py b/tools/telemetry/telemetry/web_perf/metrics/blob_timeline_unittest.py
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..e7c9ef87c887bfa83ab3ee889701011445cda5bd
|
| --- /dev/null
|
| +++ b/tools/telemetry/telemetry/web_perf/metrics/blob_timeline_unittest.py
|
| @@ -0,0 +1,134 @@
|
| +# Copyright 2014 The Chromium Authors. All rights reserved.
|
| +# Use of this source code is governed by a BSD-style license that can be
|
| +# found in the LICENSE file.
|
| +
|
| +import unittest
|
| +
|
| +from collections import namedtuple
|
| +from telemetry.page import page
|
| +from telemetry.results import page_test_results
|
| +from telemetry.web_perf.metrics import blob_timeline
|
| +from telemetry.web_perf import timeline_interaction_record
|
| +
|
| +
|
| +FakeEvent = namedtuple('Event', 'name, start, end')
|
| +Interaction = timeline_interaction_record.TimelineInteractionRecord
|
| +
|
| +
|
| +def GetBlobMetrics(events, interactions):
|
| + results = page_test_results.PageTestResults()
|
| + test_page = page.Page('file://blank.html')
|
| + results.WillRunPage(test_page)
|
| + blob_timeline.BlobTimelineMetric()._AddWriteResultsInternal(
|
| + events, interactions, results) # pylint:disable=protected-access
|
| + blob_timeline.BlobTimelineMetric()._AddReadResultsInternal(
|
| + events, interactions, results) # pylint:disable=protected-access
|
| + return_dict = dict((value.name, value.values) for value in
|
| + results.current_page_run.values)
|
| + results.DidRunPage(test_page)
|
| + return return_dict
|
| +
|
| +def FakeWriteEvent(start, end):
|
| + return FakeEvent(blob_timeline.WRITE_EVENT_NAME,
|
| + start, end)
|
| +
|
| +def FakeReadEvent(start, end):
|
| + return FakeEvent(blob_timeline.READ_EVENT_NAME,
|
| + start, end)
|
| +
|
| +def WriteInteraction(start, end):
|
| + return Interaction(blob_timeline.WRITE_INTERACTION_LABEL,
|
| + start, end)
|
| +
|
| +def ReadInteraction(start, end):
|
| + return Interaction(blob_timeline.READ_INTERACTION_LABEL,
|
| + start, end)
|
| +
|
| +def WriteReadInteraction(start, end):
|
| + return Interaction(
|
| + blob_timeline.WRITE_READ_INTERACTION_LABEL,
|
| + start, end)
|
| +
|
| +
|
| +class BlobTimelineMetricUnitTest(unittest.TestCase):
|
| + def testWriteMetric(self):
|
| + events = [FakeWriteEvent(0, 1),
|
| + FakeWriteEvent(9, 11),
|
| + FakeWriteEvent(10, 13),
|
| + FakeWriteEvent(20, 24),
|
| + FakeWriteEvent(21, 26),
|
| + FakeWriteEvent(29, 35),
|
| + FakeWriteEvent(30, 37),
|
| + FakeWriteEvent(40, 48),
|
| + FakeWriteEvent(41, 50),
|
| + FakeEvent('something', 10, 13),
|
| + FakeEvent('FrameView::something', 20, 24),
|
| + FakeEvent('SomeThing::performLayout', 30, 37),
|
| + FakeEvent('something else', 40, 48)]
|
| + interactions = [WriteInteraction(10, 20),
|
| + WriteInteraction(30, 40)]
|
| +
|
| + self.assertFalse(GetBlobMetrics(events, []))
|
| + self.assertFalse(GetBlobMetrics([], interactions))
|
| +
|
| + # The first event starts before the first interaction, so it is ignored.
|
| + # The second event starts before the first interaction, so it is ignored.
|
| + # The third event starts during the first interaction, and its duration is
|
| + # 13 - 10 = 3.
|
| + # The fourth event starts during the first interaction, and its duration is
|
| + # 24 - 20 = 4.
|
| + # The fifth event starts between the two interactions, so it is ignored.
|
| + # The sixth event starts between the two interactions, so it is ignored.
|
| + # The seventh event starts during the second interaction, and its duration
|
| + # is 37 - 30 = 7.
|
| + # The eighth event starts during the second interaction and its duration is
|
| + # 48 - 40 = 8.
|
| + # The ninth event starts after the last interaction, so it is ignored.
|
| + # The rest of the events are not layout events, so they are ignored.
|
| + self.assertEqual({'blob_writes': [3, 4, 7, 8]}, GetBlobMetrics(
|
| + events, interactions))
|
| +
|
| + def testReadMetric(self):
|
| + events = [FakeReadEvent(0, 1),
|
| + FakeReadEvent(9, 11),
|
| + FakeReadEvent(10, 13), # counts
|
| + FakeReadEvent(15, 18), # counts
|
| + FakeReadEvent(21, 26),
|
| + FakeReadEvent(29, 35),
|
| + FakeReadEvent(32, 37), # counts
|
| + FakeEvent('something', 10, 13),
|
| + FakeEvent('something else', 40, 48)]
|
| + interactions = [ReadInteraction(10, 20),
|
| + ReadInteraction(30, 40)]
|
| +
|
| + self.assertFalse(GetBlobMetrics(events, []))
|
| + self.assertFalse(GetBlobMetrics([], interactions))
|
| +
|
| + # We ignore events outside of the interaction intervals, and we use the
|
| + # begining of the first event of the interval and the end of the last
|
| + # event.
|
| + # 18 - 10 = 8
|
| + # 37 - 32 = 5
|
| + self.assertEqual({'blob_reads': [8, 5]}, GetBlobMetrics(
|
| + events, interactions))
|
| +
|
| + def testReadWriteMetric(self):
|
| + events = [FakeReadEvent(0, 1),
|
| + FakeReadEvent(9, 11),
|
| + FakeReadEvent(10, 13),
|
| + FakeWriteEvent(15, 18),
|
| + FakeReadEvent(21, 26),
|
| + FakeReadEvent(29, 35),
|
| + FakeReadEvent(32, 37),
|
| + FakeEvent('something', 31, 33)]
|
| + interactions = [WriteReadInteraction(10, 20),
|
| + WriteReadInteraction(30, 35)]
|
| +
|
| + self.assertFalse(GetBlobMetrics(events, []))
|
| +
|
| + # We only use the time difference between the interactions here
|
| + self.assertEqual({'blob_write_reads': [10, 5]}, GetBlobMetrics(
|
| + events, interactions))
|
| + # Should be the same as no events
|
| + self.assertEqual({'blob_write_reads': [10, 5]}, GetBlobMetrics(
|
| + [], interactions))
|
|
|