Skip to content

Commit

Permalink
v8: export cpu_profiler_metadata_size in getHeapCodeStatistics
Browse files Browse the repository at this point in the history
  • Loading branch information
theanarkh committed Apr 21, 2022
1 parent a2d86f6 commit 535faee
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
8 changes: 6 additions & 2 deletions doc/api/v8.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,23 @@ added: v12.8.0

* Returns: {Object}

Returns an object with the following properties:
Get statistics about code and its metadata in the heap, see V8
`GetHeapCodeAndMetadataStatistics` API. Returns an object with the
following properties:

* `code_and_metadata_size` {number}
* `bytecode_and_metadata_size` {number}
* `external_script_source_size` {number}
* `cpu_profiler_metadata_size` {number}

<!-- eslint-skip -->

```js
{
code_and_metadata_size: 212208,
bytecode_and_metadata_size: 161368,
external_script_source_size: 1410794
external_script_source_size: 1410794,
cpu_profiler_metadata_size: 0
}
```

Expand Down
6 changes: 4 additions & 2 deletions lib/v8.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ const {
// Properties for heap code statistics buffer extraction.
kCodeAndMetadataSizeIndex,
kBytecodeAndMetadataSizeIndex,
kExternalScriptSourceSizeIndex
kExternalScriptSourceSizeIndex,
kCPUProfilerMetaDataSizeIndex
} = binding;

const kNumberOfHeapSpaces = kHeapSpaces.length;
Expand Down Expand Up @@ -212,7 +213,8 @@ function getHeapCodeStatistics() {
return {
code_and_metadata_size: buffer[kCodeAndMetadataSizeIndex],
bytecode_and_metadata_size: buffer[kBytecodeAndMetadataSizeIndex],
external_script_source_size: buffer[kExternalScriptSourceSizeIndex]
external_script_source_size: buffer[kExternalScriptSourceSizeIndex],
cpu_profiler_metadata_size: buffer[kCPUProfilerMetaDataSizeIndex]
};
}

Expand Down
3 changes: 2 additions & 1 deletion src/node_v8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ static constexpr size_t kHeapSpaceStatisticsPropertiesCount =
#define HEAP_CODE_STATISTICS_PROPERTIES(V) \
V(0, code_and_metadata_size, kCodeAndMetadataSizeIndex) \
V(1, bytecode_and_metadata_size, kBytecodeAndMetadataSizeIndex) \
V(2, external_script_source_size, kExternalScriptSourceSizeIndex)
V(2, external_script_source_size, kExternalScriptSourceSizeIndex) \
V(3, cpu_profiler_metadata_size, kCPUProfilerMetaDataSizeIndex)

#define V(a, b, c) +1
static const size_t kHeapCodeStatisticsPropertiesCount =
Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-v8-stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const heapCodeStatistics = v8.getHeapCodeStatistics();
const heapCodeStatisticsKeys = [
'bytecode_and_metadata_size',
'code_and_metadata_size',
'cpu_profiler_metadata_size',
'external_script_source_size'];
assert.deepStrictEqual(Object.keys(heapCodeStatistics).sort(),
heapCodeStatisticsKeys);
Expand Down

0 comments on commit 535faee

Please sign in to comment.