From a9b8c3d2c994975460819384803c84b830771e6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20B=C3=BCchele?= Date: Fri, 10 Aug 2018 09:00:20 -0700 Subject: [PATCH] startup time tracking Summary: Adds tracking from opening the application to the interface being shown. Reviewed By: passy Differential Revision: D9239037 fbshipit-source-id: eba60a9e839f9cc2b7a3c8706c6b9d63acb854b4 --- src/App.js | 23 +++++++++++++++-------- static/index.js | 16 +++++++++++++++- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/App.js b/src/App.js index 24ea397d3..d4b3042a8 100644 --- a/src/App.js +++ b/src/App.js @@ -16,6 +16,7 @@ import BugReporterDialog from './chrome/BugReporterDialog.js'; import ErrorBar from './chrome/ErrorBar.js'; import PluginContainer from './PluginContainer.js'; import PluginManager from './chrome/PluginManager.js'; +import {ipcRenderer} from 'electron'; import type Logger from './fb-stubs/Logger.js'; import type BugReporter from './fb-stubs/BugReporter.js'; @@ -33,13 +34,18 @@ type Props = { }; export class App extends React.Component { - constructor(props: Props) { - performance.mark('init'); - super(props); - } - componentDidMount() { - this.props.logger.trackTimeSince('init'); + // track time since launch + const [s, ns] = process.hrtime(); + const launchEndTime = s * 1e3 + ns / 1e6; + ipcRenderer.on('getLaunchTime', (event, launchStartTime) => { + this.props.logger.track( + 'performance', + 'launchTime', + launchEndTime - launchStartTime, + ); + }); + ipcRenderer.send('getLaunchTime'); } render() { @@ -65,7 +71,6 @@ export class App extends React.Component { ); } } - export default connect( ({ application: {pluginManagerVisible, bugDialogVisible, leftSidebarVisible}, @@ -77,5 +82,7 @@ export default connect( selectedDevice, error, }), - {toggleBugDialogVisible}, + { + toggleBugDialogVisible, + }, )(App); diff --git a/static/index.js b/static/index.js index fa3a6f304..9f3cae33c 100644 --- a/static/index.js +++ b/static/index.js @@ -4,7 +4,11 @@ * LICENSE file in the root directory of this source tree. * @format */ -const {app, BrowserWindow} = require('electron'); + +const [s, ns] = process.hrtime(); +let launchStartTime = s * 1e3 + ns / 1e6; + +const {app, BrowserWindow, ipcMain} = require('electron'); const path = require('path'); const url = require('url'); const fs = require('fs'); @@ -128,6 +132,16 @@ app.on('ready', function() { installExtension(REDUX_DEVTOOLS.id); } }); + +ipcMain.on('getLaunchTime', event => { + if (launchStartTime) { + event.sender.send('getLaunchTime', launchStartTime); + // set launchTime to null to only report it once, to prevents reporting wrong + // launch times for example after reloading the renderer process + launchStartTime = null; + } +}); + function tryCreateWindow() { if (appReady && pluginsCompiled) { win = new BrowserWindow({