(pid: number)
| 185 | } |
| 186 | |
| 187 | function parseLinuxStatus(pid: number) { |
| 188 | if (process.platform !== "linux") { |
| 189 | return null; |
| 190 | } |
| 191 | |
| 192 | try { |
| 193 | const status = readFileSync(`/proc/${pid}/status`, "utf8"); |
| 194 | const valueKb = (name: string) => { |
| 195 | const match = status.match(new RegExp(`^${name}:\\s+(\\d+)\\s+kB`, "m")); |
| 196 | return match ? Number(match[1]) * 1024 : null; |
| 197 | }; |
| 198 | return { |
| 199 | rssBytes: valueKb("VmRSS") ?? 0, |
| 200 | // External process probes cannot reliably read Bun's JS heap; RSS is the leak signal here. |
| 201 | heapBytes: null, |
| 202 | highWaterRssBytes: valueKb("VmHWM"), |
| 203 | }; |
| 204 | } catch { |
| 205 | return null; |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | async function readProcessMemory(pid: number) { |
| 210 | const linux = parseLinuxStatus(pid); |
no test coverage detected