UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 1.3 kB
import{GCProfiler as e}from"node:v8";const t={Scavenge:`scavenge`,MinorMarkSweep:`scavenge`,MarkSweepCompact:`mark_sweep_compact`,IncrementalMarking:`incremental`,ProcessWeakCallbacks:`weak_processing`},n=/* @__PURE__ */ new Set;let r,i,a;function getOldGenerationAfterGcBytes(){return a}function drain(e){let i=r?.stop();e&&r?.start();let o=[];for(let e of i?.statistics??[]){let n=t[e.gcType];if(!n)continue;let r=e.beforeGC.heapStatistics.usedHeapSize,i={kind:n,reason:`other`,durationMs:e.cost/1e3,heapUsedBeforeBytes:r,reclaimedBytes:Math.max(0,r-e.afterGC.heapStatistics.usedHeapSize)};if(n===`mark_sweep_compact`){i.heapUsedAfterMajorGcBytes=e.afterGC.heapStatistics.usedHeapSize,i.heapUsedAfterMajorGcTimestampSeconds=Date.now()/1e3,a=0;for(let t of e.afterGC.heapSpaceStatistics)(t.spaceName===`old_space`||t.spaceName===`large_object_space`)&&(a+=t.spaceUsedSize)}o.push(i)}if(o.length)for(let e of n)e(o)}function flushGcSamples(){r&&drain(!0)}function observeGcSamples(t){if(!process.versions.bun)return r?drain(!0):(r=new e,r.start(),i=setInterval(()=>drain(!0),1e3).unref()),n.add(t),()=>{if(!n.has(t))return;let e=n.size===1;drain(!e),n.delete(t),e&&(clearInterval(i),i=void 0,r=void 0,a=void 0)}}export{getOldGenerationAfterGcBytes as n,observeGcSamples as r,flushGcSamples as t};