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

Side by Side Diff: telemetry/telemetry/web_perf/metrics/blob_timeline_unittest.py

Issue 3010923002: [Telemetry] Removed legacy blob storage metrics (Closed)
Patch Set: Created 3 years, 3 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 unified diff | Download patch
OLDNEW
(Empty)
1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 import unittest
6
7 from collections import namedtuple
8 from telemetry.internal.results import page_test_results
9 from telemetry.page import page
10 from telemetry.web_perf.metrics import blob_timeline
11 from telemetry.web_perf import timeline_interaction_record
12
13
14 FakeEvent = namedtuple('Event', 'name, start, end, thread_duration, args')
15 Interaction = timeline_interaction_record.TimelineInteractionRecord
16 TEST_INTERACTION_LABEL = 'Action_TestInteraction'
17 WRITE_EVENT_NAME = 'Registry::RegisterBlob'
18 READ_EVENT_NAME = 'BlobRequest'
19
20
21 def GetBlobMetrics(events, interactions):
22 results = page_test_results.PageTestResults()
23 test_page = page.Page('file://blank.html', name='blank.html')
24 results.WillRunPage(test_page)
25 blob_timeline.BlobTimelineMetric()._AddWriteResultsInternal(
26 events, interactions, results) # pylint:disable=protected-access
27 blob_timeline.BlobTimelineMetric()._AddReadResultsInternal(
28 events, interactions, results) # pylint:disable=protected-access
29 return_dict = dict((value.name, value.values) for value in
30 results.current_page_run.values)
31 results.DidRunPage(test_page)
32 return return_dict
33
34 def FakeWriteEvent(start, end, thread_duration=None):
35 if not thread_duration:
36 thread_duration = end - start
37 return FakeEvent(blob_timeline.WRITE_EVENT_NAME,
38 start, end, thread_duration, {'uuid':'fakeuuid'})
39
40 def FakeReadEvent(start, end, uuid, thread_duration=None):
41 if not thread_duration:
42 thread_duration = end - start
43 return FakeEvent(blob_timeline.READ_EVENT_NAME,
44 start, end, thread_duration, {'uuid': uuid})
45
46 def TestInteraction(start, end):
47 return Interaction(TEST_INTERACTION_LABEL, start, end)
48
49
50 class BlobTimelineMetricUnitTest(unittest.TestCase):
51 def testWriteMetric(self):
52 events = [FakeWriteEvent(0, 1),
53 FakeWriteEvent(9, 11),
54 FakeWriteEvent(10, 13),
55 FakeWriteEvent(20, 24),
56 FakeWriteEvent(21, 26),
57 FakeWriteEvent(29, 35),
58 FakeWriteEvent(30, 37),
59 FakeWriteEvent(40, 48),
60 FakeWriteEvent(41, 50),
61 FakeEvent('something', 10, 13, 3, {}),
62 FakeEvent('FrameView::something', 20, 24, 4, {}),
63 FakeEvent('SomeThing::performLayout', 30, 37, 7, {}),
64 FakeEvent('something else', 40, 48, 8, {})]
65 interactions = [TestInteraction(10, 20),
66 TestInteraction(30, 40)]
67
68 # The first event starts before the first interaction, so it is ignored.
69 # The second event starts before the first interaction, so it is ignored.
70 # The third event starts during the first interaction, and its duration is
71 # 13 - 10 = 3.
72 # The fourth event starts during the first interaction, and its duration is
73 # 24 - 20 = 4.
74 # The fifth event starts between the two interactions, so it is ignored.
75 # The sixth event starts between the two interactions, so it is ignored.
76 # The seventh event starts during the second interaction, and its duration
77 # is 37 - 30 = 7.
78 # The eighth event starts during the second interaction and its duration is
79 # 48 - 40 = 8.
80 # The ninth event starts after the last interaction, so it is ignored.
81 # The rest of the events are not layout events, so they are ignored.
82 self.assertEqual(
83 {'blob-reads': None, 'blob-writes': [3, 4, 7, 8]},
84 GetBlobMetrics(events, interactions))
85
86 def testReadMetric(self):
87 events = [FakeReadEvent(0, 1, 'a'),
88 FakeReadEvent(9, 11, 'a'),
89 FakeReadEvent(10, 13, 'b', 1), # counts
90 FakeReadEvent(15, 18, 'b'), # counts
91 FakeReadEvent(21, 26, 'b'),
92 FakeReadEvent(29, 35, 'c'),
93 FakeReadEvent(31, 32, 'e'), # counts
94 FakeReadEvent(34, 36, 'e', 1), # counts
95 FakeReadEvent(32, 37, 'd'), # counts
96 FakeEvent('something', 10, 13, 3, {}),
97 FakeEvent('something else', 40, 48, 8, {})]
98 interactions = [TestInteraction(10, 20),
99 TestInteraction(30, 40)]
100
101 # We ignore events outside of the interaction intervals, and we use the
102 # beginning of the first event of the interval and the end of the last
103 # event.
104 # 18 - 10 = 8
105 # 37 - 32 = 5
106 self.assertEqual(
107 {'blob-reads': [4, 2, 5], 'blob-writes': None},
108 GetBlobMetrics(events, interactions))
109
110 def testReadAndWriteMetrics(self):
111 events = [FakeReadEvent(0, 1, 'a'),
112 FakeReadEvent(9, 11, 'a'),
113 FakeReadEvent(10, 13, 'b'), # counts
114 FakeWriteEvent(15, 18), # counts
115 FakeReadEvent(21, 26, 'c'),
116 FakeReadEvent(29, 35, 'd'),
117 FakeWriteEvent(31, 34, 1), # counts
118 FakeReadEvent(32, 33, 'e'), # counts
119 FakeReadEvent(34, 35, 'e'), # counts
120 FakeEvent('something', 31, 33, 2, {})]
121 interactions = [TestInteraction(10, 20),
122 TestInteraction(30, 35)]
123
124 # We use the read events in the interactions, so the same as the test above.
125 self.assertEqual(
126 {'blob-reads': [3, 2], 'blob-writes': [3, 1]},
127 GetBlobMetrics(events, interactions))
OLDNEW
« no previous file with comments | « telemetry/telemetry/web_perf/metrics/blob_timeline.py ('k') | telemetry/telemetry/web_perf/timeline_based_measurement.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698