Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

report: add more heap infos in process report #43116

Merged
Merged
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
19 changes: 14 additions & 5 deletions doc/api/report.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,20 @@ is provided below for reference.
}
],
"javascriptHeap": {
"totalMemory": 6127616,
"totalCommittedMemory": 4357352,
"usedMemory": 3221136,
"availableMemory": 1521370240,
"memoryLimit": 1526909922,
"totalMemory": 5660672,
"executableMemory": 524288,
"totalCommittedMemory": 5488640,
"availableMemory": 4341379928,
"totalGlobalHandlesMemory": 8192,
"usedGlobalHandlesMemory": 3136,
"usedMemory": 4816432,
"memoryLimit": 4345298944,
"mallocedMemory": 254128,
"externalMemory": 315644,
"peakMallocedMemory": 98752,
"nativeContextCount": 1,
"detachedContextCount": 0,
"doesZapGarbage": 0,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what the policies are on removing keys in the diagnostic report. When V8 removes these keys, what can we do to generate the report to fill these keys?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what the policies are on removing keys in the diagnostic report. When V8 removes these keys, what can we do to generate the report to fill these keys?

These fields are currently following the V8 API, if V8 removes these fields, I think we need to change the value of the field to -1.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be a good idea to add some comments here explaining about this (it's probably necessary to turn the json label to js for that, but it's probably also good to allow more comments on this example in general)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be a good idea to add some comments here explaining about this (it's probably necessary to turn the json label to js for that, but it's probably also good to allow more comments on this example in general)

There are too many fields in this object, I need some time to understand the specific meaning of it, maybe submit another PR?

"heapSpaces": {
"read_only_space": {
"memorySize": 524288,
Expand Down
17 changes: 16 additions & 1 deletion src/node_report.cc
Original file line number Diff line number Diff line change
Expand Up @@ -608,12 +608,27 @@ static void PrintGCStatistics(JSONWriter* writer, Isolate* isolate) {

writer->json_objectstart("javascriptHeap");
writer->json_keyvalue("totalMemory", v8_heap_stats.total_heap_size());
writer->json_keyvalue("executableMemory",
v8_heap_stats.total_heap_size_executable());
writer->json_keyvalue("totalCommittedMemory",
v8_heap_stats.total_physical_size());
writer->json_keyvalue("usedMemory", v8_heap_stats.used_heap_size());
writer->json_keyvalue("availableMemory",
v8_heap_stats.total_available_size());
writer->json_keyvalue("totalGlobalHandlesMemory",
v8_heap_stats.total_global_handles_size());
writer->json_keyvalue("usedGlobalHandlesMemory",
v8_heap_stats.used_global_handles_size());
writer->json_keyvalue("usedMemory", v8_heap_stats.used_heap_size());
writer->json_keyvalue("memoryLimit", v8_heap_stats.heap_size_limit());
writer->json_keyvalue("mallocedMemory", v8_heap_stats.malloced_memory());
writer->json_keyvalue("externalMemory", v8_heap_stats.external_memory());
writer->json_keyvalue("peakMallocedMemory",
v8_heap_stats.peak_malloced_memory());
writer->json_keyvalue("nativeContextCount",
v8_heap_stats.number_of_native_contexts());
writer->json_keyvalue("detachedContextCount",
v8_heap_stats.number_of_detached_contexts());
writer->json_keyvalue("doesZapGarbage", v8_heap_stats.does_zap_garbage());

writer->json_objectstart("heapSpaces");
// Loop through heap spaces
Expand Down
32 changes: 25 additions & 7 deletions test/common/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,32 @@ function _validateContent(report, fields = []) {

// Verify the format of the javascriptHeap section.
const heap = report.javascriptHeap;
const jsHeapFields = ['totalMemory', 'totalCommittedMemory', 'usedMemory',
'availableMemory', 'memoryLimit', 'heapSpaces'];
// See `PrintGCStatistics` in node_report.cc
const jsHeapFields = [
'totalMemory',
'executableMemory',
'totalCommittedMemory',
'availableMemory',
'totalGlobalHandlesMemory',
'usedGlobalHandlesMemory',
'usedMemory',
'memoryLimit',
'mallocedMemory',
'externalMemory',
'peakMallocedMemory',
'nativeContextCount',
'detachedContextCount',
'doesZapGarbage',
'heapSpaces',
];
checkForUnknownFields(heap, jsHeapFields);
assert(Number.isSafeInteger(heap.totalMemory));
assert(Number.isSafeInteger(heap.totalCommittedMemory));
assert(Number.isSafeInteger(heap.usedMemory));
assert(Number.isSafeInteger(heap.availableMemory));
assert(Number.isSafeInteger(heap.memoryLimit));
// Do not check `heapSpaces` here
for (let i = 0; i < jsHeapFields.length - 1; i++) {
assert(
Number.isSafeInteger(heap[jsHeapFields[i]]),
`heap.${jsHeapFields[i]} is not a safe integer`
);
}
assert(typeof heap.heapSpaces === 'object' && heap.heapSpaces !== null);
const heapSpaceFields = ['memorySize', 'committedMemory', 'capacity',
'used', 'available'];
Expand Down