Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <!DOCTYPE html> | |
| 2 <!-- | |
| 3 Copyright 2017 The Chromium Authors. All rights reserved. | |
| 4 Use of this source code is governed by a BSD-style license that can be | |
| 5 found in the LICENSE file. | |
| 6 --> | |
| 7 | |
| 8 <link rel="import" href="/tracing/core/test_utils.html"> | |
| 9 <link rel="import" href="/tracing/metrics/vr/frame_cycle_duration_metric.html"> | |
| 10 <link rel="import" href="/tracing/model/model.html"> | |
| 11 <link rel="import" href="/tracing/value/histogram_set.html"> | |
| 12 | |
| 13 <script> | |
| 14 'use strict'; | |
| 15 tr.b.unittest.testSuite(function() { | |
|
benjhayden
2017/08/30 18:38:39
I highly recommend reading go/unit-test-practices
tiborg
2017/08/30 22:12:29
Very good read! Would you also suggest splitting t
| |
| 16 const TOLERANCE = 1e-6; | |
| 17 | |
| 18 function createSlice(duration, currentTime) { | |
|
benjhayden
2017/08/30 18:38:39
This can be inlined into the sole caller.
tiborg
2017/08/30 22:12:29
Done.
| |
| 19 const option = { | |
| 20 cat: 'gpu', | |
| 21 title: duration.title, | |
| 22 start: currentTime, | |
| 23 end: currentTime + duration.wall, | |
| 24 cpuStart: currentTime, | |
| 25 cpuEnd: currentTime + duration.cpu, | |
| 26 }; | |
| 27 return tr.c.TestUtils.newSliceEx(option); | |
| 28 } | |
| 29 | |
| 30 function createSubSlices(durations, currentTime, sliceGroup) { | |
| 31 if (durations === undefined) { | |
| 32 return []; | |
| 33 } | |
| 34 const slices = []; | |
| 35 durations.forEach(function(duration) { | |
|
benjhayden
2017/08/30 18:38:39
Please use for..of instead of forEach:
for (const
tiborg
2017/08/30 22:12:29
Done.
| |
| 36 const slice = createSlice(duration, currentTime); | |
| 37 currentTime += Math.max(duration.wall, duration.cpu) + 1; | |
| 38 slice.subSlices = createSubSlices(duration.sub, currentTime, sliceGroup); | |
| 39 sliceGroup.pushSlice(slice); | |
| 40 slices.push(slice); | |
| 41 }); | |
| 42 return slices; | |
| 43 } | |
| 44 | |
| 45 function createModel(durations) { | |
|
benjhayden
2017/08/30 18:38:39
This can be inlined into the sole caller.
tiborg
2017/08/30 22:12:29
Done.
| |
| 46 const model = tr.c.TestUtils.newModel(function(model) { | |
| 47 const process = model.getOrCreateProcess(1); | |
| 48 const thread = process.getOrCreateThread(2); | |
| 49 const group = thread.sliceGroup; | |
| 50 createSubSlices(durations, 0, group); | |
| 51 group.createSubSlices(); | |
| 52 }); | |
| 53 return model; | |
| 54 } | |
| 55 | |
| 56 function getValues(name, histograms) { | |
|
benjhayden
2017/08/30 18:38:39
Callers should call getHistogramNamed directly wit
tiborg
2017/08/30 22:12:29
Done.
| |
| 57 return { | |
| 58 wall: histograms.getHistogramNamed(name + ' (Wall Duration)'), | |
| 59 cpu: histograms.getHistogramNamed(name + ' (CPU Duration)'), | |
| 60 }; | |
| 61 } | |
| 62 | |
| 63 function getAvg(durations) { | |
|
benjhayden
2017/08/30 18:38:39
This doesn't look necessary. All callers can be re
tiborg
2017/08/30 22:12:29
Done.
| |
| 64 const sum = durations.reduce(function(a, b) { return a + b; }); | |
| 65 return sum / durations.length; | |
| 66 } | |
| 67 | |
| 68 test('frameCycleDurationMetric', function() { | |
| 69 const durations = [ | |
| 70 { | |
| 71 title: 'VrShellGl::DrawFrame', | |
| 72 wall: 25, | |
| 73 cpu: 12, | |
| 74 sub: [ | |
| 75 {title: 'VrShellGl::AcquireFrame', wall: 2, cpu: 2}, | |
| 76 {title: 'VrShellGl::AcquireFrame', wall: 2.5, cpu: 1.5}, | |
| 77 {title: 'VrShellGl::UpdateController', wall: 1, cpu: 0.5}, | |
| 78 {title: 'VrShellGl::UpdateController', wall: 0.5, cpu: 0.4}, | |
| 79 { | |
| 80 title: 'VrShellGl::DrawWorldElements', | |
| 81 wall: 5, | |
| 82 cpu: 3, | |
| 83 sub: [ | |
| 84 {title: 'VrShellGl::DrawUiView', wall: 1.5, cpu: 1}, | |
| 85 {title: 'VrShellGl::DrawUiView', wall: 2, cpu: 1.5}, | |
| 86 ] | |
| 87 }, | |
| 88 {title: 'VrShellGl::DrawWorldElements', wall: 6, cpu: 3}, | |
| 89 {title: 'VrShellGl::DrawFrameSubmitWhenReady', wall: 3, cpu: 0.5}, | |
| 90 { | |
| 91 title: 'VrShellGl::DrawFrameSubmitWhenReady', | |
| 92 wall: 3.5, | |
| 93 cpu: 0.5 | |
| 94 }, | |
| 95 ] | |
| 96 }, | |
| 97 {title: 'VrShellGl::DrawFrame', wall: 20, cpu: 10}, | |
| 98 ]; | |
| 99 const histograms = new tr.v.HistogramSet(); | |
| 100 const model = createModel(durations); | |
| 101 | |
| 102 tr.metrics.vr.frameCycleDurationMetric(histograms, model); | |
| 103 | |
| 104 const drawFrameValues = getValues('draw_frame', histograms); | |
| 105 assert.closeTo(drawFrameValues.wall.average, getAvg([25, 20]), | |
| 106 TOLERANCE); | |
| 107 assert.closeTo(drawFrameValues.cpu.average, getAvg([12, 10]), TOLERANCE); | |
| 108 | |
| 109 const acquireFrameValues = getValues('acquire_frame', histograms); | |
| 110 assert.closeTo(acquireFrameValues.wall.average, getAvg([2, 2.5]), | |
| 111 TOLERANCE); | |
| 112 assert.closeTo(acquireFrameValues.cpu.average, getAvg([2, 1.5]), | |
| 113 TOLERANCE); | |
| 114 | |
| 115 const updateControllerValues = getValues('update_controller', histograms); | |
| 116 assert.closeTo(updateControllerValues.wall.average, getAvg([1, 0.5]), | |
| 117 TOLERANCE); | |
| 118 assert.closeTo(updateControllerValues.cpu.average, getAvg([0.5, 0.4]), | |
| 119 TOLERANCE); | |
| 120 | |
| 121 const drawWorldElementsValues = | |
| 122 getValues('draw_world_elements', histograms); | |
| 123 assert.closeTo(drawWorldElementsValues.wall.average, getAvg([5, 6]), | |
| 124 TOLERANCE); | |
| 125 assert.closeTo(drawWorldElementsValues.cpu.average, getAvg([3, 3]), | |
| 126 TOLERANCE); | |
| 127 | |
| 128 const submitFrameValues = getValues('submit_frame', histograms); | |
| 129 assert.closeTo(submitFrameValues.wall.average, getAvg([3, 3.5]), | |
| 130 TOLERANCE); | |
| 131 assert.closeTo(submitFrameValues.cpu.average, getAvg([0.5, 0.5]), | |
| 132 TOLERANCE); | |
| 133 | |
| 134 const drawUiValues = getValues('draw_ui', histograms); | |
| 135 assert.closeTo(drawUiValues.wall.average, getAvg([1.5, 2]), TOLERANCE); | |
| 136 assert.closeTo(drawUiValues.cpu.average, getAvg([1, 1.5]), TOLERANCE); | |
| 137 }); | |
| 138 }); | |
| 139 </script> | |
| OLD | NEW |