Skip to content

Commit

Permalink
report: add more heap infos in process report
Browse files Browse the repository at this point in the history
PR-URL: #43116
Reviewed-By: Zeyu "Alex" Yang <himself65@outlook.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
  • Loading branch information
theanarkh authored and danielleadams committed Jun 13, 2022
1 parent 28c034d commit 201f3d7
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 13 deletions.
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,
"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

0 comments on commit 201f3d7

Please sign in to comment.