Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: tracing/tracing/metrics/system_health/cpu_time_metric_test.html

Issue 2351963006: Add range of interest support to cpuTimeMetric. (Closed)
Patch Set: Add test, comments, etc. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tracing/tracing/metrics/system_health/cpu_time_metric.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/metrics/system_health/cpu_time_metric.html"> 9 <link rel="import" href="/tracing/metrics/system_health/cpu_time_metric.html">
10 <link rel="import" href="/tracing/value/value_set.html"> 10 <link rel="import" href="/tracing/value/value_set.html">
11 11
12 <script> 12 <script>
13 'use strict'; 13 'use strict';
14 14
15 tr.b.unittest.testSuite(function() { 15 tr.b.unittest.testSuite(function() {
16 function computeCpuTime(customizeModelCallback) { 16 function computeCpuTime(customizeModelCallback, opt_options) {
17 var model = tr.c.TestUtils.newModel(function(model) { 17 var model = tr.c.TestUtils.newModel(function(model) {
18 customizeModelCallback(model); 18 customizeModelCallback(model);
19 }); 19 });
20 var values = new tr.v.ValueSet(); 20 var values = new tr.v.ValueSet();
21 tr.metrics.sh.cpuTimeMetric(values, model); 21 tr.metrics.sh.cpuTimeMetric(values, model, opt_options);
22 return tr.b.getOnlyElement(values).average; 22 return tr.b.getOnlyElement(values).average;
23 } 23 }
24 24
25 // There are two slices, each of length 50. The total bounds is 3000. 25 // There are two slices, each of length 50. The total bounds is 3000.
26 // This yields total CPU time of 100ms, averaged over 3 seconds is 33ms. 26 // This yields total CPU time of 100ms, averaged over 3 seconds is 33ms.
27 test('cpuTimeMetric_oneProcess', function() { 27 test('cpuTimeMetric_oneProcess', function() {
28 var sliceDuration = 50; 28 var sliceDuration = 50;
29 var totalDuration = 3000; 29 var totalDuration = 3000;
30 var value = computeCpuTime(function(model) { 30 var value = computeCpuTime(function(model) {
31 model.rendererProcess = model.getOrCreateProcess(2); 31 model.rendererProcess = model.getOrCreateProcess(2);
32 model.rendererMain = model.rendererProcess.getOrCreateThread(3); 32 model.rendererMain = model.rendererProcess.getOrCreateThread(3);
33 model.rendererMain.sliceGroup.pushSlice(tr.c.TestUtils.newSliceEx({ 33 model.rendererMain.sliceGroup.pushSlice(tr.c.TestUtils.newSliceEx({
34 type: tr.model.ThreadSlice, 34 type: tr.model.ThreadSlice,
35 isTopLevel: true, 35 isTopLevel: true,
36 start: 0, 36 start: 0,
37 duration: sliceDuration, 37 duration: sliceDuration,
38 cpuStart: 0, 38 cpuStart: 0,
39 cpuDuration: sliceDuration, 39 cpuDuration: sliceDuration,
40 })); 40 }));
41 model.rendererMain.sliceGroup.pushSlice(tr.c.TestUtils.newSliceEx({ 41 model.rendererMain.sliceGroup.pushSlice(tr.c.TestUtils.newSliceEx({
42 type: tr.model.ThreadSlice, 42 type: tr.model.ThreadSlice,
43 isTopLevel: true, 43 isTopLevel: true,
44 start: totalDuration - sliceDuration, 44 start: totalDuration - sliceDuration,
45 duration: sliceDuration, 45 duration: sliceDuration,
46 cpuStart: totalDuration - sliceDuration, 46 cpuStart: totalDuration - sliceDuration,
47 cpuDuration: sliceDuration, 47 cpuDuration: sliceDuration,
48 })); 48 }));
49 }); 49 });
50 assert.closeTo(value, 33.33, 0.1); 50 assert.closeTo(value, 0.033, 0.001);
51 });
52
53 // Makes sure that rangeOfInterest works correctly.
54 test('cpuTimeMetric_oneProcess_rangeOfInterest', function() {
55 var sliceDuration = 50;
56 var totalDuration = 3000;
57 var rangeOfInterest = new tr.b.Range.fromExplicitRange(-10, 30);
58 var options = {}
59 options.rangeOfInterest = rangeOfInterest
60 var value = computeCpuTime(function(model) {
61 model.rendererProcess = model.getOrCreateProcess(2);
62 model.rendererMain = model.rendererProcess.getOrCreateThread(3);
63 model.rendererMain.sliceGroup.pushSlice(tr.c.TestUtils.newSliceEx({
64 type: tr.model.ThreadSlice,
65 isTopLevel: true,
66 start: 0,
67 duration: sliceDuration,
68 cpuStart: 0,
69 cpuDuration: sliceDuration,
70 }));
71 model.rendererMain.sliceGroup.pushSlice(tr.c.TestUtils.newSliceEx({
72 type: tr.model.ThreadSlice,
73 isTopLevel: true,
74 start: totalDuration - sliceDuration,
75 duration: sliceDuration,
76 cpuStart: totalDuration - sliceDuration,
77 cpuDuration: sliceDuration,
78 }));
79 }, options);
80 assert.closeTo(value, 0.75, 0.001);
51 }); 81 });
52 82
53 // Process 1: There are two slices, each of length 50. The total bounds is 83 // Process 1: There are two slices, each of length 50. The total bounds is
54 // 3000. Process 2: There is one slice of length 50. 84 // 3000. Process 2: There is one slice of length 50.
55 // This yields total CPU time of 150ms, averaged over 3 seconds is 50ms. 85 // This yields total CPU time of 150ms, averaged over 3 seconds is 50ms.
56 test('cpuTimeMetric_twoProcesses', function() { 86 test('cpuTimeMetric_twoProcesses', function() {
57 var sliceDuration = 50; 87 var sliceDuration = 50;
58 var totalDuration = 3000; 88 var totalDuration = 3000;
59 var value = computeCpuTime(function(model) { 89 var value = computeCpuTime(function(model) {
60 model.rendererProcess = model.getOrCreateProcess(2); 90 model.rendererProcess = model.getOrCreateProcess(2);
(...skipping 19 matching lines...) Expand all
80 var otherThread = otherProcess.getOrCreateThread(4); 110 var otherThread = otherProcess.getOrCreateThread(4);
81 otherThread.sliceGroup.pushSlice(tr.c.TestUtils.newSliceEx({ 111 otherThread.sliceGroup.pushSlice(tr.c.TestUtils.newSliceEx({
82 type: tr.model.ThreadSlice, 112 type: tr.model.ThreadSlice,
83 isTopLevel: true, 113 isTopLevel: true,
84 start: 0, 114 start: 0,
85 duration: sliceDuration, 115 duration: sliceDuration,
86 cpuStart: 0, 116 cpuStart: 0,
87 cpuDuration: sliceDuration, 117 cpuDuration: sliceDuration,
88 })); 118 }));
89 }); 119 });
90 assert.closeTo(value, 50.0, 0.1); 120 assert.closeTo(value, 0.05, 0.001);
91 }); 121 });
92 }); 122 });
93 </script> 123 </script>
OLDNEW
« no previous file with comments | « tracing/tracing/metrics/system_health/cpu_time_metric.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698