| 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/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 test('FindMetricByName', function() { | 17 test('FindMetricByName', function() { |
| 18 function sampleMetricA(values, model) { | 18 function sampleMetricA(values, model) { |
| 19 var n1 = new tr.v.Histogram(tr.v.Unit.byName.count); | 19 var n1 = new tr.v.Histogram(tr.v.Unit.byName.count); |
| 20 n1.add(1); | 20 n1.addSample(1); |
| 21 values.addValue(new tr.v.NumericValue('foo', n1)); | 21 values.addValue(new tr.v.NumericValue('foo', n1)); |
| 22 } | 22 } |
| 23 tr.metrics.MetricRegistry.register(sampleMetricA); | 23 tr.metrics.MetricRegistry.register(sampleMetricA); |
| 24 | 24 |
| 25 function sampleMetricB(values, model) { | 25 function sampleMetricB(values, model) { |
| 26 var n1 = new tr.v.Histogram(tr.v.Unit.byName.count); | 26 var n1 = new tr.v.Histogram(tr.v.Unit.byName.count); |
| 27 var n2 = new tr.v.Histogram(tr.v.Unit.byName.count); | 27 var n2 = new tr.v.Histogram(tr.v.Unit.byName.count); |
| 28 n1.add(1); | 28 n1.addSample(1); |
| 29 n2.add(2); | 29 n2.addSample(2); |
| 30 values.addValue(new tr.v.NumericValue('foo', n1)); | 30 values.addValue(new tr.v.NumericValue('foo', n1)); |
| 31 values.addValue(new tr.v.NumericValue('bar', n2)); | 31 values.addValue(new tr.v.NumericValue('bar', n2)); |
| 32 } | 32 } |
| 33 tr.metrics.MetricRegistry.register(sampleMetricB); | 33 tr.metrics.MetricRegistry.register(sampleMetricB); |
| 34 | 34 |
| 35 function sampleMetricC(values, model) { | 35 function sampleMetricC(values, model) { |
| 36 var n1 = new tr.v.Histogram(tr.v.Unit.byName.count); | 36 var n1 = new tr.v.Histogram(tr.v.Unit.byName.count); |
| 37 var n2 = new tr.v.Histogram(tr.v.Unit.byName.count); | 37 var n2 = new tr.v.Histogram(tr.v.Unit.byName.count); |
| 38 var n3 = new tr.v.Histogram(tr.v.Unit.byName.count); | 38 var n3 = new tr.v.Histogram(tr.v.Unit.byName.count); |
| 39 n1.add(1); | 39 n1.addSample(1); |
| 40 n2.add(2); | 40 n2.addSample(2); |
| 41 n3.add(3); | 41 n3.addSample(3); |
| 42 values.addValue(new tr.v.NumericValue('foo', n1)); | 42 values.addValue(new tr.v.NumericValue('foo', n1)); |
| 43 values.addValue(new tr.v.NumericValue('bar', n2)); | 43 values.addValue(new tr.v.NumericValue('bar', n2)); |
| 44 values.addValue(new tr.v.NumericValue('baz', n3)); | 44 values.addValue(new tr.v.NumericValue('baz', n3)); |
| 45 } | 45 } |
| 46 tr.metrics.MetricRegistry.register(sampleMetricC); | 46 tr.metrics.MetricRegistry.register(sampleMetricC); |
| 47 | 47 |
| 48 var typeInfo = tr.metrics.MetricRegistry.findTypeInfoWithName( | 48 var typeInfo = tr.metrics.MetricRegistry.findTypeInfoWithName( |
| 49 'sampleMetricB'); | 49 'sampleMetricB'); |
| 50 assert.strictEqual(typeInfo.constructor, sampleMetricB); | 50 assert.strictEqual(typeInfo.constructor, sampleMetricB); |
| 51 }); | 51 }); |
| 52 | 52 |
| 53 test('registerNonFunctionThrows', function() { | 53 test('registerNonFunctionThrows', function() { |
| 54 assert.throws(function() { | 54 assert.throws(function() { |
| 55 tr.metrics.MetricRegistry.register('not a function'); | 55 tr.metrics.MetricRegistry.register('not a function'); |
| 56 }); | 56 }); |
| 57 | 57 |
| 58 assert.throws(function() { | 58 assert.throws(function() { |
| 59 tr.metrics.MetricRegistry.register(function() {}); | 59 tr.metrics.MetricRegistry.register(function() {}); |
| 60 }); | 60 }); |
| 61 | 61 |
| 62 assert.throws(function() { | 62 assert.throws(function() { |
| 63 tr.metrics.MetricRegistry.register(function(a) {}); | 63 tr.metrics.MetricRegistry.register(function(a) {}); |
| 64 }); | 64 }); |
| 65 }); | 65 }); |
| 66 }); | 66 }); |
| 67 </script> | 67 </script> |
| OLD | NEW |