From fc9823edc770e9a209e8947519a588a28ad3dc31 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Fri, 6 Jan 2023 13:09:36 +0530 Subject: [PATCH 01/19] update UI --- ui | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui b/ui index a955ae39f..86a7f1cda 160000 --- a/ui +++ b/ui @@ -1 +1 @@ -Subproject commit a955ae39fa97232131682ad72d866bf3155a0906 +Subproject commit 86a7f1cdab5c3a9a2cfbd0daecb9f7e1dd06660e From d71d65073f6b5d3aa0d5e3794e131502a18fcd79 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Fri, 6 Jan 2023 13:09:57 +0530 Subject: [PATCH 02/19] rename constant --- src/utils/processStats.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils/processStats.ts b/src/utils/processStats.ts index 2b8d8f054..6f3baaa30 100644 --- a/src/utils/processStats.ts +++ b/src/utils/processStats.ts @@ -1,7 +1,7 @@ import ElectronLog from 'electron-log'; import { webFrame } from 'electron/renderer'; -const FIVE_MINUTES_IN_MICROSECONDS = 30 * 1000; +const LOGGING_INTERVAL_IN_MICROSECONDS = 1 * 1000; async function logMainProcessStats() { const systemMemoryInfo = process.getSystemMemoryInfo(); @@ -31,9 +31,9 @@ async function logRendererProcessStats() { } export function setupMainProcessStatsLogger() { - setInterval(logMainProcessStats, FIVE_MINUTES_IN_MICROSECONDS); + setInterval(logMainProcessStats, LOGGING_INTERVAL_IN_MICROSECONDS); } export function setupRendererProcessStatsLogger() { - setInterval(logRendererProcessStats, FIVE_MINUTES_IN_MICROSECONDS); + setInterval(logRendererProcessStats, LOGGING_INTERVAL_IN_MICROSECONDS); } From a66d720dc2b461fe753093f15d548f62218b4f14 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Fri, 6 Jan 2023 13:18:47 +0530 Subject: [PATCH 03/19] convert process stats to human readable format value --- src/utils/processStats.ts | 58 +++++++++++++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 8 deletions(-) diff --git a/src/utils/processStats.ts b/src/utils/processStats.ts index 6f3baaa30..1a4dd7806 100644 --- a/src/utils/processStats.ts +++ b/src/utils/processStats.ts @@ -4,28 +4,31 @@ import { webFrame } from 'electron/renderer'; const LOGGING_INTERVAL_IN_MICROSECONDS = 1 * 1000; async function logMainProcessStats() { - const systemMemoryInfo = process.getSystemMemoryInfo(); - const cpuUsage = process.getCPUUsage(); const processMemoryInfo = await process.getProcessMemoryInfo(); + const normalizedProcessMemoryInfo = await getNormalizedProcessMemoryInfo( + processMemoryInfo + ); + const systemMemoryInfo = process.getSystemMemoryInfo(); + const normalizedSystemMemoryInfo = + getNormalizedSystemMemoryInfo(systemMemoryInfo); + const cpuUsage = process.getCPUUsage(); const heapStatistics = process.getHeapStatistics(); ElectronLog.log('main process stats', { - systemMemoryInfo, - cpuUsage, - processMemoryInfo, + processMemoryInfo: normalizedProcessMemoryInfo, + systemMemoryInfo: normalizedSystemMemoryInfo, heapStatistics, + cpuUsage, }); } async function logRendererProcessStats() { - const blinkMemoryInfo = process.getBlinkMemoryInfo(); + const blinkMemoryInfo = getNormalizedBlinkMemoryInfo(); const heapStatistics = process.getHeapStatistics(); - const processMemoryInfo = process.getProcessMemoryInfo(); const webFrameResourceUsage = webFrame.getResourceUsage(); ElectronLog.log('renderer process stats', { blinkMemoryInfo, heapStatistics, - processMemoryInfo, webFrameResourceUsage, }); } @@ -37,3 +40,42 @@ export function setupMainProcessStatsLogger() { export function setupRendererProcessStatsLogger() { setInterval(logRendererProcessStats, LOGGING_INTERVAL_IN_MICROSECONDS); } + +const getNormalizedProcessMemoryInfo = async ( + processMemoryInfo: Electron.ProcessMemoryInfo +) => { + return { + residentSet: convertBytesToHumanReadable(processMemoryInfo.residentSet), + private: convertBytesToHumanReadable(processMemoryInfo.private), + shared: convertBytesToHumanReadable(processMemoryInfo.shared), + }; +}; + +const getNormalizedSystemMemoryInfo = ( + systemMemoryInfo: Electron.SystemMemoryInfo +) => { + return { + total: convertBytesToHumanReadable(systemMemoryInfo.total), + free: convertBytesToHumanReadable(systemMemoryInfo.free), + swapTotal: convertBytesToHumanReadable(systemMemoryInfo.swapTotal), + swapFree: convertBytesToHumanReadable(systemMemoryInfo.swapFree), + }; +}; + +const getNormalizedBlinkMemoryInfo = () => { + const blinkMemoryInfo = process.getBlinkMemoryInfo(); + return { + allocated: convertBytesToHumanReadable(blinkMemoryInfo.allocated), + total: convertBytesToHumanReadable(blinkMemoryInfo.total), + }; +}; + +function convertBytesToHumanReadable(bytes: number, precision = 2): string { + if (bytes === 0) { + return '0 MB'; + } + + const i = Math.floor(Math.log(bytes) / Math.log(1024)); + const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; + return (bytes / Math.pow(1024, i)).toFixed(precision) + ' ' + sizes[i]; +} From 54fc0705cdc4db66eda24f6529801134ddfedce0 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Fri, 6 Jan 2023 14:58:23 +0530 Subject: [PATCH 04/19] fix units and add spike logger --- src/utils/processStats.ts | 58 +++++++++++++++++++++++++++++++++------ 1 file changed, 49 insertions(+), 9 deletions(-) diff --git a/src/utils/processStats.ts b/src/utils/processStats.ts index 1a4dd7806..43ded4976 100644 --- a/src/utils/processStats.ts +++ b/src/utils/processStats.ts @@ -1,7 +1,14 @@ import ElectronLog from 'electron-log'; import { webFrame } from 'electron/renderer'; +import { isPlatform } from './main'; -const LOGGING_INTERVAL_IN_MICROSECONDS = 1 * 1000; +const LOGGING_INTERVAL_IN_MICROSECONDS = 30 * 1000; // 30 seconds + +const SPIKE_DETECTION_INTERVAL_IN_MICROSECONDS = 1 * 1000; // 1 seconds + +const HIGH_MEMORY_USAGE_THRESHOLD_IN_KILOBYTES = 1 * 1024 * 1024; // 1 GB + +const LOW_MEMORY_FREE_THRESHOLD_IN_KILOBYTES = 1 * 1024 * 1024; // 1 GB async function logMainProcessStats() { const processMemoryInfo = await process.getProcessMemoryInfo(); @@ -22,6 +29,30 @@ async function logMainProcessStats() { }); } +async function logSpikeMemoryUsage() { + const processMemoryInfo = await process.getProcessMemoryInfo(); + const systemMemoryInfo = process.getSystemMemoryInfo(); + if ( + processMemoryInfo.residentSet > + HIGH_MEMORY_USAGE_THRESHOLD_IN_KILOBYTES || + systemMemoryInfo.free < LOW_MEMORY_FREE_THRESHOLD_IN_KILOBYTES + ) { + const normalizedProcessMemoryInfo = + await getNormalizedProcessMemoryInfo(processMemoryInfo); + const normalizedSystemMemoryInfo = + getNormalizedSystemMemoryInfo(systemMemoryInfo); + const cpuUsage = process.getCPUUsage(); + const heapStatistics = process.getHeapStatistics(); + + ElectronLog.log('main process stats', { + processMemoryInfo: normalizedProcessMemoryInfo, + systemMemoryInfo: normalizedSystemMemoryInfo, + heapStatistics, + cpuUsage, + }); + } +} + async function logRendererProcessStats() { const blinkMemoryInfo = getNormalizedBlinkMemoryInfo(); const heapStatistics = process.getHeapStatistics(); @@ -34,6 +65,7 @@ async function logRendererProcessStats() { } export function setupMainProcessStatsLogger() { + setInterval(logSpikeMemoryUsage, SPIKE_DETECTION_INTERVAL_IN_MICROSECONDS); setInterval(logMainProcessStats, LOGGING_INTERVAL_IN_MICROSECONDS); } @@ -45,9 +77,11 @@ const getNormalizedProcessMemoryInfo = async ( processMemoryInfo: Electron.ProcessMemoryInfo ) => { return { - residentSet: convertBytesToHumanReadable(processMemoryInfo.residentSet), - private: convertBytesToHumanReadable(processMemoryInfo.private), - shared: convertBytesToHumanReadable(processMemoryInfo.shared), + residentSet: !isPlatform('mac') + ? convertBytesToHumanReadable(processMemoryInfo.residentSet * 1024) + : 0, + private: convertBytesToHumanReadable(processMemoryInfo.private * 10124), + shared: convertBytesToHumanReadable(processMemoryInfo.shared * 1024), }; }; @@ -55,17 +89,23 @@ const getNormalizedSystemMemoryInfo = ( systemMemoryInfo: Electron.SystemMemoryInfo ) => { return { - total: convertBytesToHumanReadable(systemMemoryInfo.total), - free: convertBytesToHumanReadable(systemMemoryInfo.free), - swapTotal: convertBytesToHumanReadable(systemMemoryInfo.swapTotal), - swapFree: convertBytesToHumanReadable(systemMemoryInfo.swapFree), + total: convertBytesToHumanReadable(systemMemoryInfo.total * 1024), + free: convertBytesToHumanReadable(systemMemoryInfo.free * 1024), + swapTotal: !isPlatform('mac') + ? convertBytesToHumanReadable(systemMemoryInfo.swapTotal * 1024) + : 0, + swapFree: !isPlatform('mac') + ? convertBytesToHumanReadable(systemMemoryInfo.swapFree * 1024) + : 0, }; }; const getNormalizedBlinkMemoryInfo = () => { const blinkMemoryInfo = process.getBlinkMemoryInfo(); return { - allocated: convertBytesToHumanReadable(blinkMemoryInfo.allocated), + allocated: convertBytesToHumanReadable( + blinkMemoryInfo.allocated * 1024 + ), total: convertBytesToHumanReadable(blinkMemoryInfo.total), }; }; From d18462535eb5da6b99608651e6451cd1ba09ee0b Mon Sep 17 00:00:00 2001 From: Abhinav Date: Fri, 6 Jan 2023 17:01:30 +0530 Subject: [PATCH 05/19] no need of platform check --- src/utils/processStats.ts | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/utils/processStats.ts b/src/utils/processStats.ts index 43ded4976..f9bb273a9 100644 --- a/src/utils/processStats.ts +++ b/src/utils/processStats.ts @@ -1,6 +1,5 @@ import ElectronLog from 'electron-log'; import { webFrame } from 'electron/renderer'; -import { isPlatform } from './main'; const LOGGING_INTERVAL_IN_MICROSECONDS = 30 * 1000; // 30 seconds @@ -77,9 +76,9 @@ const getNormalizedProcessMemoryInfo = async ( processMemoryInfo: Electron.ProcessMemoryInfo ) => { return { - residentSet: !isPlatform('mac') - ? convertBytesToHumanReadable(processMemoryInfo.residentSet * 1024) - : 0, + residentSet: convertBytesToHumanReadable( + processMemoryInfo.residentSet * 1024 + ), private: convertBytesToHumanReadable(processMemoryInfo.private * 10124), shared: convertBytesToHumanReadable(processMemoryInfo.shared * 1024), }; @@ -91,12 +90,10 @@ const getNormalizedSystemMemoryInfo = ( return { total: convertBytesToHumanReadable(systemMemoryInfo.total * 1024), free: convertBytesToHumanReadable(systemMemoryInfo.free * 1024), - swapTotal: !isPlatform('mac') - ? convertBytesToHumanReadable(systemMemoryInfo.swapTotal * 1024) - : 0, - swapFree: !isPlatform('mac') - ? convertBytesToHumanReadable(systemMemoryInfo.swapFree * 1024) - : 0, + swapTotal: convertBytesToHumanReadable( + systemMemoryInfo.swapTotal * 1024 + ), + swapFree: convertBytesToHumanReadable(systemMemoryInfo.swapFree * 1024), }; }; From 4c36a3b80833938a0d98e2397a4f1600205eb0eb Mon Sep 17 00:00:00 2001 From: Abhinav Date: Fri, 6 Jan 2023 21:56:27 +0530 Subject: [PATCH 06/19] prevent nan --- src/utils/processStats.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/processStats.ts b/src/utils/processStats.ts index f9bb273a9..2361e7036 100644 --- a/src/utils/processStats.ts +++ b/src/utils/processStats.ts @@ -108,7 +108,7 @@ const getNormalizedBlinkMemoryInfo = () => { }; function convertBytesToHumanReadable(bytes: number, precision = 2): string { - if (bytes === 0) { + if (bytes === 0 || isNaN(bytes)) { return '0 MB'; } From 7fabf2c5c91e75b1ea38d08db0e9ec4964061abd Mon Sep 17 00:00:00 2001 From: Abhinav Date: Fri, 6 Jan 2023 22:40:20 +0530 Subject: [PATCH 07/19] add getNormalizedHeapStatistics util --- src/utils/processStats.ts | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/utils/processStats.ts b/src/utils/processStats.ts index 2361e7036..2f0dc2ce0 100644 --- a/src/utils/processStats.ts +++ b/src/utils/processStats.ts @@ -18,7 +18,7 @@ async function logMainProcessStats() { const normalizedSystemMemoryInfo = getNormalizedSystemMemoryInfo(systemMemoryInfo); const cpuUsage = process.getCPUUsage(); - const heapStatistics = process.getHeapStatistics(); + const heapStatistics = getNormalizedHeapStatistics(); ElectronLog.log('main process stats', { processMemoryInfo: normalizedProcessMemoryInfo, @@ -41,7 +41,7 @@ async function logSpikeMemoryUsage() { const normalizedSystemMemoryInfo = getNormalizedSystemMemoryInfo(systemMemoryInfo); const cpuUsage = process.getCPUUsage(); - const heapStatistics = process.getHeapStatistics(); + const heapStatistics = getNormalizedHeapStatistics(); ElectronLog.log('main process stats', { processMemoryInfo: normalizedProcessMemoryInfo, @@ -107,6 +107,38 @@ const getNormalizedBlinkMemoryInfo = () => { }; }; +const getNormalizedHeapStatistics = () => { + const heapStatistics = process.getHeapStatistics(); + return { + totalHeapSize: convertBytesToHumanReadable( + heapStatistics.totalHeapSize * 1024 + ), + totalHeapSizeExecutable: convertBytesToHumanReadable( + heapStatistics.totalHeapSizeExecutable * 1024 + ), + totalPhysicalSize: convertBytesToHumanReadable( + heapStatistics.totalPhysicalSize * 1024 + ), + totalAvailableSize: convertBytesToHumanReadable( + heapStatistics.totalAvailableSize * 1024 + ), + usedHeapSize: convertBytesToHumanReadable( + heapStatistics.usedHeapSize * 1024 + ), + + heapSizeLimit: convertBytesToHumanReadable( + heapStatistics.heapSizeLimit * 1024 + ), + mallocedMemory: convertBytesToHumanReadable( + heapStatistics.mallocedMemory * 1024 + ), + peakMallocedMemory: convertBytesToHumanReadable( + heapStatistics.peakMallocedMemory * 1024 + ), + doesZapGarbage: heapStatistics.doesZapGarbage, + }; +}; + function convertBytesToHumanReadable(bytes: number, precision = 2): string { if (bytes === 0 || isNaN(bytes)) { return '0 MB'; From ae8326a773401e583fb4f9e62eb5225f0ad9fb5f Mon Sep 17 00:00:00 2001 From: Abhinav Date: Fri, 6 Jan 2023 22:41:33 +0530 Subject: [PATCH 08/19] remove getSystemMemoryInfo as free memory reported is incorrect --- src/utils/processStats.ts | 27 +-------------------------- 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/src/utils/processStats.ts b/src/utils/processStats.ts index 2f0dc2ce0..c9b5eaa68 100644 --- a/src/utils/processStats.ts +++ b/src/utils/processStats.ts @@ -7,22 +7,16 @@ const SPIKE_DETECTION_INTERVAL_IN_MICROSECONDS = 1 * 1000; // 1 seconds const HIGH_MEMORY_USAGE_THRESHOLD_IN_KILOBYTES = 1 * 1024 * 1024; // 1 GB -const LOW_MEMORY_FREE_THRESHOLD_IN_KILOBYTES = 1 * 1024 * 1024; // 1 GB - async function logMainProcessStats() { const processMemoryInfo = await process.getProcessMemoryInfo(); const normalizedProcessMemoryInfo = await getNormalizedProcessMemoryInfo( processMemoryInfo ); - const systemMemoryInfo = process.getSystemMemoryInfo(); - const normalizedSystemMemoryInfo = - getNormalizedSystemMemoryInfo(systemMemoryInfo); const cpuUsage = process.getCPUUsage(); const heapStatistics = getNormalizedHeapStatistics(); ElectronLog.log('main process stats', { processMemoryInfo: normalizedProcessMemoryInfo, - systemMemoryInfo: normalizedSystemMemoryInfo, heapStatistics, cpuUsage, }); @@ -30,22 +24,16 @@ async function logMainProcessStats() { async function logSpikeMemoryUsage() { const processMemoryInfo = await process.getProcessMemoryInfo(); - const systemMemoryInfo = process.getSystemMemoryInfo(); if ( - processMemoryInfo.residentSet > - HIGH_MEMORY_USAGE_THRESHOLD_IN_KILOBYTES || - systemMemoryInfo.free < LOW_MEMORY_FREE_THRESHOLD_IN_KILOBYTES + processMemoryInfo.residentSet > HIGH_MEMORY_USAGE_THRESHOLD_IN_KILOBYTES ) { const normalizedProcessMemoryInfo = await getNormalizedProcessMemoryInfo(processMemoryInfo); - const normalizedSystemMemoryInfo = - getNormalizedSystemMemoryInfo(systemMemoryInfo); const cpuUsage = process.getCPUUsage(); const heapStatistics = getNormalizedHeapStatistics(); ElectronLog.log('main process stats', { processMemoryInfo: normalizedProcessMemoryInfo, - systemMemoryInfo: normalizedSystemMemoryInfo, heapStatistics, cpuUsage, }); @@ -84,19 +72,6 @@ const getNormalizedProcessMemoryInfo = async ( }; }; -const getNormalizedSystemMemoryInfo = ( - systemMemoryInfo: Electron.SystemMemoryInfo -) => { - return { - total: convertBytesToHumanReadable(systemMemoryInfo.total * 1024), - free: convertBytesToHumanReadable(systemMemoryInfo.free * 1024), - swapTotal: convertBytesToHumanReadable( - systemMemoryInfo.swapTotal * 1024 - ), - swapFree: convertBytesToHumanReadable(systemMemoryInfo.swapFree * 1024), - }; -}; - const getNormalizedBlinkMemoryInfo = () => { const blinkMemoryInfo = process.getBlinkMemoryInfo(); return { From dd7081478fd0283a727379438defba8ee814aa34 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Fri, 6 Jan 2023 22:44:01 +0530 Subject: [PATCH 09/19] increase log size to 50MB --- src/config/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config/index.ts b/src/config/index.ts index 6b2e8a1f4..1f7b9bc71 100644 --- a/src/config/index.ts +++ b/src/config/index.ts @@ -1,7 +1,7 @@ const PROD_HOST_URL: string = 'ente://app'; const RENDERER_OUTPUT_DIR: string = './ui/out'; const LOG_FILENAME = 'ente.log'; -const MAX_LOG_SIZE = 5 * 1024 * 1024; // 5MB +const MAX_LOG_SIZE = 50 * 1024 * 1024; // 50MB const FILE_STREAM_CHUNK_SIZE: number = 4 * 1024 * 1024; From ed0568a9a413e8385a9ce5e95bfadce7b5ed40ee Mon Sep 17 00:00:00 2001 From: Abhinav Date: Fri, 6 Jan 2023 23:01:37 +0530 Subject: [PATCH 10/19] add getNormalizedWebFrameResourceUsage util --- src/utils/processStats.ts | 60 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 2 deletions(-) diff --git a/src/utils/processStats.ts b/src/utils/processStats.ts index c9b5eaa68..b138d1122 100644 --- a/src/utils/processStats.ts +++ b/src/utils/processStats.ts @@ -42,8 +42,8 @@ async function logSpikeMemoryUsage() { async function logRendererProcessStats() { const blinkMemoryInfo = getNormalizedBlinkMemoryInfo(); - const heapStatistics = process.getHeapStatistics(); - const webFrameResourceUsage = webFrame.getResourceUsage(); + const heapStatistics = getNormalizedHeapStatistics(); + const webFrameResourceUsage = getNormalizedWebFrameResourceUsage(); ElectronLog.log('renderer process stats', { blinkMemoryInfo, heapStatistics, @@ -114,6 +114,62 @@ const getNormalizedHeapStatistics = () => { }; }; +const getNormalizedWebFrameResourceUsage = () => { + const webFrameResourceUsage = webFrame.getResourceUsage(); + return { + images: { + count: webFrameResourceUsage.images.count, + size: convertBytesToHumanReadable( + webFrameResourceUsage.images.size + ), + liveSize: convertBytesToHumanReadable( + webFrameResourceUsage.images.liveSize + ), + }, + scripts: { + count: webFrameResourceUsage.scripts.count, + size: convertBytesToHumanReadable( + webFrameResourceUsage.scripts.size + ), + liveSize: convertBytesToHumanReadable( + webFrameResourceUsage.scripts.liveSize + ), + }, + cssStyleSheets: { + count: webFrameResourceUsage.cssStyleSheets.count, + size: convertBytesToHumanReadable( + webFrameResourceUsage.cssStyleSheets.size + ), + liveSize: convertBytesToHumanReadable( + webFrameResourceUsage.cssStyleSheets.liveSize + ), + }, + xslStyleSheets: { + count: webFrameResourceUsage.xslStyleSheets.count, + size: convertBytesToHumanReadable( + webFrameResourceUsage.xslStyleSheets.size + ), + liveSize: convertBytesToHumanReadable( + webFrameResourceUsage.xslStyleSheets.liveSize + ), + }, + fonts: { + count: webFrameResourceUsage.fonts.count, + size: convertBytesToHumanReadable(webFrameResourceUsage.fonts.size), + liveSize: convertBytesToHumanReadable( + webFrameResourceUsage.fonts.liveSize + ), + }, + other: { + count: webFrameResourceUsage.other.count, + size: convertBytesToHumanReadable(webFrameResourceUsage.other.size), + liveSize: convertBytesToHumanReadable( + webFrameResourceUsage.other.liveSize + ), + }, + }; +}; + function convertBytesToHumanReadable(bytes: number, precision = 2): string { if (bytes === 0 || isNaN(bytes)) { return '0 MB'; From d197e821013f8b5203737df4df6d12eeecc98528 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Tue, 10 Jan 2023 21:58:54 +0530 Subject: [PATCH 11/19] update spike detection logic --- src/utils/processStats.ts | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/utils/processStats.ts b/src/utils/processStats.ts index b138d1122..a552d7aa0 100644 --- a/src/utils/processStats.ts +++ b/src/utils/processStats.ts @@ -5,7 +5,9 @@ const LOGGING_INTERVAL_IN_MICROSECONDS = 30 * 1000; // 30 seconds const SPIKE_DETECTION_INTERVAL_IN_MICROSECONDS = 1 * 1000; // 1 seconds -const HIGH_MEMORY_USAGE_THRESHOLD_IN_KILOBYTES = 1 * 1024 * 1024; // 1 GB +const MEMORY_DIFF_IN_KILOBYTES_CONSIDERED_AS_SPIKE = 500 * 1024; // 500 MB + +let previousMemoryUsage = 0; async function logMainProcessStats() { const processMemoryInfo = await process.getProcessMemoryInfo(); @@ -24,9 +26,15 @@ async function logMainProcessStats() { async function logSpikeMemoryUsage() { const processMemoryInfo = await process.getProcessMemoryInfo(); - if ( - processMemoryInfo.residentSet > HIGH_MEMORY_USAGE_THRESHOLD_IN_KILOBYTES - ) { + const currentMemoryUsage = Math.max( + processMemoryInfo.residentSet, + processMemoryInfo.private + ); + const isSpiking = + currentMemoryUsage - previousMemoryUsage >= + MEMORY_DIFF_IN_KILOBYTES_CONSIDERED_AS_SPIKE; + + if (isSpiking) { const normalizedProcessMemoryInfo = await getNormalizedProcessMemoryInfo(processMemoryInfo); const cpuUsage = process.getCPUUsage(); @@ -38,6 +46,7 @@ async function logSpikeMemoryUsage() { cpuUsage, }); } + previousMemoryUsage = currentMemoryUsage; } async function logRendererProcessStats() { @@ -67,7 +76,7 @@ const getNormalizedProcessMemoryInfo = async ( residentSet: convertBytesToHumanReadable( processMemoryInfo.residentSet * 1024 ), - private: convertBytesToHumanReadable(processMemoryInfo.private * 10124), + private: convertBytesToHumanReadable(processMemoryInfo.private * 1024), shared: convertBytesToHumanReadable(processMemoryInfo.shared * 1024), }; }; @@ -78,7 +87,7 @@ const getNormalizedBlinkMemoryInfo = () => { allocated: convertBytesToHumanReadable( blinkMemoryInfo.allocated * 1024 ), - total: convertBytesToHumanReadable(blinkMemoryInfo.total), + total: convertBytesToHumanReadable(blinkMemoryInfo.total * 1024), }; }; From 6a47f6d7ea428905defc9f1aefe15ffbf255c86d Mon Sep 17 00:00:00 2001 From: Abhinav Date: Wed, 11 Jan 2023 11:19:56 +0530 Subject: [PATCH 12/19] log ffmpeg execution time --- src/services/ffmpeg.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/services/ffmpeg.ts b/src/services/ffmpeg.ts index d8c1853fc..7a9b4e6dc 100644 --- a/src/services/ffmpeg.ts +++ b/src/services/ffmpeg.ts @@ -39,10 +39,18 @@ export async function runFFmpegCmd( }); const escapedCmd = shellescape(cmd); log.info('running ffmpeg command', escapedCmd); + const startTime = Date.now(); await execAsync(escapedCmd); if (!existsSync(tempOutputFilePath)) { throw new Error('ffmpeg output file not found'); } + log.info( + 'ffmpeg command execution time ', + escapedCmd, + Date.now() - startTime, + 'ms' + ); + const outputFile = await readFile(tempOutputFilePath); return new Uint8Array(outputFile); } catch (e) { From 71e96df4548f98bf36a2090972950254e38a2ed9 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Wed, 11 Jan 2023 13:58:46 +0530 Subject: [PATCH 13/19] log sudden increase in memory and app using more than high limit --- src/utils/processStats.ts | 41 +++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/src/utils/processStats.ts b/src/utils/processStats.ts index a552d7aa0..a6d5241fb 100644 --- a/src/utils/processStats.ts +++ b/src/utils/processStats.ts @@ -5,9 +5,9 @@ const LOGGING_INTERVAL_IN_MICROSECONDS = 30 * 1000; // 30 seconds const SPIKE_DETECTION_INTERVAL_IN_MICROSECONDS = 1 * 1000; // 1 seconds -const MEMORY_DIFF_IN_KILOBYTES_CONSIDERED_AS_SPIKE = 500 * 1024; // 500 MB +const MEMORY_DIFF_IN_KILOBYTES_CONSIDERED_AS_SPIKE = 200 * 1024; // 200 MB -let previousMemoryUsage = 0; +const HIGH_MEMORY_USAGE_THRESHOLD_IN_KILOBYTES = 700 * 1024; // 700 MB async function logMainProcessStats() { const processMemoryInfo = await process.getProcessMemoryInfo(); @@ -24,29 +24,54 @@ async function logMainProcessStats() { }); } +let previousProcessMemoryInfo: Electron.ProcessMemoryInfo = { + private: 0, + shared: 0, + residentSet: 0, +}; + +let usingHighMemory = false; + async function logSpikeMemoryUsage() { const processMemoryInfo = await process.getProcessMemoryInfo(); const currentMemoryUsage = Math.max( processMemoryInfo.residentSet, processMemoryInfo.private ); + const previewMemoryUsage = Math.max( + previousProcessMemoryInfo.private, + previousProcessMemoryInfo.residentSet + ); const isSpiking = - currentMemoryUsage - previousMemoryUsage >= + currentMemoryUsage - previewMemoryUsage >= MEMORY_DIFF_IN_KILOBYTES_CONSIDERED_AS_SPIKE; - if (isSpiking) { - const normalizedProcessMemoryInfo = + const isHighMemoryUsage = + currentMemoryUsage >= HIGH_MEMORY_USAGE_THRESHOLD_IN_KILOBYTES; + + const shouldReport = + (isHighMemoryUsage && !usingHighMemory) || + (!isHighMemoryUsage && usingHighMemory); + + if (isSpiking || shouldReport) { + const normalizedCurrentProcessMemoryInfo = await getNormalizedProcessMemoryInfo(processMemoryInfo); + const normalizedPreviousProcessMemoryInfo = + await getNormalizedProcessMemoryInfo(previousProcessMemoryInfo); const cpuUsage = process.getCPUUsage(); const heapStatistics = getNormalizedHeapStatistics(); - ElectronLog.log('main process stats', { - processMemoryInfo: normalizedProcessMemoryInfo, + ElectronLog.log('reporting memory usage spike', { + currentProcessMemoryInfo: normalizedCurrentProcessMemoryInfo, + previousProcessMemoryInfo: normalizedPreviousProcessMemoryInfo, heapStatistics, cpuUsage, }); } - previousMemoryUsage = currentMemoryUsage; + previousProcessMemoryInfo = processMemoryInfo; + if (shouldReport) { + usingHighMemory = !usingHighMemory; + } } async function logRendererProcessStats() { From 03be62a0827964434bf51e101d2a8ca28b1523f3 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Wed, 11 Jan 2023 14:35:40 +0530 Subject: [PATCH 14/19] add renderer spike logging --- src/utils/processStats.ts | 93 +++++++++++++++++++++++++++++++++------ 1 file changed, 80 insertions(+), 13 deletions(-) diff --git a/src/utils/processStats.ts b/src/utils/processStats.ts index a6d5241fb..18c16590b 100644 --- a/src/utils/processStats.ts +++ b/src/utils/processStats.ts @@ -5,20 +5,25 @@ const LOGGING_INTERVAL_IN_MICROSECONDS = 30 * 1000; // 30 seconds const SPIKE_DETECTION_INTERVAL_IN_MICROSECONDS = 1 * 1000; // 1 seconds -const MEMORY_DIFF_IN_KILOBYTES_CONSIDERED_AS_SPIKE = 200 * 1024; // 200 MB +const MEMORY_DIFF_IN_KILOBYTES_CONSIDERED_AS_SPIKE = 10 * 1024; // 10 MB -const HIGH_MEMORY_USAGE_THRESHOLD_IN_KILOBYTES = 700 * 1024; // 700 MB +const HIGH_MEMORY_USAGE_THRESHOLD_IN_KILOBYTES = 200 * 1024; // 200 MB + +const HEAP_SIZE_DIFF_IN_KILOBYTES_CONSIDERED_AS_SPIKE = 200 * 1024; // 200 MB + +const HIGH_HEAP_USAGE_THRESHOLD_IN_KILOBYTES = 700 * 1024; // 700 MB async function logMainProcessStats() { - const processMemoryInfo = await process.getProcessMemoryInfo(); - const normalizedProcessMemoryInfo = await getNormalizedProcessMemoryInfo( - processMemoryInfo + const processMemoryInfo = await getNormalizedProcessMemoryInfo( + await process.getProcessMemoryInfo() ); const cpuUsage = process.getCPUUsage(); - const heapStatistics = getNormalizedHeapStatistics(); + const heapStatistics = getNormalizedHeapStatistics( + process.getHeapStatistics() + ); ElectronLog.log('main process stats', { - processMemoryInfo: normalizedProcessMemoryInfo, + processMemoryInfo, heapStatistics, cpuUsage, }); @@ -32,7 +37,7 @@ let previousProcessMemoryInfo: Electron.ProcessMemoryInfo = { let usingHighMemory = false; -async function logSpikeMemoryUsage() { +async function logSpikeMainMemoryUsage() { const processMemoryInfo = await process.getProcessMemoryInfo(); const currentMemoryUsage = Math.max( processMemoryInfo.residentSet, @@ -59,7 +64,9 @@ async function logSpikeMemoryUsage() { const normalizedPreviousProcessMemoryInfo = await getNormalizedProcessMemoryInfo(previousProcessMemoryInfo); const cpuUsage = process.getCPUUsage(); - const heapStatistics = getNormalizedHeapStatistics(); + const heapStatistics = getNormalizedHeapStatistics( + process.getHeapStatistics() + ); ElectronLog.log('reporting memory usage spike', { currentProcessMemoryInfo: normalizedCurrentProcessMemoryInfo, @@ -74,9 +81,61 @@ async function logSpikeMemoryUsage() { } } +let previousHeapStatistics: Electron.HeapStatistics = { + totalHeapSize: 0, + totalHeapSizeExecutable: 0, + totalPhysicalSize: 0, + totalAvailableSize: 0, + usedHeapSize: 0, + heapSizeLimit: 0, + mallocedMemory: 0, + peakMallocedMemory: 0, + doesZapGarbage: false, +}; + +let usingHighHeapMemory = false; +async function logSpikeRendererMemoryUsage() { + const currentHeapStatistics = process.getHeapStatistics(); + + const isSpiking = + currentHeapStatistics.totalHeapSize - + previousHeapStatistics.totalHeapSize >= + HEAP_SIZE_DIFF_IN_KILOBYTES_CONSIDERED_AS_SPIKE; + + const isHighHeapSize = + currentHeapStatistics.totalHeapSize >= + HIGH_HEAP_USAGE_THRESHOLD_IN_KILOBYTES; + + const shouldReport = + (isHighHeapSize && !usingHighHeapMemory) || + (!isHighHeapSize && usingHighHeapMemory); + + if (isSpiking || shouldReport) { + const normalizedCurrentHeapStatistics = getNormalizedHeapStatistics( + currentHeapStatistics + ); + const normalizedPreviousProcessMemoryInfo = getNormalizedHeapStatistics( + previousHeapStatistics + ); + const cpuUsage = process.getCPUUsage(); + + ElectronLog.log('reporting memory usage spike', { + currentProcessMemoryInfo: normalizedCurrentHeapStatistics, + previousProcessMemoryInfo: normalizedPreviousProcessMemoryInfo, + cpuUsage, + }); + } + previousHeapStatistics = currentHeapStatistics; + if (shouldReport) { + usingHighHeapMemory = !usingHighHeapMemory; + } +} + async function logRendererProcessStats() { const blinkMemoryInfo = getNormalizedBlinkMemoryInfo(); - const heapStatistics = getNormalizedHeapStatistics(); + const heapStatistics = getNormalizedHeapStatistics( + process.getHeapStatistics() + ); const webFrameResourceUsage = getNormalizedWebFrameResourceUsage(); ElectronLog.log('renderer process stats', { blinkMemoryInfo, @@ -86,11 +145,18 @@ async function logRendererProcessStats() { } export function setupMainProcessStatsLogger() { - setInterval(logSpikeMemoryUsage, SPIKE_DETECTION_INTERVAL_IN_MICROSECONDS); + setInterval( + logSpikeMainMemoryUsage, + SPIKE_DETECTION_INTERVAL_IN_MICROSECONDS + ); setInterval(logMainProcessStats, LOGGING_INTERVAL_IN_MICROSECONDS); } export function setupRendererProcessStatsLogger() { + setInterval( + logSpikeRendererMemoryUsage, + SPIKE_DETECTION_INTERVAL_IN_MICROSECONDS + ); setInterval(logRendererProcessStats, LOGGING_INTERVAL_IN_MICROSECONDS); } @@ -116,8 +182,9 @@ const getNormalizedBlinkMemoryInfo = () => { }; }; -const getNormalizedHeapStatistics = () => { - const heapStatistics = process.getHeapStatistics(); +const getNormalizedHeapStatistics = ( + heapStatistics: Electron.HeapStatistics +) => { return { totalHeapSize: convertBytesToHumanReadable( heapStatistics.totalHeapSize * 1024 From faab06506e42f72fe8f37b3b41fbd658b053a03b Mon Sep 17 00:00:00 2001 From: Abhinav Date: Wed, 11 Jan 2023 19:59:16 +0530 Subject: [PATCH 15/19] update main HIGH_MEMORY_USAGE_THRESHOLD_IN_KILOBYTES --- src/utils/processStats.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/processStats.ts b/src/utils/processStats.ts index 18c16590b..f984eddd4 100644 --- a/src/utils/processStats.ts +++ b/src/utils/processStats.ts @@ -7,7 +7,7 @@ const SPIKE_DETECTION_INTERVAL_IN_MICROSECONDS = 1 * 1000; // 1 seconds const MEMORY_DIFF_IN_KILOBYTES_CONSIDERED_AS_SPIKE = 10 * 1024; // 10 MB -const HIGH_MEMORY_USAGE_THRESHOLD_IN_KILOBYTES = 200 * 1024; // 200 MB +const HIGH_MEMORY_USAGE_THRESHOLD_IN_KILOBYTES = 100 * 1024; // 100 MB const HEAP_SIZE_DIFF_IN_KILOBYTES_CONSIDERED_AS_SPIKE = 200 * 1024; // 200 MB From c71d571c8624254a05247fc17ceba5417e122dbe Mon Sep 17 00:00:00 2001 From: Abhinav Date: Wed, 11 Jan 2023 20:57:25 +0530 Subject: [PATCH 16/19] use processMemoryInfo for renderer too --- src/utils/processStats.ts | 116 +++++++++++++++++++++----------------- 1 file changed, 64 insertions(+), 52 deletions(-) diff --git a/src/utils/processStats.ts b/src/utils/processStats.ts index f984eddd4..d5da4d739 100644 --- a/src/utils/processStats.ts +++ b/src/utils/processStats.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ import ElectronLog from 'electron-log'; import { webFrame } from 'electron/renderer'; @@ -5,13 +6,13 @@ const LOGGING_INTERVAL_IN_MICROSECONDS = 30 * 1000; // 30 seconds const SPIKE_DETECTION_INTERVAL_IN_MICROSECONDS = 1 * 1000; // 1 seconds -const MEMORY_DIFF_IN_KILOBYTES_CONSIDERED_AS_SPIKE = 10 * 1024; // 10 MB +const MAIN_MEMORY_USAGE_DIFF_IN_KILOBYTES_CONSIDERED_AS_SPIKE = 10 * 1024; // 10 MB -const HIGH_MEMORY_USAGE_THRESHOLD_IN_KILOBYTES = 100 * 1024; // 100 MB +const HIGH_MAIN_MEMORY_USAGE_THRESHOLD_IN_KILOBYTES = 100 * 1024; // 100 MB -const HEAP_SIZE_DIFF_IN_KILOBYTES_CONSIDERED_AS_SPIKE = 200 * 1024; // 200 MB +const RENDERER_MEMORY_USAGE_DIFF_IN_KILOBYTES_CONSIDERED_AS_SPIKE = 200 * 1024; // 200 MB -const HIGH_HEAP_USAGE_THRESHOLD_IN_KILOBYTES = 700 * 1024; // 700 MB +const HIGH_RENDERER_MEMORY_USAGE_THRESHOLD_IN_KILOBYTES = 700 * 1024; // 700 MB async function logMainProcessStats() { const processMemoryInfo = await getNormalizedProcessMemoryInfo( @@ -29,13 +30,13 @@ async function logMainProcessStats() { }); } -let previousProcessMemoryInfo: Electron.ProcessMemoryInfo = { +let previousMainProcessMemoryInfo: Electron.ProcessMemoryInfo = { private: 0, shared: 0, residentSet: 0, }; -let usingHighMemory = false; +let mainProcessUsingHighMemory = false; async function logSpikeMainMemoryUsage() { const processMemoryInfo = await process.getProcessMemoryInfo(); @@ -44,25 +45,25 @@ async function logSpikeMainMemoryUsage() { processMemoryInfo.private ); const previewMemoryUsage = Math.max( - previousProcessMemoryInfo.private, - previousProcessMemoryInfo.residentSet + previousMainProcessMemoryInfo.private, + previousMainProcessMemoryInfo.residentSet ); const isSpiking = currentMemoryUsage - previewMemoryUsage >= - MEMORY_DIFF_IN_KILOBYTES_CONSIDERED_AS_SPIKE; + MAIN_MEMORY_USAGE_DIFF_IN_KILOBYTES_CONSIDERED_AS_SPIKE; const isHighMemoryUsage = - currentMemoryUsage >= HIGH_MEMORY_USAGE_THRESHOLD_IN_KILOBYTES; + currentMemoryUsage >= HIGH_MAIN_MEMORY_USAGE_THRESHOLD_IN_KILOBYTES; const shouldReport = - (isHighMemoryUsage && !usingHighMemory) || - (!isHighMemoryUsage && usingHighMemory); + (isHighMemoryUsage && !mainProcessUsingHighMemory) || + (!isHighMemoryUsage && mainProcessUsingHighMemory); if (isSpiking || shouldReport) { const normalizedCurrentProcessMemoryInfo = await getNormalizedProcessMemoryInfo(processMemoryInfo); const normalizedPreviousProcessMemoryInfo = - await getNormalizedProcessMemoryInfo(previousProcessMemoryInfo); + await getNormalizedProcessMemoryInfo(previousMainProcessMemoryInfo); const cpuUsage = process.getCPUUsage(); const heapStatistics = getNormalizedHeapStatistics( process.getHeapStatistics() @@ -75,59 +76,63 @@ async function logSpikeMainMemoryUsage() { cpuUsage, }); } - previousProcessMemoryInfo = processMemoryInfo; + previousMainProcessMemoryInfo = processMemoryInfo; if (shouldReport) { - usingHighMemory = !usingHighMemory; + mainProcessUsingHighMemory = !mainProcessUsingHighMemory; } } -let previousHeapStatistics: Electron.HeapStatistics = { - totalHeapSize: 0, - totalHeapSizeExecutable: 0, - totalPhysicalSize: 0, - totalAvailableSize: 0, - usedHeapSize: 0, - heapSizeLimit: 0, - mallocedMemory: 0, - peakMallocedMemory: 0, - doesZapGarbage: false, +let previousRendererProcessMemoryInfo: Electron.ProcessMemoryInfo = { + private: 0, + shared: 0, + residentSet: 0, }; -let usingHighHeapMemory = false; +let rendererUsingHighMemory = false; + async function logSpikeRendererMemoryUsage() { - const currentHeapStatistics = process.getHeapStatistics(); - + const processMemoryInfo = await process.getProcessMemoryInfo(); + const currentMemoryUsage = Math.max( + processMemoryInfo.residentSet, + processMemoryInfo.private + ); + const previewMemoryUsage = Math.max( + previousRendererProcessMemoryInfo.private, + previousRendererProcessMemoryInfo.residentSet + ); const isSpiking = - currentHeapStatistics.totalHeapSize - - previousHeapStatistics.totalHeapSize >= - HEAP_SIZE_DIFF_IN_KILOBYTES_CONSIDERED_AS_SPIKE; + currentMemoryUsage - previewMemoryUsage >= + RENDERER_MEMORY_USAGE_DIFF_IN_KILOBYTES_CONSIDERED_AS_SPIKE; - const isHighHeapSize = - currentHeapStatistics.totalHeapSize >= - HIGH_HEAP_USAGE_THRESHOLD_IN_KILOBYTES; + const isHighMemoryUsage = + currentMemoryUsage >= HIGH_RENDERER_MEMORY_USAGE_THRESHOLD_IN_KILOBYTES; const shouldReport = - (isHighHeapSize && !usingHighHeapMemory) || - (!isHighHeapSize && usingHighHeapMemory); + (isHighMemoryUsage && !rendererUsingHighMemory) || + (!isHighMemoryUsage && rendererUsingHighMemory); if (isSpiking || shouldReport) { - const normalizedCurrentHeapStatistics = getNormalizedHeapStatistics( - currentHeapStatistics - ); - const normalizedPreviousProcessMemoryInfo = getNormalizedHeapStatistics( - previousHeapStatistics - ); + const normalizedCurrentProcessMemoryInfo = + await getNormalizedProcessMemoryInfo(processMemoryInfo); + const normalizedPreviousProcessMemoryInfo = + await getNormalizedProcessMemoryInfo( + previousRendererProcessMemoryInfo + ); const cpuUsage = process.getCPUUsage(); + const heapStatistics = getNormalizedHeapStatistics( + process.getHeapStatistics() + ); ElectronLog.log('reporting memory usage spike', { - currentProcessMemoryInfo: normalizedCurrentHeapStatistics, + currentProcessMemoryInfo: normalizedCurrentProcessMemoryInfo, previousProcessMemoryInfo: normalizedPreviousProcessMemoryInfo, + heapStatistics, cpuUsage, }); } - previousHeapStatistics = currentHeapStatistics; + previousRendererProcessMemoryInfo = processMemoryInfo; if (shouldReport) { - usingHighHeapMemory = !usingHighHeapMemory; + rendererUsingHighMemory = !rendererUsingHighMemory; } } @@ -137,27 +142,34 @@ async function logRendererProcessStats() { process.getHeapStatistics() ); const webFrameResourceUsage = getNormalizedWebFrameResourceUsage(); + const processMemoryInfo = await getNormalizedProcessMemoryInfo( + await process.getProcessMemoryInfo() + ); ElectronLog.log('renderer process stats', { blinkMemoryInfo, heapStatistics, + processMemoryInfo, webFrameResourceUsage, }); } export function setupMainProcessStatsLogger() { - setInterval( - logSpikeMainMemoryUsage, - SPIKE_DETECTION_INTERVAL_IN_MICROSECONDS - ); - setInterval(logMainProcessStats, LOGGING_INTERVAL_IN_MICROSECONDS); + // setInterval( + // logSpikeMainMemoryUsage, + // SPIKE_DETECTION_INTERVAL_IN_MICROSECONDS + // ); + setInterval(logMainProcessStats, SPIKE_DETECTION_INTERVAL_IN_MICROSECONDS); } export function setupRendererProcessStatsLogger() { + // setInterval( + // logSpikeRendererMemoryUsage, + // SPIKE_DETECTION_INTERVAL_IN_MICROSECONDS + // ); setInterval( - logSpikeRendererMemoryUsage, + logRendererProcessStats, SPIKE_DETECTION_INTERVAL_IN_MICROSECONDS ); - setInterval(logRendererProcessStats, LOGGING_INTERVAL_IN_MICROSECONDS); } const getNormalizedProcessMemoryInfo = async ( From 4484977c0775d14485917502a24a8e8db73415e5 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Wed, 11 Jan 2023 22:56:06 +0530 Subject: [PATCH 17/19] increase renderer high limit --- src/utils/processStats.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/processStats.ts b/src/utils/processStats.ts index d5da4d739..e06ef768a 100644 --- a/src/utils/processStats.ts +++ b/src/utils/processStats.ts @@ -12,7 +12,7 @@ const HIGH_MAIN_MEMORY_USAGE_THRESHOLD_IN_KILOBYTES = 100 * 1024; // 100 MB const RENDERER_MEMORY_USAGE_DIFF_IN_KILOBYTES_CONSIDERED_AS_SPIKE = 200 * 1024; // 200 MB -const HIGH_RENDERER_MEMORY_USAGE_THRESHOLD_IN_KILOBYTES = 700 * 1024; // 700 MB +const HIGH_RENDERER_MEMORY_USAGE_THRESHOLD_IN_KILOBYTES = 1024 * 1024; // 1 GB async function logMainProcessStats() { const processMemoryInfo = await getNormalizedProcessMemoryInfo( From 386808bf541613783f964861b9a3d7cfe1556b69 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Wed, 11 Jan 2023 22:57:05 +0530 Subject: [PATCH 18/19] reset testing changes --- src/utils/processStats.ts | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/utils/processStats.ts b/src/utils/processStats.ts index e06ef768a..7bf262cd9 100644 --- a/src/utils/processStats.ts +++ b/src/utils/processStats.ts @@ -1,4 +1,3 @@ -/* eslint-disable @typescript-eslint/no-unused-vars */ import ElectronLog from 'electron-log'; import { webFrame } from 'electron/renderer'; @@ -154,22 +153,19 @@ async function logRendererProcessStats() { } export function setupMainProcessStatsLogger() { - // setInterval( - // logSpikeMainMemoryUsage, - // SPIKE_DETECTION_INTERVAL_IN_MICROSECONDS - // ); - setInterval(logMainProcessStats, SPIKE_DETECTION_INTERVAL_IN_MICROSECONDS); + setInterval( + logSpikeMainMemoryUsage, + SPIKE_DETECTION_INTERVAL_IN_MICROSECONDS + ); + setInterval(logMainProcessStats, LOGGING_INTERVAL_IN_MICROSECONDS); } export function setupRendererProcessStatsLogger() { - // setInterval( - // logSpikeRendererMemoryUsage, - // SPIKE_DETECTION_INTERVAL_IN_MICROSECONDS - // ); setInterval( - logRendererProcessStats, + logSpikeRendererMemoryUsage, SPIKE_DETECTION_INTERVAL_IN_MICROSECONDS ); + setInterval(logRendererProcessStats, LOGGING_INTERVAL_IN_MICROSECONDS); } const getNormalizedProcessMemoryInfo = async ( From 29124babb0accdc5da78d221a426252640c93780 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Thu, 12 Jan 2023 09:12:47 +0530 Subject: [PATCH 19/19] add process name in spike log --- src/utils/processStats.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/processStats.ts b/src/utils/processStats.ts index 7bf262cd9..64f900d58 100644 --- a/src/utils/processStats.ts +++ b/src/utils/processStats.ts @@ -68,7 +68,7 @@ async function logSpikeMainMemoryUsage() { process.getHeapStatistics() ); - ElectronLog.log('reporting memory usage spike', { + ElectronLog.log('reporting main memory usage spike', { currentProcessMemoryInfo: normalizedCurrentProcessMemoryInfo, previousProcessMemoryInfo: normalizedPreviousProcessMemoryInfo, heapStatistics, @@ -122,7 +122,7 @@ async function logSpikeRendererMemoryUsage() { process.getHeapStatistics() ); - ElectronLog.log('reporting memory usage spike', { + ElectronLog.log('reporting renderer memory usage spike', { currentProcessMemoryInfo: normalizedCurrentProcessMemoryInfo, previousProcessMemoryInfo: normalizedPreviousProcessMemoryInfo, heapStatistics,