OLD | NEW |
(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 metrics import test_page_test_results |
| 8 from metrics import gpu_timeline |
| 9 from telemetry.timeline import async_slice as async_slice_module |
| 10 from telemetry.timeline import slice as slice_module |
| 11 from telemetry.timeline import model as model_module |
| 12 from telemetry.web_perf import timeline_interaction_record as tir_module |
| 13 |
| 14 SERVICE_FRAME_END_CATEGORY, SERVICE_FRAME_END_NAME = \ |
| 15 gpu_timeline.SERVICE_FRAME_END_MARKER |
| 16 |
| 17 DEVICE_FRAME_END_CATEGORY, DEVICE_FRAME_END_NAME = \ |
| 18 gpu_timeline.DEVICE_FRAME_END_MARKER |
| 19 |
| 20 INTERACTION_RECORDS = [tir_module.TimelineInteractionRecord("test-record", |
| 21 0, |
| 22 float('inf'))] |
| 23 |
| 24 |
| 25 def _CreateGPUSlices(parent_thread, name, start_time, duration, offset=0): |
| 26 args = { 'gl_category': gpu_timeline.TOPLEVEL_GL_CATEGORY } |
| 27 return (slice_module.Slice(parent_thread, |
| 28 gpu_timeline.TOPLEVEL_SERVICE_CATEGORY, |
| 29 name, start_time, |
| 30 args=args, |
| 31 duration=duration, |
| 32 thread_duration=duration), |
| 33 async_slice_module.AsyncSlice(gpu_timeline.TOPLEVEL_DEVICE_CATEGORY, |
| 34 name, start_time + offset, |
| 35 args=args, |
| 36 duration=duration)) |
| 37 |
| 38 def _CreateFrameEndSlices(parent_thread, start_time, duration, offset=0): |
| 39 args = { 'gl_category': gpu_timeline.TOPLEVEL_GL_CATEGORY } |
| 40 return (slice_module.Slice(parent_thread, |
| 41 SERVICE_FRAME_END_CATEGORY, |
| 42 SERVICE_FRAME_END_NAME, |
| 43 start_time, |
| 44 args=args, |
| 45 duration=duration, |
| 46 thread_duration=duration), |
| 47 async_slice_module.AsyncSlice(DEVICE_FRAME_END_CATEGORY, |
| 48 DEVICE_FRAME_END_NAME, |
| 49 start_time + offset, |
| 50 args=args, |
| 51 duration=duration)) |
| 52 |
| 53 |
| 54 def _AddSliceToThread(parent_thread, slice_item): |
| 55 if isinstance(slice_item, slice_module.Slice): |
| 56 parent_thread.PushSlice(slice_item) |
| 57 elif isinstance(slice_item, async_slice_module.AsyncSlice): |
| 58 parent_thread.AddAsyncSlice(slice_item) |
| 59 else: |
| 60 assert False, "Invalid Slice Item Type: %s" % type(slice_item) |
| 61 |
| 62 |
| 63 class GPUTimelineTest(unittest.TestCase): |
| 64 def GetResults(self, metric, model, renderer_thread, interaction_records): |
| 65 results = test_page_test_results.TestPageTestResults(self) |
| 66 metric.AddResults(model, renderer_thread, interaction_records, results) |
| 67 return results |
| 68 |
| 69 def testExpectedResults(self): |
| 70 """Test a simply trace will output all expected results.""" |
| 71 model = model_module.TimelineModel() |
| 72 test_thread = model.GetOrCreateProcess(1).GetOrCreateThread(2) |
| 73 for slice_item in _CreateGPUSlices(test_thread, 'test_item', 100, 10): |
| 74 _AddSliceToThread(test_thread, slice_item) |
| 75 model.FinalizeImport() |
| 76 |
| 77 metric = gpu_timeline.GPUTimelineMetric() |
| 78 results = self.GetResults(metric, model=model, renderer_thread=test_thread, |
| 79 interaction_records=INTERACTION_RECORDS) |
| 80 |
| 81 for source_type in (None, 'cpu', 'gpu'): |
| 82 results.AssertHasPageSpecificScalarValue( |
| 83 gpu_timeline.TimelineName('total', source_type, 'max'), 'ms', 10) |
| 84 results.AssertHasPageSpecificScalarValue( |
| 85 gpu_timeline.TimelineName('total', source_type, 'mean'), 'ms', 10) |
| 86 results.AssertHasPageSpecificScalarValue( |
| 87 gpu_timeline.TimelineName('total', source_type, 'stddev'), 'ms', 0) |
| 88 |
| 89 for tracked_name in gpu_timeline.TRACKED_NAMES.values(): |
| 90 for source_type in ('cpu', 'gpu'): |
| 91 results.AssertHasPageSpecificScalarValue( |
| 92 gpu_timeline.TimelineName(tracked_name, source_type, 'max'), |
| 93 'ms', 0) |
| 94 results.AssertHasPageSpecificScalarValue( |
| 95 gpu_timeline.TimelineName(tracked_name, source_type, 'mean'), |
| 96 'ms', 0) |
| 97 results.AssertHasPageSpecificScalarValue( |
| 98 gpu_timeline.TimelineName(tracked_name, source_type, 'stddev'), |
| 99 'ms', 0) |
| 100 |
| 101 def testNoDeviceTraceResults(self): |
| 102 """Test expected results when missing device traces.""" |
| 103 model = model_module.TimelineModel() |
| 104 test_thread = model.GetOrCreateProcess(1).GetOrCreateThread(2) |
| 105 service_slice, _ = _CreateGPUSlices(test_thread, 'test_item', 100, 10) |
| 106 _AddSliceToThread(test_thread, service_slice) |
| 107 model.FinalizeImport() |
| 108 |
| 109 metric = gpu_timeline.GPUTimelineMetric() |
| 110 results = self.GetResults(metric, model=model, renderer_thread=test_thread, |
| 111 interaction_records=INTERACTION_RECORDS) |
| 112 |
| 113 for source_type in (None, 'cpu'): |
| 114 results.AssertHasPageSpecificScalarValue( |
| 115 gpu_timeline.TimelineName('total', source_type, 'max'), 'ms', 10) |
| 116 results.AssertHasPageSpecificScalarValue( |
| 117 gpu_timeline.TimelineName('total', source_type, 'mean'), 'ms', 10) |
| 118 results.AssertHasPageSpecificScalarValue( |
| 119 gpu_timeline.TimelineName('total', source_type, 'stddev'), 'ms', 0) |
| 120 |
| 121 self.assertRaises(AssertionError, results.GetPageSpecificValueNamed, |
| 122 gpu_timeline.TimelineName('total', 'gpu', 'max')) |
| 123 self.assertRaises(AssertionError, results.GetPageSpecificValueNamed, |
| 124 gpu_timeline.TimelineName('total', 'gpu', 'mean')) |
| 125 self.assertRaises(AssertionError, results.GetPageSpecificValueNamed, |
| 126 gpu_timeline.TimelineName('total', 'gpu', 'stddev')) |
| 127 |
| 128 for name in gpu_timeline.TRACKED_NAMES.values(): |
| 129 results.AssertHasPageSpecificScalarValue( |
| 130 gpu_timeline.TimelineName(name, 'cpu', 'max'), 'ms', 0) |
| 131 results.AssertHasPageSpecificScalarValue( |
| 132 gpu_timeline.TimelineName(name, 'cpu', 'mean'), 'ms', 0) |
| 133 results.AssertHasPageSpecificScalarValue( |
| 134 gpu_timeline.TimelineName(name, 'cpu', 'stddev'), 'ms', 0) |
| 135 |
| 136 self.assertRaises(AssertionError, results.GetPageSpecificValueNamed, |
| 137 gpu_timeline.TimelineName(name, 'gpu', 'max')) |
| 138 self.assertRaises(AssertionError, results.GetPageSpecificValueNamed, |
| 139 gpu_timeline.TimelineName(name, 'gpu', 'mean')) |
| 140 self.assertRaises(AssertionError, results.GetPageSpecificValueNamed, |
| 141 gpu_timeline.TimelineName(name, 'gpu', 'stddev')) |
| 142 |
| 143 def testFrameSeparation(self): |
| 144 """Test frames are correctly calculated using the frame end marker.""" |
| 145 model = model_module.TimelineModel() |
| 146 test_thread = model.GetOrCreateProcess(1).GetOrCreateThread(2) |
| 147 |
| 148 # First frame is 10 seconds. |
| 149 for slice_item in _CreateGPUSlices(test_thread, 'test_item', 100, 10): |
| 150 _AddSliceToThread(test_thread, slice_item) |
| 151 |
| 152 # Mark frame end. |
| 153 for slice_item in _CreateFrameEndSlices(test_thread, 105, 5): |
| 154 _AddSliceToThread(test_thread, slice_item) |
| 155 |
| 156 # Second frame is 20 seconds. |
| 157 for slice_item in _CreateGPUSlices(test_thread, 'test_item', 110, 20): |
| 158 _AddSliceToThread(test_thread, slice_item) |
| 159 |
| 160 model.FinalizeImport() |
| 161 |
| 162 metric = gpu_timeline.GPUTimelineMetric() |
| 163 results = self.GetResults(metric, model=model, renderer_thread=test_thread, |
| 164 interaction_records=INTERACTION_RECORDS) |
| 165 |
| 166 for source_type in (None, 'cpu', 'gpu'): |
| 167 results.AssertHasPageSpecificScalarValue( |
| 168 gpu_timeline.TimelineName('total', source_type, 'max'), 'ms', 20) |
| 169 results.AssertHasPageSpecificScalarValue( |
| 170 gpu_timeline.TimelineName('total', source_type, 'mean'), 'ms', 15) |
| 171 results.AssertHasPageSpecificScalarValue( |
| 172 gpu_timeline.TimelineName('total', source_type, 'stddev'), 'ms', 5) |
| 173 |
| 174 def testFrameSeparationBeforeMarker(self): |
| 175 """Test frames are correctly calculated using the frame end marker.""" |
| 176 model = model_module.TimelineModel() |
| 177 test_thread = model.GetOrCreateProcess(1).GetOrCreateThread(2) |
| 178 |
| 179 # Mark frame end. |
| 180 for slice_item in _CreateFrameEndSlices(test_thread, 105, 5): |
| 181 _AddSliceToThread(test_thread, slice_item) |
| 182 |
| 183 # First frame is 10 seconds. |
| 184 for slice_item in _CreateGPUSlices(test_thread, 'test_item', 100, 10): |
| 185 _AddSliceToThread(test_thread, slice_item) |
| 186 |
| 187 # Second frame is 20 seconds. |
| 188 for slice_item in _CreateGPUSlices(test_thread, 'test_item', 110, 20): |
| 189 _AddSliceToThread(test_thread, slice_item) |
| 190 |
| 191 model.FinalizeImport() |
| 192 |
| 193 metric = gpu_timeline.GPUTimelineMetric() |
| 194 results = self.GetResults(metric, model=model, renderer_thread=test_thread, |
| 195 interaction_records=INTERACTION_RECORDS) |
| 196 |
| 197 for source_type in (None, 'cpu', 'gpu'): |
| 198 results.AssertHasPageSpecificScalarValue( |
| 199 gpu_timeline.TimelineName('total', source_type, 'max'), 'ms', 20) |
| 200 results.AssertHasPageSpecificScalarValue( |
| 201 gpu_timeline.TimelineName('total', source_type, 'mean'), 'ms', 15) |
| 202 results.AssertHasPageSpecificScalarValue( |
| 203 gpu_timeline.TimelineName('total', source_type, 'stddev'), 'ms', 5) |
| 204 |
| 205 def testTrackedNameTraces(self): |
| 206 """Be sure tracked names are being recorded correctly.""" |
| 207 self.assertGreater(len(gpu_timeline.TRACKED_NAMES), 0) |
| 208 |
| 209 marker_name, result_name = gpu_timeline.TRACKED_NAMES.iteritems().next() |
| 210 |
| 211 model = model_module.TimelineModel() |
| 212 test_thread = model.GetOrCreateProcess(1).GetOrCreateThread(2) |
| 213 for slice_item in _CreateGPUSlices(test_thread, marker_name, 100, 10): |
| 214 _AddSliceToThread(test_thread, slice_item) |
| 215 model.FinalizeImport() |
| 216 |
| 217 metric = gpu_timeline.GPUTimelineMetric() |
| 218 results = self.GetResults(metric, model=model, renderer_thread=test_thread, |
| 219 interaction_records=INTERACTION_RECORDS) |
| 220 |
| 221 for source_type in ('cpu', 'gpu'): |
| 222 results.AssertHasPageSpecificScalarValue( |
| 223 gpu_timeline.TimelineName(result_name, source_type, 'max'), |
| 224 'ms', 10) |
| 225 results.AssertHasPageSpecificScalarValue( |
| 226 gpu_timeline.TimelineName(result_name, source_type, 'mean'), |
| 227 'ms', 10) |
| 228 results.AssertHasPageSpecificScalarValue( |
| 229 gpu_timeline.TimelineName(result_name, source_type, 'stddev'), |
| 230 'ms', 0) |
| 231 |
| 232 def testTrackedNameWithContextIDTraces(self): |
| 233 """Be sure tracked names with context IDs are recorded correctly.""" |
| 234 self.assertGreater(len(gpu_timeline.TRACKED_NAMES), 0) |
| 235 |
| 236 marker_name, result_name = gpu_timeline.TRACKED_NAMES.iteritems().next() |
| 237 context_id = '-0x1234' |
| 238 |
| 239 model = model_module.TimelineModel() |
| 240 test_thread = model.GetOrCreateProcess(1).GetOrCreateThread(2) |
| 241 for slice_item in _CreateGPUSlices(test_thread, marker_name + context_id, |
| 242 100, 10): |
| 243 _AddSliceToThread(test_thread, slice_item) |
| 244 model.FinalizeImport() |
| 245 |
| 246 metric = gpu_timeline.GPUTimelineMetric() |
| 247 results = self.GetResults(metric, model=model, renderer_thread=test_thread, |
| 248 interaction_records=INTERACTION_RECORDS) |
| 249 |
| 250 for source_type in ('cpu', 'gpu'): |
| 251 results.AssertHasPageSpecificScalarValue( |
| 252 gpu_timeline.TimelineName(result_name, source_type, 'max'), |
| 253 'ms', 10) |
| 254 results.AssertHasPageSpecificScalarValue( |
| 255 gpu_timeline.TimelineName(result_name, source_type, 'mean'), |
| 256 'ms', 10) |
| 257 results.AssertHasPageSpecificScalarValue( |
| 258 gpu_timeline.TimelineName(result_name, source_type, 'stddev'), |
| 259 'ms', 0) |
| 260 |
| 261 def testOutOfOrderDeviceTraces(self): |
| 262 """Out of order device traces are still matched up to correct services.""" |
| 263 self.assertGreaterEqual(len(gpu_timeline.TRACKED_NAMES), 2) |
| 264 |
| 265 tracked_names_iter = gpu_timeline.TRACKED_NAMES.iteritems() |
| 266 marker1_name, result1_name = tracked_names_iter.next() |
| 267 result2_name = result1_name |
| 268 while result2_name == result1_name: |
| 269 marker2_name, result2_name = tracked_names_iter.next() |
| 270 |
| 271 model = model_module.TimelineModel() |
| 272 test_thread = model.GetOrCreateProcess(1).GetOrCreateThread(2) |
| 273 |
| 274 # marker1 lasts for 10 seconds. |
| 275 service_item1, device_item1 = _CreateGPUSlices(test_thread, marker1_name, |
| 276 100, 10) |
| 277 # marker2 lasts for 20 seconds. |
| 278 service_item2, device_item2 = _CreateGPUSlices(test_thread, marker2_name, |
| 279 200, 20) |
| 280 |
| 281 # Append out of order |
| 282 _AddSliceToThread(test_thread, service_item1) |
| 283 _AddSliceToThread(test_thread, service_item2) |
| 284 _AddSliceToThread(test_thread, device_item2) |
| 285 _AddSliceToThread(test_thread, device_item1) |
| 286 |
| 287 model.FinalizeImport() |
| 288 |
| 289 metric = gpu_timeline.GPUTimelineMetric() |
| 290 results = self.GetResults(metric, model=model, renderer_thread=test_thread, |
| 291 interaction_records=INTERACTION_RECORDS) |
| 292 |
| 293 for source_type in ('cpu', 'gpu'): |
| 294 results.AssertHasPageSpecificScalarValue( |
| 295 gpu_timeline.TimelineName(result1_name, source_type, 'max'), |
| 296 'ms', 10) |
| 297 results.AssertHasPageSpecificScalarValue( |
| 298 gpu_timeline.TimelineName(result1_name, source_type, 'mean'), |
| 299 'ms', 10) |
| 300 results.AssertHasPageSpecificScalarValue( |
| 301 gpu_timeline.TimelineName(result1_name, source_type, 'stddev'), |
| 302 'ms', 0) |
| 303 results.AssertHasPageSpecificScalarValue( |
| 304 gpu_timeline.TimelineName(result2_name, source_type, 'max'), |
| 305 'ms', 20) |
| 306 results.AssertHasPageSpecificScalarValue( |
| 307 gpu_timeline.TimelineName(result2_name, source_type, 'mean'), |
| 308 'ms', 20) |
| 309 results.AssertHasPageSpecificScalarValue( |
| 310 gpu_timeline.TimelineName(result2_name, source_type, 'stddev'), |
| 311 'ms', 0) |
OLD | NEW |