Add markers for more granular logging of startup time

This commit is contained in:
Rafael Oleza
2019-05-07 17:45:59 +02:00
parent a6382d707b
commit 90bcdf4cba
6 changed files with 95 additions and 1 deletions

View File

@@ -6,6 +6,7 @@ const StorageFolder = require('../storage-folder')
const Config = require('../config')
const ConfigFile = require('../config-file')
const FileRecoveryService = require('./file-recovery-service')
const StartupTime = require('../startup-time')
const ipcHelpers = require('../ipc-helpers')
const {BrowserWindow, Menu, app, clipboard, dialog, ipcMain, shell, screen} = require('electron')
const {CompositeDisposable, Disposable} = require('event-kit')
@@ -135,6 +136,8 @@ module.exports =
class AtomApplication extends EventEmitter {
// Public: The entry point into the Atom application.
static open (options) {
StartupTime.addMarker('main-process:atom-application:open')
const socketSecret = getExistingSocketSecret(options.version)
const socketPath = getSocketPath(socketSecret)
const createApplication = options.createApplication || (async () => {
@@ -172,6 +175,8 @@ class AtomApplication extends EventEmitter {
}
constructor (options) {
StartupTime.addMarker('main-process:atom-application:constructor:start')
super()
this.quitting = false
this.quittingForUpdate = false
@@ -214,6 +219,8 @@ class AtomApplication extends EventEmitter {
this.disposable = new CompositeDisposable()
this.handleEvents()
StartupTime.addMarker('main-process:atom-application:constructor:end')
}
// This stuff was previously done in the constructor, but we want to be able to construct this object
@@ -221,6 +228,8 @@ class AtomApplication extends EventEmitter {
// of these various sub-objects into the constructor, but you'll need to remove the side-effects they
// perform during their construction, adding an initialize method that you call here.
async initialize (options) {
StartupTime.addMarker('main-process:atom-application:initialize:start')
global.atomApplication = this
// DEPRECATED: This can be removed at some point (added in 1.13)
@@ -246,6 +255,8 @@ class AtomApplication extends EventEmitter {
this.autoUpdateManager.initialize()
await socketServerPromise
StartupTime.addMarker('main-process:atom-application:initialize:end')
return result
}
@@ -1084,6 +1095,7 @@ class AtomApplication extends EventEmitter {
let openedWindow
if (existingWindow) {
openedWindow = existingWindow
StartupTime.addMarker('main-process:atom-application:open-in-existing')
openedWindow.openLocations(locationsToOpen)
if (openedWindow.isMinimized()) {
openedWindow.restore()
@@ -1108,6 +1120,7 @@ class AtomApplication extends EventEmitter {
if (!resourcePath) resourcePath = this.resourcePath
if (!windowDimensions) windowDimensions = this.getDimensionsForNewWindow()
StartupTime.addMarker('main-process:atom-application:create-window')
openedWindow = this.createWindow({
locationsToOpen,
windowInitializationScript,

View File

@@ -2,6 +2,7 @@ const {BrowserWindow, app, dialog, ipcMain} = require('electron')
const path = require('path')
const url = require('url')
const {EventEmitter} = require('events')
const StartupTime = require('../startup-time')
const ICON_PATH = path.resolve(__dirname, '..', '..', 'resources', 'atom.png')
@@ -11,6 +12,8 @@ let nextId = 0
module.exports =
class AtomWindow extends EventEmitter {
constructor (atomApplication, fileRecoveryService, settings = {}) {
StartupTime.addMarker('main-process:atom-window:start')
super()
this.id = nextId++
@@ -78,6 +81,22 @@ class AtomWindow extends EventEmitter {
.some(location => location.pathToOpen && !location.isDirectory)
this.loadSettings.initialProjectRoots = this.projectRoots
StartupTime.addMarker('main-process:atom-window:end')
// Expose the startup markers to the renderer process, so we can have unified
// measures about startup time between the main process and the renderer process.
Object.defineProperty(this.browserWindow, 'startupMarkers', {
get: () => {
// We only want to make the main process startup data available once,
// so if the window is refreshed or a new window is opened, the
// renderer process won't use it again.
const timingData = StartupTime.exportData()
StartupTime.deleteData()
return timingData
}
})
// Only send to the first non-spec window created
if (includeShellLoadTime && !this.isSpec) {
includeShellLoadTime = false

View File

@@ -3,6 +3,8 @@ if (typeof snapshotResult !== 'undefined') {
}
const startTime = Date.now()
const StartupTime = require('../startup-time')
StartupTime.setStartTime()
const path = require('path')
const fs = require('fs-plus')

View File

@@ -8,9 +8,13 @@ const atomPaths = require('../atom-paths')
const fs = require('fs')
const CSON = require('season')
const Config = require('../config')
const StartupTime = require('../startup-time')
StartupTime.setStartTime()
module.exports = function start (resourcePath, devResourcePath, startTime) {
global.shellStartTime = startTime
StartupTime.addMarker('main-process:start')
process.on('uncaughtException', function (error = {}) {
if (error.message != null) {
@@ -85,7 +89,9 @@ module.exports = function start (resourcePath, devResourcePath, startTime) {
app.setPath('userData', temp.mkdirSync('atom-test-data'))
}
StartupTime.addMarker('main-process:electron-onready:start')
app.on('ready', function () {
StartupTime.addMarker('main-process:electron-onready:end')
app.removeListener('open-file', addPathToOpen)
app.removeListener('open-url', addUrlToOpen)
const AtomApplication = require(path.join(args.resourcePath, 'src', 'main-process', 'atom-application'))

33
src/startup-time.js Normal file
View File

@@ -0,0 +1,33 @@
let startTime
let markers = []
module.exports = {
setStartTime () {
if (!startTime) {
startTime = Date.now()
}
},
addMarker (label, dateTime) {
if (!startTime) {
return
}
dateTime = dateTime || Date.now()
markers.push({label, time: dateTime - startTime})
},
importData (data) {
startTime = data.startTime
markers = data.markers
},
exportData () {
if (!startTime) {
return undefined
}
return { startTime, markers }
},
deleteData () {
startTime = undefined
markers = []
}
}