@opencode/util 0.0.0-dev-21662 → 0.0.0-dev-21668
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/heap-snapshot.d.ts +11 -3
- package/dist/heap-snapshot.js +17 -5
- package/package.json +1 -1
package/dist/heap-snapshot.d.ts
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
2
|
/**
|
|
3
|
-
* Writes a V8 heap snapshot of this process into `directory` and returns once the file is complete
|
|
4
|
-
*
|
|
5
|
-
*
|
|
3
|
+
* Writes a V8 heap snapshot of this process into `directory` and returns once the file is complete, with the
|
|
4
|
+
* process's memory just before the snapshot: the snapshot holds only the garbage-collected heap, and writing it
|
|
5
|
+
* raises the process's memory. Blocks the event loop while the heap serializes. The file can contain secrets, so it
|
|
6
|
+
* is created owner-only before the runtime writes into it.
|
|
6
7
|
*/
|
|
7
8
|
export declare const write: (directory: string) => Effect.Effect<{
|
|
8
9
|
path: string;
|
|
9
10
|
pid: number;
|
|
11
|
+
memory: {
|
|
12
|
+
rss: number;
|
|
13
|
+
heapTotal: number;
|
|
14
|
+
heapUsed: number;
|
|
15
|
+
external: number;
|
|
16
|
+
arrayBuffers: number;
|
|
17
|
+
};
|
|
10
18
|
}, import("effect/Cause").UnknownError, never>;
|
|
11
19
|
export * as HeapSnapshot from "./heap-snapshot.js";
|
package/dist/heap-snapshot.js
CHANGED
|
@@ -5,9 +5,10 @@ import path from "node:path";
|
|
|
5
5
|
// requests queue instead of serializing two heaps at once.
|
|
6
6
|
const lock = Semaphore.makeUnsafe(1);
|
|
7
7
|
/**
|
|
8
|
-
* Writes a V8 heap snapshot of this process into `directory` and returns once the file is complete
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* Writes a V8 heap snapshot of this process into `directory` and returns once the file is complete, with the
|
|
9
|
+
* process's memory just before the snapshot: the snapshot holds only the garbage-collected heap, and writing it
|
|
10
|
+
* raises the process's memory. Blocks the event loop while the heap serializes. The file can contain secrets, so it
|
|
11
|
+
* is created owner-only before the runtime writes into it.
|
|
11
12
|
*/
|
|
12
13
|
export const write = Effect.fn("HeapSnapshot.write")(function* (directory) {
|
|
13
14
|
const v8 = yield* Effect.tryPromise(() => import("node:v8"));
|
|
@@ -18,9 +19,20 @@ export const write = Effect.fn("HeapSnapshot.write")(function* (directory) {
|
|
|
18
19
|
const handle = await open(file, "wx", 0o600);
|
|
19
20
|
await handle.close();
|
|
20
21
|
});
|
|
21
|
-
yield* Effect.
|
|
22
|
+
const memory = yield* Effect.sync(() => process.memoryUsage());
|
|
23
|
+
yield* Effect.logInfo("writing heap snapshot", { path: file, rss: memory.rss, heapUsed: memory.heapUsed });
|
|
22
24
|
yield* Effect.try(() => v8.writeHeapSnapshot(file));
|
|
23
25
|
yield* Effect.logInfo("heap snapshot written", { path: file });
|
|
24
|
-
return {
|
|
26
|
+
return {
|
|
27
|
+
path: file,
|
|
28
|
+
pid: process.pid,
|
|
29
|
+
memory: {
|
|
30
|
+
rss: memory.rss,
|
|
31
|
+
heapTotal: memory.heapTotal,
|
|
32
|
+
heapUsed: memory.heapUsed,
|
|
33
|
+
external: memory.external,
|
|
34
|
+
arrayBuffers: memory.arrayBuffers,
|
|
35
|
+
},
|
|
36
|
+
};
|
|
25
37
|
}, (effect) => lock.withPermit(effect));
|
|
26
38
|
export * as HeapSnapshot from "./heap-snapshot.js";
|