From 0b150fc6a82137f42a83bef857675964a7a5d9ed Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 27 Apr 2015 16:40:02 -0700 Subject: [PATCH 1/6] Add --profile-startup --- src/browser/main.coffee | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/browser/main.coffee b/src/browser/main.coffee index 469d53fae..e73bb4c40 100644 --- a/src/browser/main.coffee +++ b/src/browser/main.coffee @@ -110,6 +110,7 @@ parseCommandLine = -> options.alias('h', 'help').boolean('h').describe('h', 'Print this usage message.') options.alias('l', 'log-file').string('l').describe('l', 'Log all output to file.') options.alias('n', 'new-window').boolean('n').describe('n', 'Open a new window.') + options.boolean('profile-startup').describe('profile-startup', 'Create a profile of startup execution time.') options.alias('r', 'resource-path').string('r').describe('r', 'Set the path to the Atom source directory and enable dev-mode.') options.alias('s', 'spec-directory').string('s').describe('s', 'Set the directory from which to run package specs (default: Atom\'s spec directory).') options.boolean('safe').describe('safe', 'Do not load packages from ~/.atom/packages or ~/.atom/dev/packages.') @@ -139,6 +140,7 @@ parseCommandLine = -> pidToKillWhenClosed = args['pid'] if args['wait'] logFile = args['log-file'] socketPath = args['socket-path'] + profileStartup = args['profile-startup'] if args['resource-path'] devMode = true @@ -165,6 +167,6 @@ parseCommandLine = -> {resourcePath, pathsToOpen, executedFrom, test, version, pidToKillWhenClosed, devMode, apiPreviewMode, safeMode, newWindow, specDirectory, logFile, - socketPath} + socketPath, profileStartup} start() From 6b1c7f7a04e63bc34ebfc3374c75b427b342d767 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 27 Apr 2015 16:40:28 -0700 Subject: [PATCH 2/6] :memo: Add missing the --- src/browser/main.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/browser/main.coffee b/src/browser/main.coffee index e73bb4c40..e35632104 100644 --- a/src/browser/main.coffee +++ b/src/browser/main.coffee @@ -110,7 +110,7 @@ parseCommandLine = -> options.alias('h', 'help').boolean('h').describe('h', 'Print this usage message.') options.alias('l', 'log-file').string('l').describe('l', 'Log all output to file.') options.alias('n', 'new-window').boolean('n').describe('n', 'Open a new window.') - options.boolean('profile-startup').describe('profile-startup', 'Create a profile of startup execution time.') + options.boolean('profile-startup').describe('profile-startup', 'Create a profile of the startup execution time.') options.alias('r', 'resource-path').string('r').describe('r', 'Set the path to the Atom source directory and enable dev-mode.') options.alias('s', 'spec-directory').string('s').describe('s', 'Set the directory from which to run package specs (default: Atom\'s spec directory).') options.boolean('safe').describe('safe', 'Do not load packages from ~/.atom/packages or ~/.atom/dev/packages.') From 9c7f9f74a172df70fe6e61319c44a61e96b3847a Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 27 Apr 2015 18:13:01 -0700 Subject: [PATCH 3/6] Thread through profileStartup load setting --- src/browser/atom-application.coffee | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/browser/atom-application.coffee b/src/browser/atom-application.coffee index dbe29caab..178755786 100644 --- a/src/browser/atom-application.coffee +++ b/src/browser/atom-application.coffee @@ -85,15 +85,16 @@ class AtomApplication else @loadState() or @openPath(options) - openWithOptions: ({pathsToOpen, urlsToOpen, test, pidToKillWhenClosed, devMode, safeMode, apiPreviewMode, newWindow, specDirectory, logFile}) -> + openWithOptions: ({pathsToOpen, urlsToOpen, test, pidToKillWhenClosed, devMode, safeMode, apiPreviewMode, newWindow, specDirectory, logFile, profileStartup}) -> if test @runSpecs({exitWhenDone: true, @resourcePath, specDirectory, logFile}) else if pathsToOpen.length > 0 - @openPaths({pathsToOpen, pidToKillWhenClosed, newWindow, devMode, safeMode, apiPreviewMode}) + @openPaths({pathsToOpen, pidToKillWhenClosed, newWindow, devMode, safeMode, apiPreviewMode, profileStartup}) else if urlsToOpen.length > 0 @openUrl({urlToOpen, devMode, safeMode, apiPreviewMode}) for urlToOpen in urlsToOpen else - @openPath({pidToKillWhenClosed, newWindow, devMode, safeMode, apiPreviewMode}) # Always open a editor window if this is the first instance of Atom. + # Always open a editor window if this is the first instance of Atom. + @openPath({pidToKillWhenClosed, newWindow, devMode, safeMode, apiPreviewMode, profileStartup}) # Public: Removes the {AtomWindow} from the global window list. removeWindow: (window) -> @@ -343,9 +344,10 @@ class AtomApplication # :devMode - Boolean to control the opened window's dev mode. # :safeMode - Boolean to control the opened window's safe mode. # :apiPreviewMode - Boolean to control the opened window's 1.0 API preview mode. + # :profileStartup - Boolean to control creating a profile of the startup time. # :window - {AtomWindow} to open file paths in. - openPath: ({pathToOpen, pidToKillWhenClosed, newWindow, devMode, safeMode, apiPreviewMode, window}) -> - @openPaths({pathsToOpen: [pathToOpen], pidToKillWhenClosed, newWindow, devMode, safeMode, apiPreviewMode, window}) + openPath: ({pathToOpen, pidToKillWhenClosed, newWindow, devMode, safeMode, apiPreviewMode, profileStartup, window}) -> + @openPaths({pathsToOpen: [pathToOpen], pidToKillWhenClosed, newWindow, devMode, safeMode, apiPreviewMode, profileStartup, window}) # Public: Opens multiple paths, in existing windows if possible. # @@ -358,7 +360,7 @@ class AtomApplication # :apiPreviewMode - Boolean to control the opened window's 1.0 API preview mode. # :windowDimensions - Object with height and width keys. # :window - {AtomWindow} to open file paths in. - openPaths: ({pathsToOpen, pidToKillWhenClosed, newWindow, devMode, safeMode, apiPreviewMode, windowDimensions, window}={}) -> + openPaths: ({pathsToOpen, pidToKillWhenClosed, newWindow, devMode, safeMode, apiPreviewMode, windowDimensions, profileStartup, window}={}) -> pathsToOpen = (fs.normalize(pathToOpen) for pathToOpen in pathsToOpen) locationsToOpen = (@locationForPathToOpen(pathToOpen) for pathToOpen in pathsToOpen) @@ -388,7 +390,7 @@ class AtomApplication bootstrapScript ?= require.resolve('../window-bootstrap') resourcePath ?= @resourcePath - openedWindow = new AtomWindow({locationsToOpen, bootstrapScript, resourcePath, devMode, safeMode, apiPreviewMode, windowDimensions}) + openedWindow = new AtomWindow({locationsToOpen, bootstrapScript, resourcePath, devMode, safeMode, apiPreviewMode, windowDimensions, profileStartup}) if pidToKillWhenClosed? @pidsToOpenWindows[pidToKillWhenClosed] = openedWindow From 3cc99d5662b6895046e8a9a1b2252395b8ea36fc Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 27 Apr 2015 18:13:35 -0700 Subject: [PATCH 4/6] Handle profile startup option on load --- static/index.js | 92 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 61 insertions(+), 31 deletions(-) diff --git a/static/index.js b/static/index.js index 2db98a382..c0d031d3d 100644 --- a/static/index.js +++ b/static/index.js @@ -32,46 +32,58 @@ window.onload = function() { var devMode = loadSettings.devMode || !loadSettings.resourcePath.startsWith(process.resourcesPath + path.sep); - setupCoffeeCache(cacheDir); - - ModuleCache = require('../src/module-cache'); - ModuleCache.register(loadSettings); - ModuleCache.add(loadSettings.resourcePath); - - require('grim').includeDeprecatedAPIs = !loadSettings.apiPreviewMode; - - // Start the crash reporter before anything else. - require('crash-reporter').start({ - productName: 'Atom', - companyName: 'GitHub', - // By explicitly passing the app version here, we could save the call - // of "require('remote').require('app').getVersion()". - extra: {_version: loadSettings.appVersion} - }); - - setupVmCompatibility(); - setupCsonCache(cacheDir); - setupSourceMapCache(cacheDir); - setupBabel(cacheDir); - setupTypeScript(cacheDir); - - require(loadSettings.bootstrapScript); - require('ipc').sendChannel('window-command', 'window:loaded'); + if (loadSettings.profileStartup) { + profileStartup(cacheDir, loadSettings); + } else { + setupWindow(cacheDir, loadSettings); + } if (global.atom) { global.atom.loadTime = Date.now() - startTime; console.log('Window load time: ' + global.atom.getWindowLoadTime() + 'ms'); } } catch (error) { - var currentWindow = require('remote').getCurrentWindow(); - currentWindow.setSize(800, 600); - currentWindow.center(); - currentWindow.show(); - currentWindow.openDevTools(); - console.error(error.stack || error); + handleSetupError(error); } } +var handleSetupError = function(error) { + var currentWindow = require('remote').getCurrentWindow(); + currentWindow.setSize(800, 600); + currentWindow.center(); + currentWindow.show(); + currentWindow.openDevTools(); + console.error(error.stack || error); +} + +var setupWindow = function(cacheDir, loadSettings) { + setupCoffeeCache(cacheDir); + + ModuleCache = require('../src/module-cache'); + ModuleCache.register(loadSettings); + ModuleCache.add(loadSettings.resourcePath); + + require('grim').includeDeprecatedAPIs = !loadSettings.apiPreviewMode; + + // Start the crash reporter before anything else. + require('crash-reporter').start({ + productName: 'Atom', + companyName: 'GitHub', + // By explicitly passing the app version here, we could save the call + // of "require('remote').require('app').getVersion()". + extra: {_version: loadSettings.appVersion} + }); + + setupVmCompatibility(); + setupCsonCache(cacheDir); + setupSourceMapCache(cacheDir); + setupBabel(cacheDir); + setupTypeScript(cacheDir); + + require(loadSettings.bootstrapScript); + require('ipc').sendChannel('window-command', 'window:loaded'); +} + var setupCoffeeCache = function(cacheDir) { var CoffeeCache = require('coffee-cash'); CoffeeCache.setCacheDirectory(path.join(cacheDir, 'coffee')); @@ -121,3 +133,21 @@ var setupVmCompatibility = function() { if (!vm.Script.createContext) vm.Script.createContext = vm.createContext; } + +var profileStartup = function(cacheDir, loadSettings) { + var currentWindow = require('remote').getCurrentWindow(); + currentWindow.openDevTools(); + currentWindow.once('devtools-opened', function() { + setTimeout(function() { + console.profile('startup'); + try { + setupWindow(cacheDir, loadSettings); + } catch (error) { + handleSetupError(error); + } finally { + console.profileEnd('startup'); + console.log("Switch to the Profiles tab to view the startup profile") + } + }, 100); + }); +} From b5839a8960c28a03ad965e6ca0d8bf9f73d9cd72 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 27 Apr 2015 18:19:25 -0700 Subject: [PATCH 5/6] Add created to profile message --- static/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/static/index.js b/static/index.js index c0d031d3d..e7971d9b9 100644 --- a/static/index.js +++ b/static/index.js @@ -146,7 +146,7 @@ var profileStartup = function(cacheDir, loadSettings) { handleSetupError(error); } finally { console.profileEnd('startup'); - console.log("Switch to the Profiles tab to view the startup profile") + console.log("Switch to the Profiles tab to view the created startup profile") } }, 100); }); From 313c8a73ce1cecf8ee852b8d4100a553c5065cfd Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 27 Apr 2015 18:28:29 -0700 Subject: [PATCH 6/6] Only pen dev tools when not already open --- static/index.js | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/static/index.js b/static/index.js index e7971d9b9..140dee8f3 100644 --- a/static/index.js +++ b/static/index.js @@ -135,19 +135,25 @@ var setupVmCompatibility = function() { } var profileStartup = function(cacheDir, loadSettings) { + var profile = function() { + console.profile('startup'); + try { + setupWindow(cacheDir, loadSettings); + } catch (error) { + handleSetupError(error); + } finally { + console.profileEnd('startup'); + console.log("Switch to the Profiles tab to view the created startup profile") + } + }; + var currentWindow = require('remote').getCurrentWindow(); - currentWindow.openDevTools(); - currentWindow.once('devtools-opened', function() { - setTimeout(function() { - console.profile('startup'); - try { - setupWindow(cacheDir, loadSettings); - } catch (error) { - handleSetupError(error); - } finally { - console.profileEnd('startup'); - console.log("Switch to the Profiles tab to view the created startup profile") - } - }, 100); - }); + if (currentWindow.devToolsWebContents) { + profile(); + } else { + currentWindow.openDevTools(); + currentWindow.once('devtools-opened', function() { + setTimeout(profile, 100); + }); + } }