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

Commit b4ac794

Browse files
theanarkhruyadorno
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 2e5e7a9 commit b4ac794

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
@@ -63,7 +63,7 @@ const {
6363
} = require('internal/heap_utils');
6464
const promiseHooks = require('internal/promise_hooks');
6565
const { getOptionValue } = require('internal/options');
66-
66+
const { JSONParse } = primordials;
6767
/**
6868
* Generates a snapshot of the current V8 heap
6969
* and writes it to a JSON file.
@@ -397,6 +397,25 @@ function deserialize(buffer) {
397397
return der.readValue();
398398
}
399399

400+
class GCProfiler {
401+
#profiler = null;
402+
403+
start() {
404+
if (!this.#profiler) {
405+
this.#profiler = new binding.GCProfiler();
406+
this.#profiler.start();
407+
}
408+
}
409+
410+
stop() {
411+
if (this.#profiler) {
412+
const data = this.#profiler.stop();
413+
this.#profiler = null;
414+
return JSONParse(data);
415+
}
416+
}
417+
}
418+
400419
module.exports = {
401420
cachedDataVersionTag,
402421
getHeapSnapshot,
@@ -416,4 +435,5 @@ module.exports = {
416435
promiseHooks,
417436
startupSnapshot,
418437
setHeapSnapshotNearHeapLimit,
438+
GCProfiler,
419439
};

src/node_v8.cc

Lines changed: 190 additions & 0 deletions

0 commit comments

Comments
 (0)