Skip to content

Commit

Permalink
ISSUE #693 accumulate process time on process monitoring if we've see…
Browse files Browse the repository at this point in the history
…n the record before.
  • Loading branch information
carmenfan committed Aug 30, 2024
1 parent 5da0c13 commit b32c3a9
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions tools/bouncer_worker/src/lib/processMonitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,26 +63,27 @@ const shouldMonitor = async () => enabled && permittedOS.includes(await currentO

ProcessMonitor.startMonitor = async (processInfo) => {
if (!(await shouldMonitor())) return;
if (dataByRid[processInfo.Rid]) delete dataByRid[processInfo.Rid];
const currentMemUsage = await getCurrentMemUsage();
dataByRid[processInfo.Rid] = {
startMemory: currentMemUsage,
maxMemory: currentMemUsage,
startTime: Date.now(),
processInfo };
processInfo,
prevRecord: dataByRid[processInfo.Rid],
};
dataByRid[processInfo.Rid].timer = monitor(processInfo.Rid);
logger.verbose(`Monitoring enabled for revision ${processInfo.Rid} starting at ${dataByRid[processInfo.Rid].startMemory}`, logLabel);
};

ProcessMonitor.stopMonitor = async (rid, returnCode) => {
if (!(await shouldMonitor()) || !dataByRid[rid]) return;
const { processInfo, maxMemory, startMemory, startTime, timer } = dataByRid[rid];
const { processInfo, maxMemory, startMemory, startTime, timer, prevRecord } = dataByRid[rid];
clearInterval(timer);
const report = {
...processInfo,
ReturnCode: returnCode,
MaxMemory: maxMemory - startMemory,
ProcessTime: Date.now() - startTime,
MaxMemory: Math.max(maxMemory - startMemory, prevRecord?.MaxMemory ?? 0),
ProcessTime: (prevRecord?.ProcessTime ?? 0) + (Date.now() - startTime),
};

dataByRid[rid] = report;
Expand Down

0 comments on commit b32c3a9

Please sign in to comment.