Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(242)

Unified Diff: tools/telemetry/telemetry/web_perf/metrics/blob_timeline_unittest.py

Issue 1104053006: [Storage] Blob Storage perf tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes and metric unittest Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..eba375297d7bf8b7cd2742a235a0b63cb9a03bf0
--- /dev/null
+++ b/tools/telemetry/telemetry/web_perf/metrics/blob_timeline_unittest.py
@@ -0,0 +1,130 @@
+# 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()
+ results.WillRunPage(page.Page('file://blank.html'))
+ blob_timeline.BlobTimelineMetric()._AddWriteResultsInternal(
eakuefner 2015/05/22 18:33:19 I think it would be best to test the public behavi
dmurph 2015/05/22 19:06:21 I'm thinking it's cleaner to just call the interna
eakuefner 2015/05/28 20:36:55 Fair enough.
+ events, interactions, results)
+ blob_timeline.BlobTimelineMetric()._AddReadResultsInternal(
+ events, interactions, results)
+ return dict((value.name, value.values) for value in
eakuefner 2015/05/22 18:33:19 Please call results.DidRunPage above this line.
dmurph 2015/05/22 19:06:21 Done.
+ results.current_page_run.values)
+
+def FakeWriteEvent(start, end):
+ return FakeEvent(blob_timeline.BlobTimelineMetric.WRITE_EVENT_NAME,
+ start, end)
+
+def FakeReadEvent(start, end):
+ return FakeEvent(blob_timeline.BlobTimelineMetric.READ_EVENT_NAME,
+ start, end)
+
+def WriteInteraction(start, end):
+ return Interaction(blob_timeline.BlobTimelineMetric.WRITE_INTERACTION_LABEL,
+ start, end)
+
+def ReadInteraction(start, end):
+ return Interaction(blob_timeline.BlobTimelineMetric.READ_INTERACTION_LABEL,
+ start, end)
+
+def WriteReadInteraction(start, end):
+ return Interaction(
+ blob_timeline.BlobTimelineMetric.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))

Powered by Google App Engine
This is Rietveld 408576698