Skip to content

Commit

Permalink
src: extend HeapStatistics with new fields
Browse files Browse the repository at this point in the history
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: #8610
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
  • Loading branch information
gareth-ellis authored and addaleax committed Nov 22, 2016
1 parent 4517276 commit c4f33b4
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
14 changes: 13 additions & 1 deletion doc/api/v8.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ Returns an object with the following properties:
* `total_available_size` {number}
* `used_heap_size` {number}
* `heap_size_limit` {number}
* `malloced_memory` {number}
* `peak_malloced_memory` {number}
* `does_zap_garbage` {number}

`does_zap_garbage` is a 0/1 boolean, which signifies whether the `--zap_code_space`
option is enabled or not. This makes V8 overwrite heap garbage with a bit
pattern. The RSS footprint (resident memory set) gets bigger because it
continuously touches all heap pages and that makes them less likely to get
swapped out by the operating system.

For example:

Expand All @@ -32,7 +41,10 @@ For example:
total_physical_size: 7326976,
total_available_size: 1152656,
used_heap_size: 3476208,
heap_size_limit: 1535115264
heap_size_limit: 1535115264,
malloced_memory: 16384,
peak_malloced_memory: 1127496,
does_zap_garbage: 0
}
```

Expand Down
8 changes: 7 additions & 1 deletion lib/v8.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ const kTotalPhysicalSizeIndex = v8binding.kTotalPhysicalSizeIndex;
const kTotalAvailableSize = v8binding.kTotalAvailableSize;
const kUsedHeapSizeIndex = v8binding.kUsedHeapSizeIndex;
const kHeapSizeLimitIndex = v8binding.kHeapSizeLimitIndex;
const kDoesZapGarbageIndex = v8binding.kDoesZapGarbageIndex;
const kMallocedMemoryIndex = v8binding.kMallocedMemoryIndex;
const kPeakMallocedMemoryIndex = v8binding.kPeakMallocedMemoryIndex;

// Properties for heap space statistics buffer extraction.
const heapSpaceStatisticsBuffer =
Expand All @@ -49,7 +52,10 @@ exports.getHeapStatistics = function() {
'total_physical_size': buffer[kTotalPhysicalSizeIndex],
'total_available_size': buffer[kTotalAvailableSize],
'used_heap_size': buffer[kUsedHeapSizeIndex],
'heap_size_limit': buffer[kHeapSizeLimitIndex]
'heap_size_limit': buffer[kHeapSizeLimitIndex],
'malloced_memory': buffer[kMallocedMemoryIndex],
'peak_malloced_memory': buffer[kPeakMallocedMemoryIndex],
'does_zap_garbage': buffer[kDoesZapGarbageIndex]
};
};

Expand Down
5 changes: 4 additions & 1 deletion src/node_v8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ using v8::Value;
V(2, total_physical_size, kTotalPhysicalSizeIndex) \
V(3, total_available_size, kTotalAvailableSize) \
V(4, used_heap_size, kUsedHeapSizeIndex) \
V(5, heap_size_limit, kHeapSizeLimitIndex)
V(5, heap_size_limit, kHeapSizeLimitIndex) \
V(6, malloced_memory, kMallocedMemoryIndex) \
V(7, peak_malloced_memory, kPeakMallocedMemoryIndex) \
V(8, does_zap_garbage, kDoesZapGarbageIndex)

#define V(a, b, c) +1
static const size_t kHeapStatisticsPropertiesCount =
Expand Down
3 changes: 3 additions & 0 deletions test/parallel/test-v8-stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ var v8 = require('v8');

var s = v8.getHeapStatistics();
var keys = [
'does_zap_garbage',
'heap_size_limit',
'malloced_memory',
'peak_malloced_memory',
'total_available_size',
'total_heap_size',
'total_heap_size_executable',
Expand Down

0 comments on commit c4f33b4

Please sign in to comment.