()
| 14 | if (timer) return |
| 15 | |
| 16 | const run = async () => { |
| 17 | if (lock) return |
| 18 | |
| 19 | const stat = process.memoryUsage() |
| 20 | if (stat.rss <= LIMIT) { |
| 21 | armed = true |
| 22 | return |
| 23 | } |
| 24 | if (!armed) return |
| 25 | |
| 26 | lock = true |
| 27 | armed = false |
| 28 | const file = path.join( |
| 29 | Global.Path.log, |
| 30 | `heap-${process.pid}-${new Date().toISOString().replace(/[:.]/g, "")}.heapsnapshot`, |
| 31 | ) |
| 32 | await Promise.resolve() |
| 33 | .then(() => writeHeapSnapshot(file)) |
| 34 | .catch(() => {}) |
| 35 | |
| 36 | lock = false |
| 37 | } |
| 38 | |
| 39 | timer = setInterval(() => { |
| 40 | void run() |