From 220052d70d58d0b55076fb085537f5d48adbe7e1 Mon Sep 17 00:00:00 2001 From: Michel Weststrate Date: Wed, 8 Apr 2020 06:24:51 -0700 Subject: [PATCH] measure clean versus unclean exits Summary: This adds another field to the exit data to record whether we had a clean exit where the app was closed as it should. Note that doing a reload inside Flipper will be recorded as an unclean exit. Reviewed By: passy Differential Revision: D20915481 fbshipit-source-id: 240192d7a69bf620bfaa316e3e5cb0f45d6a34cc --- desktop/app/src/dispatcher/tracking.tsx | 42 ++++++++++++++++++++----- desktop/static/main.ts | 2 +- 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/desktop/app/src/dispatcher/tracking.tsx b/desktop/app/src/dispatcher/tracking.tsx index 0c61c556c..f80046e38 100644 --- a/desktop/app/src/dispatcher/tracking.tsx +++ b/desktop/app/src/dispatcher/tracking.tsx @@ -54,6 +54,20 @@ export default (store: Store, logger: Logger) => { ...oldExitData, timeSinceLastStartup, }); + // create fresh exit data + const { + selectedDevice, + selectedApp, + selectedPlugin, + } = store.getState().connections; + persistExitData( + { + selectedDevice, + selectedApp, + selectedPlugin, + }, + false, + ); } function droppedFrameDetection( @@ -81,7 +95,7 @@ export default (store: Store, logger: Logger) => { ); } - ipcRenderer.on('trackUsage', () => { + ipcRenderer.on('trackUsage', (_e, ...args: any[]) => { const state = store.getState(); const { selectedDevice, @@ -90,7 +104,10 @@ export default (store: Store, logger: Logger) => { clients, } = state.connections; - persistExitData({selectedDevice, selectedPlugin, selectedApp}); + persistExitData( + {selectedDevice, selectedPlugin, selectedApp}, + args[0] === 'exit', + ); const currentTime = Date.now(); const usageSummary = computeUsageSummary(state.usageTracking, currentTime); @@ -220,6 +237,7 @@ interface ExitData { deviceTitle: string; plugin: string; app: string; + cleanExit: boolean; } function loadExitData(): ExitData | undefined { @@ -229,7 +247,11 @@ function loadExitData(): ExitData | undefined { const data = window.localStorage.getItem(flipperExitDataKey); if (data) { try { - return JSON.parse(data); + const res = JSON.parse(data); + if (res.cleanExit === undefined) { + res.cleanExit = true; // avoid skewing results for historical data where this info isn't present + } + return res; } catch (e) { console.warn('Failed to parse flipperExitData', e); } @@ -237,11 +259,14 @@ function loadExitData(): ExitData | undefined { return undefined; } -export function persistExitData(state: { - selectedDevice: BaseDevice | null; - selectedPlugin: string | null; - selectedApp: string | null; -}) { +export function persistExitData( + state: { + selectedDevice: BaseDevice | null; + selectedPlugin: string | null; + selectedApp: string | null; + }, + cleanExit: boolean, +) { if (!window.localStorage) { return; } @@ -252,6 +277,7 @@ export function persistExitData(state: { deviceTitle: state.selectedDevice ? state.selectedDevice.title : '', plugin: state.selectedPlugin || '', app: state.selectedApp ? deconstructClientId(state.selectedApp).app : '', + cleanExit, }; window.localStorage.setItem( flipperExitDataKey, diff --git a/desktop/static/main.ts b/desktop/static/main.ts index 7c39000c1..574e4a0f5 100644 --- a/desktop/static/main.ts +++ b/desktop/static/main.ts @@ -310,7 +310,7 @@ function tryCreateWindow() { }); win.once('ready-to-show', () => win.show()); win.once('close', () => { - win.webContents.send('trackUsage'); + win.webContents.send('trackUsage', 'exit'); if (process.env.NODE_ENV === 'development') { // Removes as a default protocol for debug builds. Because even when the // production application is installed, and one tries to deeplink through