Skip to content

Commit 08b8667

Browse files
committed
Collect one more report after memory usage goes back down
1 parent e063553 commit 08b8667

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

scripts/watch-for-rts-spike.mts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,18 @@ class RtsMon {
4444

4545
const aboveThreshold: boolean = memoryUsageMB >= this.options.thresholdMib;
4646
if (aboveThreshold === true) {
47-
this.sendSignal(pid);
47+
await this.sendSignal(pid);
4848
this.currentIntervalSeconds *= 2;
4949
Program.log(
5050
`RSS ${memoryUsageMB.toFixed(1)}MB >= threshold (${this.options.thresholdMib} MiB). Increasing interval to ${
5151
this.currentIntervalSeconds
5252
} s`
5353
);
5454
} else {
55+
if (this.currentIntervalSeconds > this.options.intervalSeconds) {
56+
// Memory usage came back down below the threshold since last check. Collect one more report.
57+
await this.sendSignal(pid);
58+
}
5559
Program.log(`RSS ${memoryUsageMB.toFixed(1)} MiB (below threshold ${this.options.thresholdMib} MiB).`);
5660
this.resetDelay();
5761
}
@@ -67,9 +71,9 @@ class RtsMon {
6771
this.currentIntervalSeconds = this.options.intervalSeconds;
6872
}
6973

70-
private sendSignal(pid: number): void {
74+
private async sendSignal(pid: number): Promise<void> {
7175
try {
72-
this.runCommand("kill", ["-SIGUSR2", String(pid)]);
76+
await this.runCommand("kill", ["-SIGUSR2", String(pid)]);
7377
Program.log(`Sent SIGUSR2 to pid ${pid}`);
7478
} catch (e) {
7579
Program.logError(`Failed to send SIGUSR2 to pid ${pid}: ${(e as Error).message}`);

0 commit comments

Comments
 (0)