Skip to content

Commit c75ad3d

Browse files
IlyasShabiaduh95
authored andcommitted
v8: add GCProfiler support for erm
PR-URL: #61191 Reviewed-By: Aviv Keller <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: René <[email protected]>
1 parent ade4fc2 commit c75ad3d

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

doc/api/v8.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1471,6 +1471,7 @@ added:
14711471
-->
14721472
14731473
Create a new instance of the `v8.GCProfiler` class.
1474+
This API supports `using` syntax.
14741475
14751476
### `profiler.start()`
14761477
@@ -1490,7 +1491,7 @@ added:
14901491
- v18.15.0
14911492
-->
14921493
1493-
Stop collecting GC data and return an object.The content of object
1494+
Stop collecting GC data and return an object. The content of object
14941495
is as follows.
14951496
14961497
```json
@@ -1575,6 +1576,14 @@ setTimeout(() => {
15751576
}, 1000);
15761577
```
15771578
1579+
### `profiler[Symbol.dispose]()`
1580+
1581+
<!-- YAML
1582+
added: REPLACEME
1583+
-->
1584+
1585+
Stop collecting GC data, and discard the profile.
1586+
15781587
## Class: `SyncCPUProfileHandle`
15791588
15801589
<!-- YAML

lib/v8.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,10 @@ class GCProfiler {
488488
return JSONParse(data);
489489
}
490490
}
491+
492+
[SymbolDispose]() {
493+
this.stop();
494+
}
491495
}
492496

493497
module.exports = {
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use strict';
2+
3+
require('../common');
4+
const assert = require('assert');
5+
const { GCProfiler } = require('v8');
6+
7+
{
8+
const profiler = new GCProfiler();
9+
profiler.start();
10+
11+
const result = profiler[Symbol.dispose]();
12+
13+
assert.strictEqual(result, undefined);
14+
assert.strictEqual(profiler.stop(), undefined);
15+
}
16+
17+
{
18+
const profiler = new GCProfiler();
19+
profiler.start();
20+
21+
profiler[Symbol.dispose]();
22+
// Repeat invocations should not throw
23+
profiler[Symbol.dispose]();
24+
25+
assert.strictEqual(profiler.stop(), undefined);
26+
}

0 commit comments

Comments
 (0)