Merge "Report plugins and extensions in metrics"
This commit is contained in:
@@ -109,6 +109,9 @@
|
|||||||
|
|
||||||
const pending = [];
|
const pending = [];
|
||||||
|
|
||||||
|
const loadedPlugins = [];
|
||||||
|
const detectedExtensions = [];
|
||||||
|
|
||||||
const onError = function(oldOnError, msg, url, line, column, error) {
|
const onError = function(oldOnError, msg, url, line, column, error) {
|
||||||
if (oldOnError) {
|
if (oldOnError) {
|
||||||
oldOnError(msg, url, line, column, error);
|
oldOnError(msg, url, line, column, error);
|
||||||
@@ -190,6 +193,7 @@
|
|||||||
reporter(...args) {
|
reporter(...args) {
|
||||||
const report = (this._isMetricsPluginLoaded() && !pending.length) ?
|
const report = (this._isMetricsPluginLoaded() && !pending.length) ?
|
||||||
this.defaultReporter : this.cachingReporter;
|
this.defaultReporter : this.cachingReporter;
|
||||||
|
args.splice(4, 0, loadedPlugins, detectedExtensions);
|
||||||
report.apply(this, args);
|
report.apply(this, args);
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -199,16 +203,23 @@
|
|||||||
* @param {string} category
|
* @param {string} category
|
||||||
* @param {string} eventName
|
* @param {string} eventName
|
||||||
* @param {string|number} eventValue
|
* @param {string|number} eventValue
|
||||||
|
* @param {Array} plugins
|
||||||
|
* @param {Array} extensions
|
||||||
* @param {boolean|undefined} opt_noLog If true, the event will not be
|
* @param {boolean|undefined} opt_noLog If true, the event will not be
|
||||||
* logged to the JS console.
|
* logged to the JS console.
|
||||||
*/
|
*/
|
||||||
defaultReporter(type, category, eventName, eventValue, opt_noLog) {
|
defaultReporter(type, category, eventName, eventValue,
|
||||||
|
loadedPlugins, detectedExtensions, opt_noLog) {
|
||||||
const detail = {
|
const detail = {
|
||||||
type,
|
type,
|
||||||
category,
|
category,
|
||||||
name: eventName,
|
name: eventName,
|
||||||
value: eventValue,
|
value: eventValue,
|
||||||
};
|
};
|
||||||
|
if (category === TIMING.CATEGORY_UI_LATENCY) {
|
||||||
|
detail.loadedPlugins = loadedPlugins;
|
||||||
|
detail.detectedExtensions = detectedExtensions;
|
||||||
|
}
|
||||||
document.dispatchEvent(new CustomEvent(type, {detail}));
|
document.dispatchEvent(new CustomEvent(type, {detail}));
|
||||||
if (opt_noLog) { return; }
|
if (opt_noLog) { return; }
|
||||||
if (type === ERROR.TYPE && category === ERROR.CATEGORY) {
|
if (type === ERROR.TYPE && category === ERROR.CATEGORY) {
|
||||||
@@ -229,10 +240,13 @@
|
|||||||
* @param {string} category
|
* @param {string} category
|
||||||
* @param {string} eventName
|
* @param {string} eventName
|
||||||
* @param {string|number} eventValue
|
* @param {string|number} eventValue
|
||||||
|
* @param {Array} plugins
|
||||||
|
* @param {Array} extensions
|
||||||
* @param {boolean|undefined} opt_noLog If true, the event will not be
|
* @param {boolean|undefined} opt_noLog If true, the event will not be
|
||||||
* logged to the JS console.
|
* logged to the JS console.
|
||||||
*/
|
*/
|
||||||
cachingReporter(type, category, eventName, eventValue, opt_noLog) {
|
cachingReporter(type, category, eventName, eventValue,
|
||||||
|
plugins, extensions, opt_noLog) {
|
||||||
if (type === ERROR.TYPE && category === ERROR.CATEGORY) {
|
if (type === ERROR.TYPE && category === ERROR.CATEGORY) {
|
||||||
console.error(eventValue && eventValue.error || eventName);
|
console.error(eventValue && eventValue.error || eventName);
|
||||||
}
|
}
|
||||||
@@ -242,9 +256,11 @@
|
|||||||
this.reporter(...args);
|
this.reporter(...args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.reporter(type, category, eventName, eventValue, opt_noLog);
|
this.reporter(type, category, eventName, eventValue,
|
||||||
|
plugins, extensions, opt_noLog);
|
||||||
} else {
|
} else {
|
||||||
pending.push([type, category, eventName, eventValue, opt_noLog]);
|
pending.push([type, category, eventName, eventValue,
|
||||||
|
plugins, extensions, opt_noLog]);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -337,12 +353,16 @@
|
|||||||
|
|
||||||
reportExtension(name) {
|
reportExtension(name) {
|
||||||
this.reporter(EXTENSION.TYPE, EXTENSION.DETECTED, name);
|
this.reporter(EXTENSION.TYPE, EXTENSION.DETECTED, name);
|
||||||
|
if (!detectedExtensions.includes(name)) {
|
||||||
|
detectedExtensions.push(name);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
pluginLoaded(name) {
|
pluginLoaded(name) {
|
||||||
if (name.startsWith('metrics-')) {
|
if (name.startsWith('metrics-')) {
|
||||||
this.timeEnd(TIMER.METRICS_PLUGIN_LOADED);
|
this.timeEnd(TIMER.METRICS_PLUGIN_LOADED);
|
||||||
}
|
}
|
||||||
|
loadedPlugins.push(name);
|
||||||
},
|
},
|
||||||
|
|
||||||
pluginsLoaded(pluginsList) {
|
pluginsLoaded(pluginsList) {
|
||||||
|
|||||||
@@ -265,7 +265,7 @@ limitations under the License.
|
|||||||
test('pluginsLoaded reports time', () => {
|
test('pluginsLoaded reports time', () => {
|
||||||
sandbox.stub(element, 'now').returns(42);
|
sandbox.stub(element, 'now').returns(42);
|
||||||
element.pluginsLoaded();
|
element.pluginsLoaded();
|
||||||
assert.isTrue(element.defaultReporter.calledWithExactly(
|
assert.isTrue(element.defaultReporter.calledWith(
|
||||||
'timing-report', 'UI Latency', 'PluginsLoaded', 42
|
'timing-report', 'UI Latency', 'PluginsLoaded', 42
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
@@ -287,6 +287,19 @@ limitations under the License.
|
|||||||
assert.isTrue(element.defaultReporter.called);
|
assert.isTrue(element.defaultReporter.called);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('reports plugins in timing events', () => {
|
||||||
|
element.pluginsLoaded = [];
|
||||||
|
sandbox.stub(element, 'now').returns(42);
|
||||||
|
element.pluginLoaded('metrics-xyz1');
|
||||||
|
// element.pluginLoaded('foo');
|
||||||
|
element.time('timeAction');
|
||||||
|
element.timeEnd('timeAction');
|
||||||
|
assert.isTrue(element.defaultReporter.getCall(1).calledWith(
|
||||||
|
'timing-report', 'UI Latency', 'timeAction', 0,
|
||||||
|
['metrics-xyz1']
|
||||||
|
));
|
||||||
|
});
|
||||||
|
|
||||||
test('reports if metrics plugin xyz is loaded', () => {
|
test('reports if metrics plugin xyz is loaded', () => {
|
||||||
element.pluginLoaded('metrics-xyz');
|
element.pluginLoaded('metrics-xyz');
|
||||||
assert.isTrue(element.defaultReporter.called);
|
assert.isTrue(element.defaultReporter.called);
|
||||||
|
|||||||
Reference in New Issue
Block a user