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

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

Issue 2656493002: Register metric Histogram names. (Closed)
Patch Set: rebase Created 3 years, 10 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/metrics/all_metrics.html"> 8 <link rel="import" href="/tracing/metrics/all_metrics.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/mre/function_handle.html"> 10 <link rel="import" href="/tracing/mre/function_handle.html">
11 <link rel="import" href="/tracing/value/histogram_set.html"> 11 <link rel="import" href="/tracing/value/histogram_set.html">
12 12
13 <script> 13 <script>
14 'use strict'; 14 'use strict';
15 15
16 tr.exportTo('tr.metrics', function() { 16 tr.exportTo('tr.metrics', function() {
17 /** 17 /**
18 * @param {!tr.model.Model} model 18 * @param {!tr.model.Model} model
19 * @param {!Object} options 19 * @param {!Object} options
20 * @param {!Array.<string>} options.metrics 20 * @param {!Array.<string>} options.metrics
21 * @return {!tr.v.HistogramSet} 21 * @return {!tr.v.HistogramSet}
22 */ 22 */
23 function runMetrics(model, options) { 23 function runMetrics(model, options) {
24 if (options === undefined) 24 if (options === undefined) {
25 throw new Error('Options are required.'); 25 throw new Error('Options are required.');
26 }
26 27
27 var metricNames = options.metrics; 28 var metricNames = options.metrics;
28 if (!metricNames) 29 if (!metricNames) {
29 throw new Error('Metric names should be specified.'); 30 throw new Error('Metric names should be specified.');
31 }
30 32
31 var histograms = new tr.v.HistogramSet(); 33 var histograms = new tr.v.HistogramSet();
32 34
35 var metrics = [];
33 for (var metricName of metricNames) { 36 for (var metricName of metricNames) {
34 var metric = tr.metrics.MetricRegistry.findTypeInfoWithName(metricName); 37 var metric = tr.metrics.MetricRegistry.findTypeInfoWithName(metricName);
35 if (metric === undefined) 38 if (metric === undefined) {
36 throw new Error('"' + metricName + '" is not a registered metric.'); 39 throw new Error('"' + metricName + '" is not a registered metric.');
37 metric.constructor(histograms, model, options); 40 }
41 metrics.push(metric);
42 try {
43 metric.constructor(histograms, model, options);
44 } catch (e) {
45 synthesizeFailureHistograms(histograms, metric, e);
46 }
38 } 47 }
39 48
49 validateHistogramNames(histograms, metrics);
50
40 return histograms; 51 return histograms;
41 } 52 }
42 53
43 /** 54 /**
44 * @param {!tr.v.HistogramSet} histograms 55 * @param {!tr.v.HistogramSet} histograms
56 * @param {!Array.<!tr.b.RegisteredTypeInfo>} metrics
57 */
58 function validateHistogramNames(histograms, metrics) {
59 var registeredHistogramNames = new Set();
60 for (var metric of metrics) {
61 for (var name of metric.metadata.histogramNames) {
62 registeredHistogramNames.add(name);
63 }
64 }
65 for (var hist of histograms) {
66 if (!registeredHistogramNames.has(hist.name)) {
67 throw new Error('"' + hist.name +
68 '" is not a registered histogram name.');
69 }
70 }
71 }
72
73 /**
74 * @param {!tr.v.HistogramSet} histograms
75 * @param {!tr.b.RegisteredTypeInfo} metric
76 * @param {!Error} error
77 */
78 function synthesizeFailureHistograms(histograms, metric, error) {
79 for (var name of metric.metadata.histogramNames) {
80 var hist = new tr.v.Histogram(name, tr.b.Unit.byName.unitlessNumber);
81 // TODO(benjhayden): add a FailureInfo containing |error|.
82 histograms.addHistogram(hist);
83 }
84 }
85
86 /**
87 * @param {!tr.v.HistogramSet} histograms
45 * @param {!tr.model.Model} model 88 * @param {!tr.model.Model} model
46 */ 89 */
47 function addTelemetryInfo(histograms, model) { 90 function addTelemetryInfo(histograms, model) {
48 var telemetry = new tr.v.d.TelemetryInfo(); 91 var telemetry = new tr.v.d.TelemetryInfo();
49 for (var metadata of model.metadata) { 92 for (var metadata of model.metadata) {
50 if (!metadata.value) continue; 93 if (!metadata.value) continue;
51 94
52 if (metadata.value.telemetry) { 95 if (metadata.value.telemetry) {
53 telemetry.addInfo(metadata.value.telemetry); 96 telemetry.addInfo(metadata.value.telemetry);
54 } 97 }
(...skipping 27 matching lines...) Expand all
82 } 125 }
83 126
84 tr.mre.FunctionRegistry.register(metricMapFunction); 127 tr.mre.FunctionRegistry.register(metricMapFunction);
85 128
86 return { 129 return {
87 metricMapFunction, 130 metricMapFunction,
88 runMetrics, 131 runMetrics,
89 }; 132 };
90 }); 133 });
91 </script> 134 </script>
OLDNEW
« no previous file with comments | « tracing/tracing/metrics/cpu_process_metric.html ('k') | tracing/tracing/metrics/metric_registry.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698