| 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( |
| 113 timeline.ThreadCpuTimeResultName(name, 'frame')) |
| 113 | 114 |
| 114 def testBasic(self): | 115 def testBasic(self): |
| 115 model = model_module.TimelineModel() | 116 model = model_module.TimelineModel() |
| 116 renderer_main = model.GetOrCreateProcess(1).GetOrCreateThread(2) | 117 renderer_main = model.GetOrCreateProcess(1).GetOrCreateThread(2) |
| 117 renderer_main.name = 'CrRendererMain' | 118 renderer_main.name = 'CrRendererMain' |
| 118 | 119 |
| 119 # Create two frame swaps (Results times should be divided by two) | 120 # Create two frame swaps (Results times should be divided by two) for |
| 121 # an interaction that lasts 20 milliseconds. |
| 120 cc_main = model.GetOrCreateProcess(1).GetOrCreateThread(3) | 122 cc_main = model.GetOrCreateProcess(1).GetOrCreateThread(3) |
| 121 cc_main.name = 'Compositor' | 123 cc_main.name = 'Compositor' |
| 122 cc_main.BeginSlice('cc_cat', timeline.FrameTraceName, 10, 10) | 124 cc_main.BeginSlice('cc_cat', timeline.FrameTraceName, 10, 10) |
| 123 cc_main.EndSlice(11, 11) | 125 cc_main.EndSlice(11, 11) |
| 124 cc_main.BeginSlice('cc_cat', timeline.FrameTraceName, 12, 12) | 126 cc_main.BeginSlice('cc_cat', timeline.FrameTraceName, 12, 12) |
| 125 cc_main.EndSlice(13, 13) | 127 cc_main.EndSlice(13, 13) |
| 126 | 128 |
| 127 # [ X ] [ Z ] | 129 # [ X ] [ Z ] |
| 128 # [ Y ] | 130 # [ Y ] |
| 129 renderer_main.BeginSlice('cat1', 'X', 10, 0) | 131 renderer_main.BeginSlice('cat1', 'X', 10, 0) |
| 130 renderer_main.BeginSlice('cat2', 'Y', 15, 5) | 132 renderer_main.BeginSlice('cat2', 'Y', 15, 5) |
| 131 renderer_main.EndSlice(16, 5.5) | 133 renderer_main.EndSlice(16, 5.5) |
| 132 renderer_main.EndSlice(30, 19.5) | 134 renderer_main.EndSlice(30, 19.5) |
| 133 renderer_main.BeginSlice('cat1', 'Z', 31, 20) | 135 renderer_main.BeginSlice('cat1', 'Z', 31, 20) |
| 134 renderer_main.BeginSlice('cat1', 'Z', 33, 21) | 136 renderer_main.BeginSlice('cat1', 'Z', 33, 21) |
| 135 model.FinalizeImport() | 137 model.FinalizeImport() |
| 136 | 138 |
| 137 # Exclude 'Z' using an action-range. | 139 # Exclude 'Z' using an action-range. |
| 138 metric = timeline.ThreadTimesTimelineMetric() | 140 metric = timeline.ThreadTimesTimelineMetric() |
| 139 metric.details_to_report = timeline.ReportMainThreadOnly | 141 metric.details_to_report = timeline.ReportMainThreadOnly |
| 140 results = self.GetResults(metric, model, renderer_main.parent, | 142 results = self.GetResults(metric, model, renderer_main.parent, |
| 141 [_GetInteractionRecord(10, 30)]) | 143 [_GetInteractionRecord(10, 30)]) |
| 142 | 144 |
| 143 # Test for the results we expect. | 145 # Test for the results we expect. |
| 144 main_thread = "renderer_main" | 146 main_thread = "renderer_main" |
| 145 cc_thread = 'renderer_compositor' | 147 cc_thread = 'renderer_compositor' |
| 146 assert_results = [ | 148 assert_results = [ |
| 147 (timeline.ThreadCpuTimeResultName(main_thread), 'ms', 9.75), | |
| 148 (timeline.ThreadTasksResultName(main_thread), 'tasks', 0.5), | |
| 149 (timeline.ThreadMeanFrameTimeResultName(cc_thread), 'ms', 10.0), | 149 (timeline.ThreadMeanFrameTimeResultName(cc_thread), 'ms', 10.0), |
| 150 (timeline.ThreadDetailResultName(main_thread,'cat1'), 'ms', 9.5), | 150 (timeline.ThreadTasksResultName(main_thread, 'frame'), 'tasks', 0.5), |
| 151 (timeline.ThreadDetailResultName(main_thread,'cat2'), 'ms', 0.5), | 151 (timeline.ThreadTasksResultName(main_thread, 'second'), 'tasks', 50.0), |
| 152 (timeline.ThreadDetailResultName(main_thread,'idle'), 'ms', 0) | 152 (timeline.ThreadTasksResultName(cc_thread, 'frame'), 'tasks', 1.0), |
| 153 (timeline.ThreadTasksResultName(cc_thread, 'second'), 'tasks', 100.0), |
| 154 (timeline.ThreadCpuTimeResultName(main_thread, 'frame'), 'ms', 9.75), |
| 155 (timeline.ThreadCpuTimeResultName(main_thread, 'second'), '%', 97.5), |
| 156 (timeline.ThreadCpuTimeResultName(cc_thread, 'frame'), 'ms', 1.0), |
| 157 (timeline.ThreadCpuTimeResultName(cc_thread, 'second'), '%', 10.0), |
| 158 (timeline.ThreadDetailResultName(main_thread, 'frame', 'cat1'), |
| 159 'ms', 9.5), |
| 160 (timeline.ThreadDetailResultName(main_thread, 'second', 'cat1'), |
| 161 '%', 95.0), |
| 162 (timeline.ThreadDetailResultName(main_thread, 'frame', 'cat2'), |
| 163 'ms', 0.5), |
| 164 (timeline.ThreadDetailResultName(main_thread, 'second', 'cat2'), |
| 165 '%', 5.0), |
| 166 (timeline.ThreadDetailResultName(main_thread, 'frame', 'idle'), 'ms', 0), |
| 167 (timeline.ThreadDetailResultName(main_thread, 'second', 'idle'), '%', 0) |
| 153 ] | 168 ] |
| 154 for name, unit, value in assert_results: | 169 for name, unit, value in assert_results: |
| 155 results.AssertHasPageSpecificScalarValue(name, unit, value) | 170 results.AssertHasPageSpecificScalarValue(name, unit, value) |
| 156 | 171 |
| 157 def testOverheadIsRemoved(self): | 172 def testOverheadIsRemoved(self): |
| 158 model = model_module.TimelineModel() | 173 model = model_module.TimelineModel() |
| 159 renderer_main = model.GetOrCreateProcess(1).GetOrCreateThread(2) | 174 renderer_main = model.GetOrCreateProcess(1).GetOrCreateThread(2) |
| 160 renderer_main.name = 'CrRendererMain' | 175 renderer_main.name = 'CrRendererMain' |
| 161 | 176 |
| 162 # Create one frame swap. | 177 # Create one frame swap. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 175 renderer_main.EndSlice(30, 10) | 190 renderer_main.EndSlice(30, 10) |
| 176 model.FinalizeImport() | 191 model.FinalizeImport() |
| 177 | 192 |
| 178 # Include everything in an action-range. | 193 # Include everything in an action-range. |
| 179 metric = timeline.ThreadTimesTimelineMetric() | 194 metric = timeline.ThreadTimesTimelineMetric() |
| 180 metric.details_to_report = timeline.ReportMainThreadOnly | 195 metric.details_to_report = timeline.ReportMainThreadOnly |
| 181 results = self.GetResults(metric, model, renderer_main.parent, | 196 results = self.GetResults(metric, model, renderer_main.parent, |
| 182 [_GetInteractionRecord(10, 30)]) | 197 [_GetInteractionRecord(10, 30)]) |
| 183 | 198 |
| 184 # Test a couple specific results. | 199 # Test a couple specific results. |
| 185 assert_results = { | 200 assert_results = [ |
| 186 timeline.ThreadCpuTimeResultName('renderer_main') : 9.0, | 201 (timeline.ThreadCpuTimeResultName('renderer_main', 'frame') , 'ms', 9.0), |
| 187 } | 202 (timeline.ThreadCpuTimeResultName('renderer_main', 'second') , '%', 45.0), |
| 188 for name, value in assert_results.iteritems(): | 203 ] |
| 189 results.AssertHasPageSpecificScalarValue(name, 'ms', value) | 204 for name, unit, value in assert_results: |
| 205 results.AssertHasPageSpecificScalarValue(name, unit, value) |
| OLD | NEW |