Change next_proto member type.
[chromium-blink-merge.git] / tools / perf / metrics / timeline_unittest.py
blobb6a26fd1c7a89c9ed9102e50298628a156fcb284
1 # Copyright 2013 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.
5 import unittest
7 from metrics import test_page_test_results
8 from metrics import timeline
9 from telemetry.timeline import model as model_module
10 from telemetry.web_perf import timeline_interaction_record as tir_module
12 def _GetInteractionRecord(start, end):
13 return tir_module.TimelineInteractionRecord("test-record", start, end)
16 class LoadTimesTimelineMetric(unittest.TestCase):
17 def GetResults(self, metric, model, renderer_thread, interaction_records):
18 results = test_page_test_results.TestPageTestResults(self)
19 metric.AddResults(model, renderer_thread, interaction_records, results)
20 return results
22 def testSanitizing(self):
23 model = model_module.TimelineModel()
24 renderer_main = model.GetOrCreateProcess(1).GetOrCreateThread(2)
25 renderer_main.name = 'CrRendererMain'
27 # [ X ]
28 # [ Y ]
29 renderer_main.BeginSlice('cat1', 'x.y', 10, 0)
30 renderer_main.EndSlice(20, 20)
31 model.FinalizeImport()
33 metric = timeline.LoadTimesTimelineMetric()
34 results = self.GetResults(
35 metric, model=model, renderer_thread=renderer_main,
36 interaction_records=[_GetInteractionRecord(0, float('inf'))])
37 results.AssertHasPageSpecificScalarValue(
38 'CrRendererMain|x_y', 'ms', 10)
39 results.AssertHasPageSpecificScalarValue(
40 'CrRendererMain|x_y_max', 'ms', 10)
41 results.AssertHasPageSpecificScalarValue(
42 'CrRendererMain|x_y_avg', 'ms', 10)
44 def testTimelineBetweenRange(self):
45 model = model_module.TimelineModel()
46 renderer_main = model.GetOrCreateProcess(1).GetOrCreateThread(2)
47 renderer_main.name = 'CrRendererMain'
49 # [ X ] [ Z ]
50 # [ Y ] [ T ]
51 # [ interaction record ]
52 renderer_main.BeginSlice('cat1', 'x.y', 10, 0)
53 renderer_main.EndSlice(20, 20)
54 renderer_main.BeginSlice('cat1', 'z.t', 30, 0)
55 renderer_main.EndSlice(35, 35)
56 model.FinalizeImport()
58 metric = timeline.LoadTimesTimelineMetric()
59 results = self.GetResults(
60 metric, model=model, renderer_thread=renderer_main,
61 interaction_records=[_GetInteractionRecord(10, 20)])
62 results.AssertHasPageSpecificScalarValue(
63 'CrRendererMain|x_y', 'ms', 10)
64 results.AssertHasPageSpecificScalarValue(
65 'CrRendererMain|x_y_max', 'ms', 10)
66 results.AssertHasPageSpecificScalarValue(
67 'CrRendererMain|x_y_avg', 'ms', 10)
70 def testCounterSanitizing(self):
71 model = model_module.TimelineModel()
72 renderer_main = model.GetOrCreateProcess(1).GetOrCreateThread(2)
73 renderer_main.name = 'CrRendererMain'
75 x_counter = renderer_main.parent.GetOrCreateCounter('cat', 'x.y')
76 x_counter.samples += [1, 2]
77 x_counter.series_names += ['a']
78 x_counter.timestamps += [0, 1]
79 model.FinalizeImport()
81 metric = timeline.LoadTimesTimelineMetric()
82 results = self.GetResults(
83 metric, model=model, renderer_thread=renderer_main,
84 interaction_records=[_GetInteractionRecord(0, float('inf'))])
85 results.AssertHasPageSpecificScalarValue(
86 'cat_x_y', 'count', 3)
87 results.AssertHasPageSpecificScalarValue(
88 'cat_x_y_avg', 'count', 1.5)
91 class ThreadTimesTimelineMetricUnittest(unittest.TestCase):
92 def GetResults(self, metric, model, renderer_thread, interaction_record):
93 results = test_page_test_results.TestPageTestResults(self)
94 metric.AddResults(model, renderer_thread, interaction_record,
95 results)
96 return results
98 def testResults(self):
99 model = model_module.TimelineModel()
100 renderer_main = model.GetOrCreateProcess(1).GetOrCreateThread(2)
101 renderer_main.name = 'CrRendererMain'
103 metric = timeline.ThreadTimesTimelineMetric()
104 metric.details_to_report = timeline.ReportMainThreadOnly
105 results = self.GetResults(metric, model, renderer_main.parent,
106 [_GetInteractionRecord(1,2)])
108 # Test that all result thread categories exist
109 for name in timeline.TimelineThreadCategories.values():
110 results.GetPageSpecificValueNamed(timeline.ThreadCpuTimeResultName(name))
112 def testBasic(self):
113 model = model_module.TimelineModel()
114 renderer_main = model.GetOrCreateProcess(1).GetOrCreateThread(2)
115 renderer_main.name = 'CrRendererMain'
117 # Create two frame swaps (Results times should be divided by two)
118 cc_main = model.GetOrCreateProcess(1).GetOrCreateThread(3)
119 cc_main.name = 'Compositor'
120 cc_main.BeginSlice('cc_cat', timeline.FrameTraceName, 10, 10)
121 cc_main.EndSlice(11, 11)
122 cc_main.BeginSlice('cc_cat', timeline.FrameTraceName, 12, 12)
123 cc_main.EndSlice(13, 13)
125 # [ X ] [ Z ]
126 # [ Y ]
127 renderer_main.BeginSlice('cat1', 'X', 10, 0)
128 renderer_main.BeginSlice('cat2', 'Y', 15, 5)
129 renderer_main.EndSlice(16, 5.5)
130 renderer_main.EndSlice(30, 19.5)
131 renderer_main.BeginSlice('cat1', 'Z', 31, 20)
132 renderer_main.BeginSlice('cat1', 'Z', 33, 21)
133 model.FinalizeImport()
135 # Exclude 'Z' using an action-range.
136 metric = timeline.ThreadTimesTimelineMetric()
137 metric.details_to_report = timeline.ReportMainThreadOnly
138 results = self.GetResults(metric, model, renderer_main.parent,
139 [_GetInteractionRecord(10, 30)])
141 # Test for the results we expect.
142 main_thread = "renderer_main"
143 cc_thread = 'renderer_compositor'
144 assert_results = [
145 (timeline.ThreadCpuTimeResultName(main_thread), 'ms', 9.75),
146 (timeline.ThreadTasksResultName(main_thread), 'tasks', 0.5),
147 (timeline.ThreadMeanFrameTimeResultName(cc_thread), 'ms', 10.0),
148 (timeline.ThreadDetailResultName(main_thread,'cat1'), 'ms', 9.5),
149 (timeline.ThreadDetailResultName(main_thread,'cat2'), 'ms', 0.5),
150 (timeline.ThreadDetailResultName(main_thread,'idle'), 'ms', 0)
152 for name, unit, value in assert_results:
153 results.AssertHasPageSpecificScalarValue(name, unit, value)
155 def testOverheadIsRemoved(self):
156 model = model_module.TimelineModel()
157 renderer_main = model.GetOrCreateProcess(1).GetOrCreateThread(2)
158 renderer_main.name = 'CrRendererMain'
160 # Create one frame swap.
161 cc_main = model.GetOrCreateProcess(1).GetOrCreateThread(3)
162 cc_main.name = 'Compositor'
163 cc_main.BeginSlice('cc_cat', timeline.FrameTraceName, 10, 10)
164 cc_main.EndSlice(11, 11)
166 # [ X ]
167 # [Overhead]
168 overhead_category = timeline.OverheadTraceCategory
169 overhead_name = timeline.OverheadTraceName
170 renderer_main.BeginSlice('cat1', 'X', 10, 0)
171 renderer_main.BeginSlice(overhead_category, overhead_name, 15, 5)
172 renderer_main.EndSlice(16, 6)
173 renderer_main.EndSlice(30, 10)
174 model.FinalizeImport()
176 # Include everything in an action-range.
177 metric = timeline.ThreadTimesTimelineMetric()
178 metric.details_to_report = timeline.ReportMainThreadOnly
179 results = self.GetResults(metric, model, renderer_main.parent,
180 [_GetInteractionRecord(10, 30)])
182 # Test a couple specific results.
183 assert_results = {
184 timeline.ThreadCpuTimeResultName('renderer_main') : 9.0,
186 for name, value in assert_results.iteritems():
187 results.AssertHasPageSpecificScalarValue(name, 'ms', value)