OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview Utility methods for accessing chrome.metricsPrivate API. | 6 * @fileoverview Utility methods for accessing chrome.metricsPrivate API. |
7 * | 7 * |
8 * To be included as a first script in main.html | 8 * To be included as a first script in main.html |
9 */ | 9 */ |
10 | 10 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
47 */ | 47 */ |
48 metrics.call_ = function(name, args) { | 48 metrics.call_ = function(name, args) { |
49 try { | 49 try { |
50 chrome.metricsPrivate[name].apply(chrome.metricsPrivate, args); | 50 chrome.metricsPrivate[name].apply(chrome.metricsPrivate, args); |
51 } catch (e) { | 51 } catch (e) { |
52 console.error(e.stack); | 52 console.error(e.stack); |
53 } | 53 } |
54 }; | 54 }; |
55 | 55 |
56 /** | 56 /** |
57 * Create a decorator function that calls a chrome.metricsPrivate function | 57 * Records a value than can range from 1 to 10,000. |
58 * with the same name and correct parameters. | 58 * @param {string} name Short metric name. |
59 * | 59 * @param {number} value Value to be recorded. |
60 * @param {string} name Method name. | |
61 */ | 60 */ |
62 metrics.decorate = function(name) { | 61 metrics.recordMediumCount = function(name, value) { |
63 metrics[name] = function() { | 62 var args = [metrics.convertName_(name), value]; |
64 var args = Array.apply(null, arguments); | 63 metrics.call_('recordMediumCount', args); |
65 args[0] = metrics.convertName_(args[0]); | 64 if (metrics.log) |
66 metrics.call_(name, args); | 65 console.log('chrome.metricsPrivate.recordMediumCount', args); |
67 if (metrics.log) { | |
68 console.log('chrome.metricsPrivate.' + name, args); | |
69 } | |
70 }; | |
71 }; | 66 }; |
72 | 67 |
73 metrics.decorate('recordMediumCount'); | 68 /** |
74 metrics.decorate('recordSmallCount'); | 69 * Records a value than can range from 1 to 100. |
75 metrics.decorate('recordTime'); | 70 * @param {string} name Short metric name. |
76 metrics.decorate('recordUserAction'); | 71 * @param {number} value Value to be recorded. |
72 */ | |
73 metrics.recordSmallCount = function(name, value) { | |
74 var args = [metrics.convertName_(name), value]; | |
75 metrics.call_('recordSmallCount', args); | |
76 if (metrics.log) | |
hirono
2014/10/24 06:45:56
How about moving all the common part to metrics.ca
fukino
2014/10/27 09:11:24
metrics.recordEnum() also calls metrics.call_(), b
hirono
2014/10/27 09:28:45
How about logging part? You also would like to hav
fukino
2014/10/27 09:41:29
Nice suggestion! Thanks!
I moved the logging part
| |
77 console.log('chrome.metricsPrivate.recordSmallCount', args); | |
78 }; | |
79 | |
80 /** | |
81 * Records an elapsed time of no more than 10 seconds. | |
82 * @param {string} name Short metric name. | |
83 * @param {number} time Time to be recorded in milliseconds. | |
84 */ | |
85 metrics.recordTime = function(name, time) { | |
86 var args = [metrics.convertName_(name), time]; | |
87 metrics.call_('recordTime', args); | |
88 if (metrics.log) | |
89 console.log('chrome.metricsPrivate.recordTime', args); | |
90 }; | |
91 | |
92 /** | |
93 * Records an action performed by the user. | |
94 * @param {string} name Short metric name. | |
95 */ | |
96 metrics.recordUserAction = function(name) { | |
97 var args = [metrics.convertName_(name)]; | |
98 metrics.call_('recordUserAction', args); | |
99 if (metrics.log) | |
100 console.log('chrome.metricsPrivate.recordUserAction', args); | |
101 }; | |
77 | 102 |
78 /** | 103 /** |
79 * Complete the time interval recording. | 104 * Complete the time interval recording. |
80 * | 105 * |
81 * Should be preceded by a call to startInterval with the same name. * | 106 * Should be preceded by a call to startInterval with the same name. * |
82 * | 107 * |
83 * @param {string} name Unique interval name. | 108 * @param {string} name Unique interval name. |
84 */ | 109 */ |
85 metrics.recordInterval = function(name) { | 110 metrics.recordInterval = function(name) { |
86 if (name in metrics.intervals) { | 111 if (name in metrics.intervals) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 'min': 1, | 147 'min': 1, |
123 'max': boundaryValue, | 148 'max': boundaryValue, |
124 'buckets': boundaryValue + 1 | 149 'buckets': boundaryValue + 1 |
125 }; | 150 }; |
126 metrics.call_('recordValue', [metricDescr, index]); | 151 metrics.call_('recordValue', [metricDescr, index]); |
127 if (metrics.log) { | 152 if (metrics.log) { |
128 console.log('chrome.metricsPrivate.recordValue', | 153 console.log('chrome.metricsPrivate.recordValue', |
129 [metricDescr.metricName, index, value]); | 154 [metricDescr.metricName, index, value]); |
130 } | 155 } |
131 }; | 156 }; |
OLD | NEW |