OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import unittest | 5 import unittest |
6 | 6 |
7 from telemetry.timeline import model as model_module | 7 from telemetry.timeline import model as model_module |
8 from telemetry.unittest_util import test_page_test_results | 8 from telemetry.unittest_util import test_page_test_results |
9 from telemetry.web_perf import timeline_interaction_record as tir_module | 9 from telemetry.web_perf import timeline_interaction_record as tir_module |
10 | 10 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 renderer_main = model.GetOrCreateProcess(1).GetOrCreateThread(2) | 102 renderer_main = model.GetOrCreateProcess(1).GetOrCreateThread(2) |
103 renderer_main.name = 'CrRendererMain' | 103 renderer_main.name = 'CrRendererMain' |
104 | 104 |
105 metric = timeline.ThreadTimesTimelineMetric() | 105 metric = timeline.ThreadTimesTimelineMetric() |
106 metric.details_to_report = timeline.ReportMainThreadOnly | 106 metric.details_to_report = timeline.ReportMainThreadOnly |
107 results = self.GetResults(metric, model, renderer_main.parent, | 107 results = self.GetResults(metric, model, renderer_main.parent, |
108 [_GetInteractionRecord(1,2)]) | 108 [_GetInteractionRecord(1,2)]) |
109 | 109 |
110 # Test that all result thread categories exist | 110 # Test that all result thread categories exist |
111 for name in timeline.TimelineThreadCategories.values(): | 111 for name in timeline.TimelineThreadCategories.values(): |
112 results.GetPageSpecificValueNamed(timeline.ThreadCpuTimeResultName(name)) | 112 results.GetPageSpecificValueNamed(metric.ThreadCpuTimeResultName(name)) |
113 | 113 |
114 def testBasic(self): | 114 def testBasic(self): |
115 model = model_module.TimelineModel() | 115 model = model_module.TimelineModel() |
116 renderer_main = model.GetOrCreateProcess(1).GetOrCreateThread(2) | 116 renderer_main = model.GetOrCreateProcess(1).GetOrCreateThread(2) |
117 renderer_main.name = 'CrRendererMain' | 117 renderer_main.name = 'CrRendererMain' |
118 | 118 |
119 # Create two frame swaps (Results times should be divided by two) | 119 # Create two frame swaps (Results times should be divided by two) |
120 cc_main = model.GetOrCreateProcess(1).GetOrCreateThread(3) | 120 cc_main = model.GetOrCreateProcess(1).GetOrCreateThread(3) |
121 cc_main.name = 'Compositor' | 121 cc_main.name = 'Compositor' |
122 cc_main.BeginSlice('cc_cat', timeline.FrameTraceName, 10, 10) | 122 cc_main.BeginSlice('cc_cat', timeline.FrameTraceName, 10, 10) |
(...skipping 14 matching lines...) Expand all Loading... |
137 # Exclude 'Z' using an action-range. | 137 # Exclude 'Z' using an action-range. |
138 metric = timeline.ThreadTimesTimelineMetric() | 138 metric = timeline.ThreadTimesTimelineMetric() |
139 metric.details_to_report = timeline.ReportMainThreadOnly | 139 metric.details_to_report = timeline.ReportMainThreadOnly |
140 results = self.GetResults(metric, model, renderer_main.parent, | 140 results = self.GetResults(metric, model, renderer_main.parent, |
141 [_GetInteractionRecord(10, 30)]) | 141 [_GetInteractionRecord(10, 30)]) |
142 | 142 |
143 # Test for the results we expect. | 143 # Test for the results we expect. |
144 main_thread = "renderer_main" | 144 main_thread = "renderer_main" |
145 cc_thread = 'renderer_compositor' | 145 cc_thread = 'renderer_compositor' |
146 assert_results = [ | 146 assert_results = [ |
147 (timeline.ThreadCpuTimeResultName(main_thread), 'ms', 9.75), | 147 (metric.ThreadCpuTimeResultName(main_thread), 'ms', 9.75), |
148 (timeline.ThreadTasksResultName(main_thread), 'tasks', 0.5), | 148 (metric.ThreadTasksResultName(main_thread), 'tasks', 0.5), |
149 (timeline.ThreadMeanFrameTimeResultName(cc_thread), 'ms', 10.0), | 149 (metric.ThreadFrameTimeResultName(cc_thread), 'ms', 10.0), |
150 (timeline.ThreadDetailResultName(main_thread,'cat1'), 'ms', 9.5), | 150 (metric.ThreadDetailResultName(main_thread,'cat1'), 'ms', 9.5), |
151 (timeline.ThreadDetailResultName(main_thread,'cat2'), 'ms', 0.5), | 151 (metric.ThreadDetailResultName(main_thread,'cat2'), 'ms', 0.5), |
152 (timeline.ThreadDetailResultName(main_thread,'idle'), 'ms', 0) | 152 (metric.ThreadDetailResultName(main_thread,'idle'), 'ms', 0) |
153 ] | 153 ] |
154 for name, unit, value in assert_results: | 154 for name, unit, value in assert_results: |
155 results.AssertHasPageSpecificScalarValue(name, unit, value) | 155 results.AssertHasPageSpecificScalarValue(name, unit, value) |
156 | 156 |
157 def testOverheadIsRemoved(self): | 157 def testOverheadIsRemoved(self): |
158 model = model_module.TimelineModel() | 158 model = model_module.TimelineModel() |
159 renderer_main = model.GetOrCreateProcess(1).GetOrCreateThread(2) | 159 renderer_main = model.GetOrCreateProcess(1).GetOrCreateThread(2) |
160 renderer_main.name = 'CrRendererMain' | 160 renderer_main.name = 'CrRendererMain' |
161 | 161 |
162 # Create one frame swap. | 162 # Create one frame swap. |
(...skipping 13 matching lines...) Expand all Loading... |
176 model.FinalizeImport() | 176 model.FinalizeImport() |
177 | 177 |
178 # Include everything in an action-range. | 178 # Include everything in an action-range. |
179 metric = timeline.ThreadTimesTimelineMetric() | 179 metric = timeline.ThreadTimesTimelineMetric() |
180 metric.details_to_report = timeline.ReportMainThreadOnly | 180 metric.details_to_report = timeline.ReportMainThreadOnly |
181 results = self.GetResults(metric, model, renderer_main.parent, | 181 results = self.GetResults(metric, model, renderer_main.parent, |
182 [_GetInteractionRecord(10, 30)]) | 182 [_GetInteractionRecord(10, 30)]) |
183 | 183 |
184 # Test a couple specific results. | 184 # Test a couple specific results. |
185 assert_results = { | 185 assert_results = { |
186 timeline.ThreadCpuTimeResultName('renderer_main') : 9.0, | 186 metric.ThreadCpuTimeResultName('renderer_main') : 9.0, |
187 } | 187 } |
188 for name, value in assert_results.iteritems(): | 188 for name, value in assert_results.iteritems(): |
189 results.AssertHasPageSpecificScalarValue(name, 'ms', value) | 189 results.AssertHasPageSpecificScalarValue(name, 'ms', value) |
| 190 |
| 191 def testMeasureTotalThreadTime(self): |
| 192 model = model_module.TimelineModel() |
| 193 renderer_main = model.GetOrCreateProcess(1).GetOrCreateThread(2) |
| 194 renderer_main.name = 'CrRendererMain' |
| 195 |
| 196 # Create two frame swaps (Results times should accumulate both frames) |
| 197 cc_main = model.GetOrCreateProcess(1).GetOrCreateThread(3) |
| 198 cc_main.name = 'Compositor' |
| 199 cc_main.BeginSlice('cc_cat', timeline.FrameTraceName, 10, 10) |
| 200 cc_main.EndSlice(11, 11) |
| 201 cc_main.BeginSlice('cc_cat', timeline.FrameTraceName, 12, 12) |
| 202 cc_main.EndSlice(13, 13) |
| 203 |
| 204 # [ X ] [ Z ] |
| 205 # [ Y ] |
| 206 renderer_main.BeginSlice('cat1', 'X', 10, 0) |
| 207 renderer_main.BeginSlice('cat2', 'Y', 15, 5) |
| 208 renderer_main.EndSlice(16, 5.5) |
| 209 renderer_main.BeginSlice('cat1', 'Z', 20, 9) |
| 210 renderer_main.BeginSlice('cat1', 'Z', 21, 10) |
| 211 renderer_main.EndSlice(30, 19.5) |
| 212 model.FinalizeImport() |
| 213 |
| 214 metric = timeline.ThreadTimesTimelineMetric(measure_per_frame=False) |
| 215 metric.details_to_report = timeline.ReportMainThreadOnly |
| 216 results = self.GetResults(metric, model, renderer_main.parent, |
| 217 [_GetInteractionRecord(10, 30)]) |
| 218 |
| 219 # Test for the results we expect. |
| 220 main_thread = "renderer_main" |
| 221 cc_thread = 'renderer_compositor' |
| 222 assert_results = [ |
| 223 (metric.ThreadCpuTimeResultName(main_thread), 'ms', 19.5), |
| 224 (metric.ThreadTasksResultName(main_thread), 'tasks', 1.0), |
| 225 (metric.ThreadFrameTimeResultName(cc_thread), 'ms', 20.0), |
| 226 (metric.ThreadDetailResultName(main_thread,'cat1'), 'ms', 19.0), |
| 227 (metric.ThreadDetailResultName(main_thread,'cat2'), 'ms', 1.0)] |
| 228 for name, unit, value in assert_results: |
| 229 results.AssertHasPageSpecificScalarValue(name, unit, value) |
OLD | NEW |