Bug 1411887 - Add telemetry to track console refresh time when reload a page. r=nchevobbe

MozReview-Commit-ID: 8zZyq9suJWB

--HG--
extra : rebase_source : 5b5ed09859a04116caf0db1041d76fcb97dd570f
This commit is contained in:
Alexandre Poirot 2017-10-24 11:56:58 -07:00
parent 3ccaa127b0
commit 3ac4888c45
4 changed files with 56 additions and 31 deletions

View File

@ -1989,8 +1989,8 @@ Toolbox.prototype = {
*/
async _onWillNavigate() {
let toolId = this.currentToolId;
// For now, only inspector fires "reloaded" event
if (toolId != "inspector") {
// For now, only inspector and webconsole fires "reloaded" event
if (toolId != "inspector" && toolId != "webconsole") {
return;
}

View File

@ -32,7 +32,7 @@ function NewConsoleOutputWrapper(parentNode, jsterm, toolbox, owner, document) {
this.queuedMessageAdds = [];
this.queuedMessageUpdates = [];
this.queuedRequestUpdates = [];
this.throttledDispatchTimeout = false;
this.throttledDispatchPromise = null;
store = configureStore(this.jsterm.hud);
}
@ -275,40 +275,53 @@ NewConsoleOutputWrapper.prototype = {
this.setTimeoutIfNeeded();
},
/**
* Returns a Promise that resolves once any async dispatch is finally dispatched.
*/
waitAsyncDispatches: function () {
if (!this.throttledDispatchPromise) {
return Promise.resolve();
}
return this.throttledDispatchPromise;
},
setTimeoutIfNeeded: function () {
if (this.throttledDispatchTimeout) {
if (this.throttledDispatchPromise) {
return;
}
this.throttledDispatchTimeout = setTimeout(() => {
this.throttledDispatchTimeout = null;
this.throttledDispatchPromise = new Promise(done => {
setTimeout(() => {
this.throttledDispatchPromise = null;
store.dispatch(actions.messagesAdd(this.queuedMessageAdds));
this.queuedMessageAdds = [];
store.dispatch(actions.messagesAdd(this.queuedMessageAdds));
this.queuedMessageAdds = [];
if (this.queuedMessageUpdates.length > 0) {
this.queuedMessageUpdates.forEach(({ message, res }) => {
store.dispatch(actions.networkMessageUpdate(message, null, res));
this.jsterm.hud.emit("network-message-updated", res);
});
this.queuedMessageUpdates = [];
}
if (this.queuedRequestUpdates.length > 0) {
this.queuedRequestUpdates.forEach(({ id, data}) => {
store.dispatch(actions.networkUpdateRequest(id, data));
});
this.queuedRequestUpdates = [];
if (this.queuedMessageUpdates.length > 0) {
this.queuedMessageUpdates.forEach(({ message, res }) => {
store.dispatch(actions.networkMessageUpdate(message, null, res));
this.jsterm.hud.emit("network-message-updated", res);
});
this.queuedMessageUpdates = [];
}
if (this.queuedRequestUpdates.length > 0) {
this.queuedRequestUpdates.forEach(({ id, data}) => {
store.dispatch(actions.networkUpdateRequest(id, data));
});
this.queuedRequestUpdates = [];
// Fire an event indicating that all data fetched from
// the backend has been received. This is based on
// 'FirefoxDataProvider.isQueuePayloadReady', see more
// comments in that method.
// (netmonitor/src/connector/firefox-data-provider).
// This event might be utilized in tests to find the right
// time when to finish.
this.jsterm.hud.emit("network-request-payload-ready");
}
}, 50);
// Fire an event indicating that all data fetched from
// the backend has been received. This is based on
// 'FirefoxDataProvider.isQueuePayloadReady', see more
// comments in that method.
// (netmonitor/src/connector/firefox-data-provider).
// This event might be utilized in tests to find the right
// time when to finish.
this.jsterm.hud.emit("network-request-payload-ready");
}
done();
}, 50);
});
},
// Should be used for test purpose only.

View File

@ -298,7 +298,7 @@ NewWebConsoleFrame.prototype = {
* @param object packet
* Notification packet received from the server.
*/
handleTabNavigated: function (event, packet) {
handleTabNavigated: async function (event, packet) {
if (event == "will-navigate") {
if (this.persistLog) {
// Add a _type to hit convertCachedPacket.
@ -316,6 +316,13 @@ NewWebConsoleFrame.prototype = {
if (event == "navigate" && !packet.nativeConsoleAPI) {
this.logWarningAboutReplacedAPI();
}
if (event == "navigate") {
// Wait for completion of any async dispatch before notifying that the console
// is fully updated after a page reload
await this.newConsoleOutput.waitAsyncDispatches();
this.emit("reloaded");
}
},
clearOutput(clearStorage) {

View File

@ -81,6 +81,11 @@ WebConsolePanel.prototype = {
})
.then((webConsole) => {
this.hud = webConsole;
// Pipe 'reloaded' event from NewWebConsoleFrame to WebConsolePanel.
// These events are listened by the Toolbox.
this.hud.ui.on("reloaded", () => {
this.emit("reloaded");
});
this._isReady = true;
this.emit("ready");
return this;