Skip to content

Commit 440057e

Browse files
gareth-ellisaddaleax
authored andcommittedNov 20, 2016
src: extend HeapStatistics with new fields
src: Add does_zap_garbage, malloced_memory and peak_malloced_memory to v8 HeapStatistics Following nodejs/code-and-learn#56 I have exposed does_zap_garbage to HeapStatistics. The other fields, malloced_memory and peak_malloced_memory don't seem to be in the current version of v8 in master. PR-URL: nodejs#8610 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 31dac41 commit 440057e

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed
 

‎doc/api/v8.md

+13-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ Returns an object with the following properties:
2222
* `total_available_size` {number}
2323
* `used_heap_size` {number}
2424
* `heap_size_limit` {number}
25+
* `malloced_memory` {number}
26+
* `peak_malloced_memory` {number}
27+
* `does_zap_garbage` {number}
28+
29+
`does_zap_garbage` is a 0/1 boolean, which signifies whether the `--zap_code_space`
30+
option is enabled or not. This makes V8 overwrite heap garbage with a bit
31+
pattern. The RSS footprint (resident memory set) gets bigger because it
32+
continuously touches all heap pages and that makes them less likely to get
33+
swapped out by the operating system.
2534

2635
For example:
2736

@@ -32,7 +41,10 @@ For example:
3241
total_physical_size: 7326976,
3342
total_available_size: 1152656,
3443
used_heap_size: 3476208,
35-
heap_size_limit: 1535115264
44+
heap_size_limit: 1535115264,
45+
malloced_memory: 16384,
46+
peak_malloced_memory: 1127496,
47+
does_zap_garbage: 0
3648
}
3749
```
3850

‎lib/v8.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ const kTotalPhysicalSizeIndex = v8binding.kTotalPhysicalSizeIndex;
2525
const kTotalAvailableSize = v8binding.kTotalAvailableSize;
2626
const kUsedHeapSizeIndex = v8binding.kUsedHeapSizeIndex;
2727
const kHeapSizeLimitIndex = v8binding.kHeapSizeLimitIndex;
28+
const kDoesZapGarbageIndex = v8binding.kDoesZapGarbageIndex;
29+
const kMallocedMemoryIndex = v8binding.kMallocedMemoryIndex;
30+
const kPeakMallocedMemoryIndex = v8binding.kPeakMallocedMemoryIndex;
2831

2932
// Properties for heap space statistics buffer extraction.
3033
const heapSpaceStatisticsBuffer =
@@ -49,7 +52,10 @@ exports.getHeapStatistics = function() {
4952
'total_physical_size': buffer[kTotalPhysicalSizeIndex],
5053
'total_available_size': buffer[kTotalAvailableSize],
5154
'used_heap_size': buffer[kUsedHeapSizeIndex],
52-
'heap_size_limit': buffer[kHeapSizeLimitIndex]
55+
'heap_size_limit': buffer[kHeapSizeLimitIndex],
56+
'malloced_memory': buffer[kMallocedMemoryIndex],
57+
'peak_malloced_memory': buffer[kPeakMallocedMemoryIndex],
58+
'does_zap_garbage': buffer[kDoesZapGarbageIndex]
5359
};
5460
};
5561

‎src/node_v8.cc

+4-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ using v8::Value;
2828
V(2, total_physical_size, kTotalPhysicalSizeIndex) \
2929
V(3, total_available_size, kTotalAvailableSize) \
3030
V(4, used_heap_size, kUsedHeapSizeIndex) \
31-
V(5, heap_size_limit, kHeapSizeLimitIndex)
31+
V(5, heap_size_limit, kHeapSizeLimitIndex) \
32+
V(6, malloced_memory, kMallocedMemoryIndex) \
33+
V(7, peak_malloced_memory, kPeakMallocedMemoryIndex) \
34+
V(8, does_zap_garbage, kDoesZapGarbageIndex)
3235

3336
#define V(a, b, c) +1
3437
static const size_t kHeapStatisticsPropertiesCount =

‎test/parallel/test-v8-stats.js

+3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ var v8 = require('v8');
55

66
var s = v8.getHeapStatistics();
77
var keys = [
8+
'does_zap_garbage',
89
'heap_size_limit',
10+
'malloced_memory',
11+
'peak_malloced_memory',
912
'total_available_size',
1013
'total_heap_size',
1114
'total_heap_size_executable',

0 commit comments

Comments
 (0)
Please sign in to comment.