Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 |
| 11 // This file was adapted from | |
|
rgustafson
2013/03/28 21:49:56
What other metrics will you track with this? If yo
vadimt
2013/03/28 22:05:05
I also plan to record errors (may be, using histog
rgustafson
2013/03/29 02:17:55
There's absolutely no benefit to having this file
skare_
2013/03/29 18:08:35
agree - duplicating a sibling file seems error-pro
vadimt
2013/03/29 20:15:28
Done.
vadimt
2013/03/29 20:15:28
Done.
| |
| 12 // chrome/browser/resources/file_manager/js/metrics.js. | |
| 13 // TODO(vadimt): Remove unused code. | |
|
skare_
2013/03/28 21:24:51
possible to unify between the two extensions?
vadimt
2013/03/28 21:36:50
Ideas?
Copy from file_manager as a custom build st
skare_
2013/03/29 18:08:35
something like that, but only when you really need
vadimt
2013/03/29 20:15:28
Done.
| |
| 14 | |
| 11 var metrics = {}; | 15 var metrics = {}; |
| 12 | 16 |
| 13 /** | 17 /** |
| 14 * A map from interval name to interval start timestamp. | 18 * A map from interval name to interval start timestamp. |
| 15 */ | 19 */ |
| 16 metrics.intervals = {}; | 20 metrics.intervals = {}; |
| 17 | 21 |
| 18 /** | 22 /** |
| 19 * Start the named time interval. | 23 * Start the named time interval. |
| 20 * Should be followed by a call to recordInterval with the same name. | 24 * Should be followed by a call to recordInterval with the same name. |
| 21 * | 25 * |
| 22 * @param {string} name Unique interval name. | 26 * @param {string} name Unique interval name. |
| 23 */ | 27 */ |
| 24 metrics.startInterval = function(name) { | 28 metrics.startInterval = function(name) { |
| 25 metrics.intervals[name] = Date.now(); | 29 metrics.intervals[name] = Date.now(); |
| 26 }; | 30 }; |
| 27 | 31 |
| 28 metrics.startInterval('Load.Total'); | 32 metrics.startInterval('Load.Total'); |
| 29 metrics.startInterval('Load.Script'); | 33 metrics.startInterval('Load.Script'); |
| 30 | 34 |
| 31 /** | 35 /** |
| 32 * Convert a short metric name to the full format. | 36 * Convert a short metric name to the full format. |
| 33 * | 37 * |
| 34 * @param {string} name Short metric name. | 38 * @param {string} name Short metric name. |
| 35 * @return {string} Full metric name. | 39 * @return {string} Full metric name. |
| 36 * @private | 40 * @private |
| 37 */ | 41 */ |
| 38 metrics.convertName_ = function(name) { | 42 metrics.convertName_ = function(name) { |
| 39 return 'FileBrowser.' + name; | 43 return 'GoogleNow.' + name; |
| 40 }; | 44 }; |
| 41 | 45 |
| 42 /** | 46 /** |
| 43 * Wrapper method for calling chrome.fileBrowserPrivate safely. | 47 * Wrapper method for calling chrome.metricsPrivate safely. |
| 44 * @param {string} name Method name. | 48 * @param {string} name Method name. |
| 45 * @param {Array.<Object>} args Arguments. | 49 * @param {Array.<Object>} args Arguments. |
| 46 * @private | 50 * @private |
| 47 */ | 51 */ |
| 48 metrics.call_ = function(name, args) { | 52 metrics.call_ = function(name, args) { |
| 49 if (!chrome.metricsPrivate) | 53 if (!chrome.metricsPrivate) |
| 50 return; // Mock object not loaded yet, ignore. | 54 return; // Mock object not loaded yet, ignore. |
| 51 | 55 |
| 52 try { | 56 try { |
| 53 chrome.metricsPrivate[name].apply(chrome.metricsPrivate, args); | 57 chrome.metricsPrivate[name].apply(chrome.metricsPrivate, args); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 125 'min': 1, | 129 'min': 1, |
| 126 'max': boundaryValue, | 130 'max': boundaryValue, |
| 127 'buckets': boundaryValue + 1 | 131 'buckets': boundaryValue + 1 |
| 128 }; | 132 }; |
| 129 metrics.call_('recordValue', [metricDescr, index]); | 133 metrics.call_('recordValue', [metricDescr, index]); |
| 130 if (metrics.log) { | 134 if (metrics.log) { |
| 131 console.log('chrome.metricsPrivate.recordValue', | 135 console.log('chrome.metricsPrivate.recordValue', |
| 132 [metricDescr.metricName, index, value]); | 136 [metricDescr.metricName, index, value]); |
| 133 } | 137 } |
| 134 }; | 138 }; |
| OLD | NEW |