Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
12 changes: 11 additions & 1 deletion doc/api/v8.md
Original file line number Diff line number Diff line change
Expand Up @@ -1320,6 +1320,7 @@ added:
-->

Start collecting GC data.
This API supports `using` syntax.

### `profiler.stop()`

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,15 @@ setTimeout(() => {
}, 1000);
```

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

<!-- YAML
added: REPLACEME
-->

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

## 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