Home | History | Annotate | Download | only in metrics
      1 <!DOCTYPE html>
      2 <!--
      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
      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/metric_registry.html">
     10 <link rel="import" href="/tracing/value/histogram.html">
     11 
     12 <script>
     13 'use strict';
     14 
     15 tr.b.unittest.testSuite(function() {
     16   test('FindMetricByName', function() {
     17     function sampleMetricA(values, model) {
     18       var n1 = new tr.v.Histogram('foo', tr.b.Unit.byName.count);
     19       n1.addSample(1);
     20       values.addHistogram(n1);
     21     }
     22     tr.metrics.MetricRegistry.register(sampleMetricA);
     23 
     24     function sampleMetricB(values, model) {
     25       var n1 = new tr.v.Histogram('foo', tr.b.Unit.byName.count);
     26       var n2 = new tr.v.Histogram('bar', tr.b.Unit.byName.count);
     27       n1.addSample(1);
     28       n2.addSample(2);
     29       values.addHistogram(n1);
     30       values.addHistogram(n2);
     31     }
     32     tr.metrics.MetricRegistry.register(sampleMetricB);
     33 
     34     function sampleMetricC(values, model) {
     35       var n1 = new tr.v.Histogram('foo', tr.b.Unit.byName.count);
     36       var n2 = new tr.v.Histogram('bar', tr.b.Unit.byName.count);
     37       var n3 = new tr.v.Histogram('baz', tr.b.Unit.byName.count);
     38       n1.addSample(1);
     39       n2.addSample(2);
     40       n3.addSample(3);
     41       values.addHistogram(n1);
     42       values.addHistogram(n2);
     43       values.addHistogram(n3);
     44     }
     45     tr.metrics.MetricRegistry.register(sampleMetricC);
     46 
     47     var typeInfo = tr.metrics.MetricRegistry.findTypeInfoWithName(
     48         'sampleMetricB');
     49     assert.strictEqual(typeInfo.constructor, sampleMetricB);
     50   });
     51 
     52   test('registerNonFunctionThrows', function() {
     53     assert.throws(function() {
     54       tr.metrics.MetricRegistry.register('not a function');
     55     });
     56 
     57     assert.throws(function() {
     58       tr.metrics.MetricRegistry.register(function() {});
     59     });
     60 
     61     assert.throws(function() {
     62       tr.metrics.MetricRegistry.register(function(a) {});
     63     });
     64   });
     65 });
     66 </script>
     67