From 5f5e3f4bed6cbb8ee483ac28731ba7372d52ce27 Mon Sep 17 00:00:00 2001 From: Moritz Utcke Date: Mon, 2 Jun 2025 21:49:26 -0300 Subject: [PATCH] Heap Snapshot --- src/pages/heap-snapshot.astro | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/pages/heap-snapshot.astro b/src/pages/heap-snapshot.astro index 3497bd66..1c1f49bf 100644 --- a/src/pages/heap-snapshot.astro +++ b/src/pages/heap-snapshot.astro @@ -1,6 +1,19 @@ --- -import { writeHeapSnapshot } from "v8"; +import { getHeapSnapshot } from "v8"; +import * as fs from "fs"; // Create a named heap snapshot -writeHeapSnapshot("~/.heapsnapshot"); +const snapshotStream = getHeapSnapshot(); +const fileName = `heap-${Date.now()}.heapsnapshot`; +const fileStream = fs.createWriteStream(fileName); + +snapshotStream.pipe(fileStream); + +fileStream.on("finish", () => { + console.log(`Heap snapshot saved to ${fileName}`); +}); + +fileStream.on("error", (err) => { + console.error("Error writing heap snapshot:", err); +}); --- \ No newline at end of file