MCPcopy Index your code
hub / github.com/anomalyco/opencode / start

Function start

packages/opencode/src/cli/heap.ts:12–43  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

10let armed = true
11
12export function start() {
13 if (!Flag.OPENCODE_AUTO_HEAP_SNAPSHOT) return
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()
41 }, MINUTE)
42 timer.unref?.()
43}
44
45export * as Heap from "./heap"

Callers

nothing calls this directly

Calls 1

runFunction · 0.70

Tested by

no test coverage detected