Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion doc/api/v8.md
Original file line number Diff line number Diff line change
Expand Up @@ -1310,6 +1310,7 @@ added:
-->

Create a new instance of the `v8.GCProfiler` class.
This API supports `using` syntax.

### `profiler.start()`

Expand All @@ -1329,7 +1330,7 @@ added:
- v18.15.0
-->

Stop collecting GC data and return an object.The content of object
Stop collecting GC data and return an object. The content of object
is as follows.

```json
Expand Down Expand Up @@ -1405,6 +1406,14 @@ setTimeout(() => {
}, 1000);
```

### `profiler[Symbol.dispose]()`

<!-- YAML
added: REPLACEME
-->

Stop collecting GC data, and discard the profile.

## Class: `SyncCPUProfileHandle`

<!-- YAML
Expand Down
4 changes: 4 additions & 0 deletions lib/v8.js
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,10 @@ class GCProfiler {
return JSONParse(data);
}
}

[SymbolDispose]() {
this.stop();
}
}

module.exports = {
Expand Down
26 changes: 26 additions & 0 deletions test/parallel/test-v8-collect-gc-profile-using.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';

require('../common');
const assert = require('assert');
const { GCProfiler } = require('v8');

{
const profiler = new GCProfiler();
profiler.start();

const result = profiler[Symbol.dispose]();

assert.strictEqual(result, undefined);
assert.strictEqual(profiler.stop(), undefined);
}

{
const profiler = new GCProfiler();
profiler.start();

profiler[Symbol.dispose]();
// Repeat invocations should not throw
profiler[Symbol.dispose]();

assert.strictEqual(profiler.stop(), undefined);
}
Loading