remove getSystemMemoryInfo as free memory reported is incorrect

This commit is contained in:
Abhinav 2023-01-06 22:41:33 +05:30
parent 7fabf2c5c9
commit ae8326a773

View file

@ -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 {