Merge "Send metrics logs after metrics plugin loaded"

This commit is contained in:
Milutin Kristofic
2019-07-23 15:23:18 +00:00
committed by Gerrit Code Review
3 changed files with 23 additions and 4 deletions

View File

@@ -87,10 +87,12 @@
STARTUP_DIFF_VIEW_DISPLAYED: 'StartupDiffViewDisplayed', STARTUP_DIFF_VIEW_DISPLAYED: 'StartupDiffViewDisplayed',
STARTUP_FILE_LIST_DISPLAYED: 'StartupFileListDisplayed', STARTUP_FILE_LIST_DISPLAYED: 'StartupFileListDisplayed',
WEB_COMPONENTS_READY: 'WebComponentsReady', WEB_COMPONENTS_READY: 'WebComponentsReady',
METRICS_PLUGIN_LOADED: 'MetricsPluginLoaded',
}; };
const STARTUP_TIMERS = {}; const STARTUP_TIMERS = {};
STARTUP_TIMERS[TIMER.PLUGINS_LOADED] = 0; STARTUP_TIMERS[TIMER.PLUGINS_LOADED] = 0;
STARTUP_TIMERS[TIMER.METRICS_PLUGIN_LOADED] = 0;
STARTUP_TIMERS[TIMER.STARTUP_CHANGE_DISPLAYED] = 0; STARTUP_TIMERS[TIMER.STARTUP_CHANGE_DISPLAYED] = 0;
STARTUP_TIMERS[TIMER.STARTUP_CHANGE_LOAD_FULL] = 0; STARTUP_TIMERS[TIMER.STARTUP_CHANGE_LOAD_FULL] = 0;
STARTUP_TIMERS[TIMER.STARTUP_DASHBOARD_DISPLAYED] = 0; STARTUP_TIMERS[TIMER.STARTUP_DASHBOARD_DISPLAYED] = 0;
@@ -174,8 +176,13 @@
!this._baselines.hasOwnProperty(TIMER.PLUGINS_LOADED); !this._baselines.hasOwnProperty(TIMER.PLUGINS_LOADED);
}, },
_isMetricsPluginLoaded() {
return this._arePluginsLoaded() || this._baselines &&
!this._baselines.hasOwnProperty(TIMER.METRICS_PLUGIN_LOADED);
},
reporter(...args) { reporter(...args) {
const report = (this._arePluginsLoaded() && !pending.length) ? const report = (this._isMetricsPluginLoaded() && !pending.length) ?
this.defaultReporter : this.cachingReporter; this.defaultReporter : this.cachingReporter;
report.apply(this, args); report.apply(this, args);
}, },
@@ -223,7 +230,7 @@
if (type === ERROR.TYPE && category === ERROR.CATEGORY) { if (type === ERROR.TYPE && category === ERROR.CATEGORY) {
console.error(eventValue.error || eventName); console.error(eventValue.error || eventName);
} }
if (this._arePluginsLoaded()) { if (this._isMetricsPluginLoaded()) {
if (pending.length) { if (pending.length) {
for (const args of pending.splice(0)) { for (const args of pending.splice(0)) {
this.reporter(...args); this.reporter(...args);
@@ -326,6 +333,12 @@
this.reporter(EXTENSION.TYPE, EXTENSION.DETECTED, name); this.reporter(EXTENSION.TYPE, EXTENSION.DETECTED, name);
}, },
pluginLoaded(name) {
if (name.startsWith('metrics-')) {
this.timeEnd(TIMER.METRICS_PLUGIN_LOADED);
}
},
pluginsLoaded(pluginsList) { pluginsLoaded(pluginsList) {
this.timeEnd(TIMER.PLUGINS_LOADED); this.timeEnd(TIMER.PLUGINS_LOADED);
this.reporter( this.reporter(
@@ -346,8 +359,8 @@
timeEnd(name) { timeEnd(name) {
if (!this._baselines.hasOwnProperty(name)) { return; } if (!this._baselines.hasOwnProperty(name)) { return; }
const baseTime = this._baselines[name]; const baseTime = this._baselines[name];
this._reportTiming(name, this.now() - baseTime);
delete this._baselines[name]; delete this._baselines[name];
this._reportTiming(name, this.now() - baseTime);
// Finalize the interval. Either from a registered start mark or // Finalize the interval. Either from a registered start mark or
// the navigation start time (if baseTime is 0). // the navigation start time (if baseTime is 0).

View File

@@ -266,7 +266,7 @@ limitations under the License.
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.calledWithExactly(
'timing-report', 'UI Latency', 'PluginsLoaded', 42, undefined 'timing-report', 'UI Latency', 'PluginsLoaded', 42
)); ));
}); });
@@ -287,6 +287,11 @@ limitations under the License.
assert.isTrue(element.defaultReporter.called); assert.isTrue(element.defaultReporter.called);
}); });
test('reports if metrics plugin xyz is loaded', () => {
element.pluginLoaded('metrics-xyz');
assert.isTrue(element.defaultReporter.called);
});
test('reports cached events preserving order', () => { test('reports cached events preserving order', () => {
element.time('foo'); element.time('foo');
element.time('bar'); element.time('bar');

View File

@@ -673,6 +673,7 @@
delete _pluginsPending[name]; delete _pluginsPending[name];
_pluginsInstalled.push(name); _pluginsInstalled.push(name);
Gerrit._setPluginsCount(_pluginsPendingCount - 1); Gerrit._setPluginsCount(_pluginsPendingCount - 1);
getReporting().pluginLoaded(name);
console.log(`Plugin ${name} installed.`); console.log(`Plugin ${name} installed.`);
} }
}; };