From 4737a9135f79d4f0fd48259594bf5452249257a4 Mon Sep 17 00:00:00 2001 From: Kiran Niranjan Date: Thu, 25 Oct 2018 09:50:54 +0530 Subject: [PATCH] ELECTRON-870 - Remove process.getCPUUsage from renderer process due to sandbox --- js/mainApiMgr.js | 4 ++-- js/memoryMonitor.js | 11 +++++++---- js/preload/preloadMain.js | 4 +--- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/js/mainApiMgr.js b/js/mainApiMgr.js index 27e19077..b5811846 100644 --- a/js/mainApiMgr.js +++ b/js/mainApiMgr.js @@ -153,10 +153,10 @@ electron.ipcMain.on(apiName, (event, arg) => { } case apiCmds.optimizeMemoryConsumption: if (typeof arg.memory === 'object' - && typeof arg.cpuUsage === 'object' && typeof arg.memory.workingSetSize === 'number' && typeof arg.activeRequests === 'number') { - setPreloadMemoryInfo(arg.memory, arg.cpuUsage, arg.activeRequests); + log.send(logLevels.INFO, 'Received memory info from renderer'); + setPreloadMemoryInfo(arg.memory, arg.activeRequests); } break; case apiCmds.optimizeMemoryRegister: diff --git a/js/memoryMonitor.js b/js/memoryMonitor.js index e4e48b52..e1e1f190 100644 --- a/js/memoryMonitor.js +++ b/js/memoryMonitor.js @@ -9,6 +9,7 @@ const { getConfigField } = require('./config'); const maxMemory = 800; const defaultInterval = 30 * 1000; +const defaultIntervalSymLock = 10 * 1000; const memoryRefreshThreshold = 60 * 60 * 1000; const cpuUsageThreshold = 5; @@ -84,7 +85,8 @@ function optimizeMemory() { } }); } else { - log.send(logLevels.INFO, `Not Reloading the app as + log.send(logLevels.INFO, `Not Reloading the app as + application was refreshed less than a hour ago? ${canReload ? 'no' : 'yes'} memory consumption was ${memoryConsumed} CPU usage percentage was ${preloadMemory.cpuUsage.percentCPUUsage} user was in a meeting? ${isInMeeting} @@ -105,11 +107,11 @@ function setIsInMeeting(meetingStatus) { * Sets preload memory info and calls optimize memory func * * @param memoryInfo - memory consumption of the preload main script - * @param cpuUsage - CPU usage of the preload main script * @param activeRequests - pending active network requests on the client */ -function setPreloadMemoryInfo(memoryInfo, cpuUsage, activeRequests) { +function setPreloadMemoryInfo(memoryInfo, activeRequests) { log.send(logLevels.INFO, 'Memory info received from preload process now running optimize memory logic'); + const cpuUsage = process.getCPUUsage(); preloadMemory = { memoryInfo, cpuUsage, activeRequests }; optimizeMemory(); } @@ -119,6 +121,7 @@ function setPreloadMemoryInfo(memoryInfo, cpuUsage, activeRequests) { * and waits for 30s to optimize memory */ eventEmitter.on('appMinimized', () => { + log.send(logLevels.INFO, 'Application was minimised'); appMinimizedTimer = setTimeout(() => { const mainWindow = getMainWindow(); if (mainWindow && !mainWindow.isDestroyed() && mainWindow.isMinimized()) { @@ -151,7 +154,7 @@ eventEmitter.on('sys-locked', () => { powerMonitorTimer = setTimeout(() => { log.send(logLevels.INFO, 'System screen was locked for more than 30s so calling requestMemoryInfo'); requestMemoryInfo(); - }, defaultInterval); + }, defaultIntervalSymLock); }); /** diff --git a/js/preload/preloadMain.js b/js/preload/preloadMain.js index 70d3f49a..d20a7b83 100644 --- a/js/preload/preloadMain.js +++ b/js/preload/preloadMain.js @@ -505,12 +505,10 @@ function createAPI() { local.ipcRenderer.on('memory-info-request', () => { if (window.name === 'main') { const memory = process.getProcessMemoryInfo(); - const cpuUsage = process.getCPUUsage(); - const activeRequests = local.activeRequests(); + const activeRequests = typeof local.activeRequests === 'function' ? local.activeRequests() : 0; local.ipcRenderer.send(apiName, { cmd: apiCmds.optimizeMemoryConsumption, memory, - cpuUsage, activeRequests, }); }