From 2c277712ad259ee403bd9752c3d50ca6d3b1422a Mon Sep 17 00:00:00 2001 From: Vishwas Shashidhar Date: Tue, 27 Nov 2018 16:56:08 -0800 Subject: [PATCH] ELECTRON-907: add logging for system and app information --- js/config.js | 1 - js/main.js | 30 +++++++++--------- js/stats.js | 82 +++++++++++++++++++++++++++++++++++++++++++++++++ js/windowMgr.js | 7 +---- 4 files changed, 98 insertions(+), 22 deletions(-) create mode 100644 js/stats.js diff --git a/js/config.js b/js/config.js index 4a50b4ca..f1205c8d 100644 --- a/js/config.js +++ b/js/config.js @@ -103,7 +103,6 @@ function readUserConfig(customConfigPath) { try { // data is the contents of the text file we just read userConfig = JSON.parse(data); - log.send(logLevels.INFO, `user config data is ${JSON.stringify(userConfig)}`); resolve(userConfig); } catch (e) { log.send(logLevels.INFO, `cannot parse user config data ${data}, error is ${e}`); diff --git a/js/main.js b/js/main.js index 34efca59..d370e89c 100644 --- a/js/main.js +++ b/js/main.js @@ -8,26 +8,25 @@ const nodeURL = require('url'); const shellPath = require('shell-path'); const urlParser = require('url'); const nodePath = require('path'); -const compareSemVersions = require('./utils/compareSemVersions.js'); -const { version, clientVersion, buildNumber } = require('../package.json'); +require('electron-dl')(); -// Local Dependencies -const { - getConfigField, - readConfigFileSync, - updateUserConfigOnLaunch, - getUserConfigField -} = require('./config.js'); -const { setCheckboxValues } = require('./menus/menuTemplate.js'); -const { isMac, isDevEnv } = require('./utils/misc.js'); -const protocolHandler = require('./protocolHandler'); -const getCmdLineArg = require('./utils/getCmdLineArg.js'); +const { version, clientVersion, buildNumber } = require('../package.json'); const log = require('./log.js'); const logLevels = require('./enums/logLevels.js'); + +log.send(logLevels.INFO, `-----------------Starting the app-----------------`); + +// Local Dependencies +require('./stats'); +const { getConfigField, readConfigFileSync, updateUserConfigOnLaunch, getUserConfigField } = require('./config.js'); +const protocolHandler = require('./protocolHandler'); +const { setCheckboxValues } = require('./menus/menuTemplate.js'); const autoLaunch = require('./autoLaunch'); const { handleCacheFailureCheckOnStartup, handleCacheFailureCheckOnExit} = require('./cacheHandler'); -require('electron-dl')(); +const compareSemVersions = require('./utils/compareSemVersions.js'); +const { isMac, isDevEnv } = require('./utils/misc.js'); +const getCmdLineArg = require('./utils/getCmdLineArg.js'); //setting the env path child_process issue https://github.com/electron/electron/issues/7688 shellPath() @@ -105,7 +104,7 @@ function setChromeFlags() { let config = readConfigFileSync(); // If we cannot find any config, just skip setting any flags - if (config && config !== null && config.customFlags) { + if (config && config.customFlags) { if (config.customFlags.authServerWhitelist && config.customFlags.authServerWhitelist !== "") { log.send(logLevels.INFO, 'Setting auth server whitelist flag'); @@ -212,6 +211,7 @@ app.on('window-all-closed', function () { app.on('quit', function () { handleCacheFailureCheckOnExit(); + log.send(logLevels.INFO, `-----------------Quitting the app-----------------`); }); /** diff --git a/js/stats.js b/js/stats.js new file mode 100644 index 00000000..ff45e5ff --- /dev/null +++ b/js/stats.js @@ -0,0 +1,82 @@ +const os = require('os'); +const { app } = require('electron'); + +const config = require('./config'); + +const log = require('./log.js'); +const logLevels = require('./enums/logLevels.js'); + +const MB_IN_BYTES = 1048576; + +const getSystemStats = () => { + log.send(logLevels.INFO, `-----------------Gathering system information-----------------`); + log.send(logLevels.INFO, `Network Info -> ${JSON.stringify(os.networkInterfaces())}`); + log.send(logLevels.INFO, `CPU Info -> ${JSON.stringify(os.cpus())}`); + log.send(logLevels.INFO, `Operating System -> ${JSON.stringify(os.type())}`); + log.send(logLevels.INFO, `Platform -> ${JSON.stringify(os.platform())}`); + log.send(logLevels.INFO, `Architecture -> ${JSON.stringify(os.arch())}`); + log.send(logLevels.INFO, `Hostname -> ${JSON.stringify(os.hostname())}`); + log.send(logLevels.INFO, `Temp Directory -> ${JSON.stringify(os.tmpdir())}`); + log.send(logLevels.INFO, `Home Directory -> ${JSON.stringify(os.homedir())}`); + log.send(logLevels.INFO, `Total Memory (MB) -> ${JSON.stringify(os.totalmem() / MB_IN_BYTES)}`); + log.send(logLevels.INFO, `Free Memory (MB) -> ${JSON.stringify(os.freemem() / MB_IN_BYTES)}`); + log.send(logLevels.INFO, `Load Average -> ${JSON.stringify(os.loadavg())}`); + log.send(logLevels.INFO, `Uptime -> ${JSON.stringify(os.uptime())}`); + log.send(logLevels.INFO, `User Info (OS Returned) -> ${JSON.stringify(os.userInfo())}`); +}; + +const getGPUStats = () => { + log.send(logLevels.INFO, `-----------------Gathering GPU information-----------------`); + log.send(logLevels.INFO, `GPU Feature Status -> ${JSON.stringify(app.getGPUFeatureStatus())}`); +}; + +const getPodStats = () => { + const fields = ['url', 'minimizeOnClose', 'launchOnStartup', 'alwaysOnTop', 'bringToFront', 'whitelistUrl', 'isCustomTitleBar', 'memoryRefresh', 'devToolsEnabled', 'ctWhitelist', 'notificationSettings', 'crashReporter', 'customFlags', 'permissions', 'autoLaunchPath']; + config.getMultipleConfigField(fields) + .then((data) => { + log.send(logLevels.INFO, `-----------------Gathering POD & App information-----------------`); + log.send(logLevels.INFO, `Is app packaged? ${app.isPackaged}`); + for (let field in data) { + if (Object.prototype.hasOwnProperty.call(data, field)) { + log.send(logLevels.INFO, `${field} -> ${JSON.stringify(data[field])}`); + } + } + }); +}; + +const getAppMetrics = () => { + log.send(logLevels.INFO, `-----------------Gathering App Metrics-----------------`); + const metrics = app.getAppMetrics(); + metrics.forEach((metric) => { + log.send(logLevels.INFO, `PID -> ${metric.pid}, Type -> ${metric.type}, CPU Usage -> ${JSON.stringify(metric.cpu)}`); + }); +}; + +const logAppEvents = () => { + + const events = [ + 'will-finish-launching', 'ready', 'window-all-closed', 'before-quit', 'will-quit', 'quit', + 'open-file', 'open-url', 'activate', 'browser-window-blur', 'browser-window-focus', + 'browser-window-created', 'web-contents-created', 'certificate-error', 'login', 'gpu-process-crashed', + 'accessibility-support-changed', 'session-created', 'second-instance' + ]; + + events.forEach((appEvent) => { + app.on(appEvent, () => { + log.send(logLevels.INFO, `Event Occurred: ${appEvent}`) + }); + }); +}; + +getSystemStats(); +getGPUStats(); +getPodStats(); +getAppMetrics(); +logAppEvents(); + +module.exports = { + getSystemStats: getSystemStats, + getGPUStats: getGPUStats, + getPodStats: getPodStats, + getAppMetrics: getAppMetrics +}; \ No newline at end of file diff --git a/js/windowMgr.js b/js/windowMgr.js index 93498b63..659fc6c5 100644 --- a/js/windowMgr.js +++ b/js/windowMgr.js @@ -136,19 +136,14 @@ function doCreateMainWindow(initialUrl, initialBounds, isCustomTitleBar) { isCustomTitleBarEnabled = typeof isCustomTitleBar === 'boolean' && isCustomTitleBar && isWindowsOS; - log.send(logLevels.INFO, `we are configuring a custom title bar for windows -> ${isCustomTitleBarEnabled}`); ctWhitelist = config && config.ctWhitelist; - log.send(logLevels.INFO, `we are configuring certificate transparency whitelist for the domains -> ${ctWhitelist}`); log.send(logLevels.INFO, `creating main window for ${url}`); - if (config && config !== null && config.customFlags) { - - log.send(logLevels.INFO, 'Chrome flags config found!'); + if (config && config.customFlags) { if (config.customFlags.authServerWhitelist && config.customFlags.authServerWhitelist !== "") { - log.send(logLevels.INFO, 'setting ntlm domains'); electronSession.defaultSession.allowNTLMCredentialsForDomains(config.customFlags.authServerWhitelist); }