import { Y as a } from "../index-DSGwv2Yx.js";
const s = 1024 * 1024;
class l {
  log = /* @__PURE__ */ new Map();
  maxMemory = 0;
  maxLabel;
  lastMemInfo = [];
  peakMemory = 0;
  startMemory() {
    this.lastMemInfo.push(a());
  }
  getPeakMemory() {
    return this.peakMemory;
  }
  getMaxMemory() {
    return this.maxMemory;
  }
  endMemory(o) {
    if (this.lastMemInfo.length === 0) {
      console.warn("MemoryProfiler: endMemory called without matching startMemory");
      return;
    }
    const e = a(), t = this.lastMemInfo.pop(), m = (e.numBytesInGPUAllocated ?? e.numBytesAllocatedInGPU ?? e.numBytes) - (t?.numBytesInGPUAllocated ?? t?.numBytesAllocatedInGPU ?? t?.numBytes ?? 0);
    this.log.set(o, Math.max(this.log.get(o) || 0, m)), m > this.maxMemory && (this.maxMemory = m, this.maxLabel = o), this.peakMemory = Math.max(
      this.peakMemory,
      e.numBytesInGPUAllocated ?? e.numBytesAllocatedInGPU ?? e.numBytes
    );
  }
  printSummary() {
    console.log("Memory Usage Summary:");
    for (const [o, e] of this.log.entries())
      console.log(`- ${o}: ${(e / s).toFixed(2)} MB`);
    this.maxLabel && console.log(`Peak Memory Usage: ${(this.maxMemory / s).toFixed(2)} MB at "${this.maxLabel}"`), console.log(`Overall Peak Memory Usage: ${(this.peakMemory / s).toFixed(2)} MB`);
  }
}
export {
  l as default
};
