v8: support gc profile · nodejs/node@02632b4 · GitHub
Skip to content

Commit 02632b4

Browse files
theanarkhjuanarbol
authored andcommitted
v8: support gc profile
PR-URL: #46255 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
1 parent 63e92ea commit 02632b4

8 files changed

Lines changed: 460 additions & 1 deletion

File tree

doc/api/v8.md

Lines changed: 106 additions & 0 deletions

lib/v8.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const {
6060
const { HeapSnapshotStream } = require('internal/heap_utils');
6161
const promiseHooks = require('internal/promise_hooks');
6262
const { getOptionValue } = require('internal/options');
63-
63+
const { JSONParse } = primordials;
6464
/**
6565
* Generates a snapshot of the current V8 heap
6666
* and writes it to a JSON file.
@@ -384,6 +384,25 @@ function deserialize(buffer) {
384384
return der.readValue();
385385
}
386386

387+
class GCProfiler {
388+
#profiler = null;
389+
390+
start() {
391+
if (!this.#profiler) {
392+
this.#profiler = new binding.GCProfiler();
393+
this.#profiler.start();
394+
}
395+
}
396+
397+
stop() {
398+
if (this.#profiler) {
399+
const data = this.#profiler.stop();
400+
this.#profiler = null;
401+
return JSONParse(data);
402+
}
403+
}
404+
}
405+
387406
module.exports = {
388407
cachedDataVersionTag,
389408
getHeapSnapshot,
@@ -403,4 +422,5 @@ module.exports = {
403422
promiseHooks,
404423
startupSnapshot,
405424
setHeapSnapshotNearHeapLimit,
425+
GCProfiler,
406426
};

src/node_v8.cc

Lines changed: 190 additions & 0 deletions

0 commit comments

Comments
 (0)