| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <!-- | 2 <!-- |
| 3 Copyright 2016 The Chromium Authors. All rights reserved. | 3 Copyright 2016 The Chromium Authors. All rights reserved. |
| 4 Use of this source code is governed by a BSD-style license that can be | 4 Use of this source code is governed by a BSD-style license that can be |
| 5 found in the LICENSE file. | 5 found in the LICENSE file. |
| 6 --> | 6 --> |
| 7 | 7 |
| 8 <link rel="import" href="/tracing/core/test_utils.html"> | 8 <link rel="import" href="/tracing/core/test_utils.html"> |
| 9 <link rel="import" href="/tracing/extras/chrome/chrome_test_utils.html"> |
| 9 <link rel="import" href="/tracing/metrics/system_health/cpu_time_metric.html"> | 10 <link rel="import" href="/tracing/metrics/system_health/cpu_time_metric.html"> |
| 10 <link rel="import" href="/tracing/value/histogram_set.html"> | 11 <link rel="import" href="/tracing/value/histogram_set.html"> |
| 11 | 12 |
| 12 <script> | 13 <script> |
| 13 'use strict'; | 14 'use strict'; |
| 14 | 15 |
| 15 tr.b.unittest.testSuite(function() { | 16 tr.b.unittest.testSuite(function() { |
| 16 function computeCpuTime(customizeModelCallback, opt_options) { | 17 function computeCpuTime(customizeModelCallback, opt_options) { |
| 17 var model = tr.c.TestUtils.newModel(function(model) { | 18 var model = tr.c.TestUtils.newModel(function(model) { |
| 18 customizeModelCallback(model); | 19 customizeModelCallback(model); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 43 isTopLevel: true, | 44 isTopLevel: true, |
| 44 start: totalDuration - sliceDuration, | 45 start: totalDuration - sliceDuration, |
| 45 duration: sliceDuration, | 46 duration: sliceDuration, |
| 46 cpuStart: totalDuration - sliceDuration, | 47 cpuStart: totalDuration - sliceDuration, |
| 47 cpuDuration: sliceDuration, | 48 cpuDuration: sliceDuration, |
| 48 })); | 49 })); |
| 49 }); | 50 }); |
| 50 assert.closeTo(value, 0.033, 0.001); | 51 assert.closeTo(value, 0.033, 0.001); |
| 51 }); | 52 }); |
| 52 | 53 |
| 54 // Normalize against the browser process, whose non-CPU slice goes from 2900 |
| 55 // to 3000. |
| 56 test('cpuTimeMetric_browserProcess', function() { |
| 57 var sliceDuration = 50; |
| 58 var totalDuration = 3000; |
| 59 var model = tr.e.chrome.ChromeTestUtils.newChromeModel(function(model) { |
| 60 model.browserMain.sliceGroup.pushSlice(tr.c.TestUtils.newSliceEx({ |
| 61 type: tr.model.ThreadSlice, |
| 62 isTopLevel: true, |
| 63 start: totalDuration - 2 * sliceDuration, |
| 64 duration: 2 * sliceDuration, |
| 65 })); |
| 66 model.rendererMain.sliceGroup.pushSlice(tr.c.TestUtils.newSliceEx({ |
| 67 type: tr.model.ThreadSlice, |
| 68 isTopLevel: true, |
| 69 start: 0, |
| 70 duration: sliceDuration, |
| 71 cpuStart: 0, |
| 72 cpuDuration: sliceDuration, |
| 73 })); |
| 74 model.rendererMain.sliceGroup.pushSlice(tr.c.TestUtils.newSliceEx({ |
| 75 type: tr.model.ThreadSlice, |
| 76 isTopLevel: true, |
| 77 start: totalDuration - sliceDuration, |
| 78 duration: sliceDuration, |
| 79 cpuStart: totalDuration - sliceDuration, |
| 80 cpuDuration: sliceDuration, |
| 81 })); |
| 82 }); |
| 83 var values = new tr.v.HistogramSet(); |
| 84 tr.metrics.sh.cpuTimeMetric(values, model); |
| 85 var value = tr.b.getOnlyElement(values).average; |
| 86 assert.closeTo(value, 0.5, 0.001); |
| 87 }); |
| 88 |
| 53 // Makes sure that rangeOfInterest works correctly. | 89 // Makes sure that rangeOfInterest works correctly. |
| 54 test('cpuTimeMetric_oneProcess_rangeOfInterest', function() { | 90 test('cpuTimeMetric_oneProcess_rangeOfInterest', function() { |
| 55 var sliceDuration = 50; | 91 var sliceDuration = 50; |
| 56 var totalDuration = 3000; | 92 var totalDuration = 3000; |
| 57 var rangeOfInterest = new tr.b.Range.fromExplicitRange(-10, 30); | 93 var rangeOfInterest = new tr.b.Range.fromExplicitRange(-10, 30); |
| 58 var options = {}; | 94 var options = {}; |
| 59 options.rangeOfInterest = rangeOfInterest; | 95 options.rangeOfInterest = rangeOfInterest; |
| 60 var value = computeCpuTime(function(model) { | 96 var value = computeCpuTime(function(model) { |
| 61 model.rendererProcess = model.getOrCreateProcess(2); | 97 model.rendererProcess = model.getOrCreateProcess(2); |
| 62 model.rendererMain = model.rendererProcess.getOrCreateThread(3); | 98 model.rendererMain = model.rendererProcess.getOrCreateThread(3); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 start: 0, | 150 start: 0, |
| 115 duration: sliceDuration, | 151 duration: sliceDuration, |
| 116 cpuStart: 0, | 152 cpuStart: 0, |
| 117 cpuDuration: sliceDuration, | 153 cpuDuration: sliceDuration, |
| 118 })); | 154 })); |
| 119 }); | 155 }); |
| 120 assert.closeTo(value, 0.05, 0.001); | 156 assert.closeTo(value, 0.05, 0.001); |
| 121 }); | 157 }); |
| 122 }); | 158 }); |
| 123 </script> | 159 </script> |
| OLD | NEW |