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

Side by Side Diff: tracing/tracing/metrics/metric_registry_test.html

Issue 2293533002: Refactor NumericBuilder to HistogramBinBoundaries. (Closed) Base URL: https://github.com/catapult-project/catapult.git@master
Patch Set: rebase 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
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/metric_registry.html"> 9 <link rel="import" href="/tracing/metrics/metric_registry.html">
10 <link rel="import" href="/tracing/value/histogram.html"> 10 <link rel="import" href="/tracing/value/histogram.html">
11 <link rel="import" href="/tracing/value/value.html"> 11 <link rel="import" href="/tracing/value/value.html">
12 12
13 <script> 13 <script>
14 'use strict'; 14 'use strict';
15 15
16 tr.b.unittest.testSuite(function() { 16 tr.b.unittest.testSuite(function() {
17 var test_utils = tr.c.TestUtils;
18 var ThreadSlice = tr.model.ThreadSlice;
19 var NUMERIC_BUILDER = tr.v.NumericBuilder.createLinear(
20 tr.v.Unit.byName.unitlessNumber, tr.b.Range.fromExplicitRange(0, 10), 10);
21
22 test('FindMetricByName', function() { 17 test('FindMetricByName', function() {
23 function sampleMetricA(values, model) { 18 function sampleMetricA(values, model) {
24 var n1 = NUMERIC_BUILDER.build(); 19 var n1 = new tr.v.Histogram(tr.v.Unit.byName.count);
25 n1.add(1); 20 n1.add(1);
26 values.addValue(new tr.v.NumericValue('foo', n1)); 21 values.addValue(new tr.v.NumericValue('foo', n1));
27 } 22 }
28 tr.metrics.MetricRegistry.register(sampleMetricA); 23 tr.metrics.MetricRegistry.register(sampleMetricA);
29 24
30 function sampleMetricB(values, model) { 25 function sampleMetricB(values, model) {
31 var n1 = NUMERIC_BUILDER.build(); 26 var n1 = new tr.v.Histogram(tr.v.Unit.byName.count);
32 var n2 = NUMERIC_BUILDER.build(); 27 var n2 = new tr.v.Histogram(tr.v.Unit.byName.count);
33 n1.add(1); 28 n1.add(1);
34 n2.add(2); 29 n2.add(2);
35 values.addValue(new tr.v.NumericValue('foo', n1)); 30 values.addValue(new tr.v.NumericValue('foo', n1));
36 values.addValue(new tr.v.NumericValue('bar', n2)); 31 values.addValue(new tr.v.NumericValue('bar', n2));
37 } 32 }
38 tr.metrics.MetricRegistry.register(sampleMetricB); 33 tr.metrics.MetricRegistry.register(sampleMetricB);
39 34
40 function sampleMetricC(values, model) { 35 function sampleMetricC(values, model) {
41 var n1 = NUMERIC_BUILDER.build(); 36 var n1 = new tr.v.Histogram(tr.v.Unit.byName.count);
42 var n2 = NUMERIC_BUILDER.build(); 37 var n2 = new tr.v.Histogram(tr.v.Unit.byName.count);
43 var n3 = NUMERIC_BUILDER.build(); 38 var n3 = new tr.v.Histogram(tr.v.Unit.byName.count);
44 n1.add(1); 39 n1.add(1);
45 n2.add(2); 40 n2.add(2);
46 n3.add(3); 41 n3.add(3);
47 values.addValue(new tr.v.NumericValue('foo', n1)); 42 values.addValue(new tr.v.NumericValue('foo', n1));
48 values.addValue(new tr.v.NumericValue('bar', n2)); 43 values.addValue(new tr.v.NumericValue('bar', n2));
49 values.addValue(new tr.v.NumericValue('baz', n3)); 44 values.addValue(new tr.v.NumericValue('baz', n3));
50 } 45 }
51 tr.metrics.MetricRegistry.register(sampleMetricC); 46 tr.metrics.MetricRegistry.register(sampleMetricC);
52 47
53 assert.isTrue(tr.metrics.MetricRegistry.findTypeInfoWithName('sampleMetricB' ).constructor === sampleMetricB); // @suppress longLineCheck 48 var typeInfo = tr.metrics.MetricRegistry.findTypeInfoWithName(
49 'sampleMetricB');
50 assert.strictEqual(typeInfo.constructor, sampleMetricB);
54 }); 51 });
55 52
56 test('registerNonFunctionThrows', function() { 53 test('registerNonFunctionThrows', function() {
57 assert.throws(function() { 54 assert.throws(function() {
58 tr.metrics.MetricRegistry.register('not a function'); 55 tr.metrics.MetricRegistry.register('not a function');
59 }); 56 });
60 57
61 assert.throws(function() { 58 assert.throws(function() {
62 tr.metrics.MetricRegistry.register(function() {}); 59 tr.metrics.MetricRegistry.register(function() {});
63 }); 60 });
64 61
65 assert.throws(function() { 62 assert.throws(function() {
66 tr.metrics.MetricRegistry.register(function(a) {}); 63 tr.metrics.MetricRegistry.register(function(a) {});
67 }); 64 });
68 }); 65 });
69 }); 66 });
70 </script> 67 </script>
OLDNEW
« no previous file with comments | « tracing/tracing/metrics/cpu_process_metric_test.html ('k') | tracing/tracing/metrics/sample_metric.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698