summaryrefslogtreecommitdiff
path: root/lib/v8.js
diff options
context:
space:
mode:
authorBen Ripkens <bripkens.dev@gmail.com>2015-12-29 11:54:35 +0100
committercjihrig <cjihrig@gmail.com>2016-01-18 11:44:00 -0500
commit5f57005ec9eacbfc7855ec7c9e246f61da5a75ae (patch)
tree2daff450b026b0d18faa494888319db7d9048393 /lib/v8.js
parente65f1f7954fb364ab70063cdb374603c82f58385 (diff)
downloadandroid-node-v8-5f57005ec9eacbfc7855ec7c9e246f61da5a75ae.tar.gz
android-node-v8-5f57005ec9eacbfc7855ec7c9e246f61da5a75ae.tar.bz2
android-node-v8-5f57005ec9eacbfc7855ec7c9e246f61da5a75ae.zip
v8,src: expose statistics about heap spaces
Provide means to inspect information about the separate heap spaces via a callable API. This is helpful to analyze memory issues. Fixes: https://github.com/nodejs/node/issues/2079 PR-URL: https://github.com/nodejs/node/pull/4463 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib/v8.js')
-rw-r--r--lib/v8.js33
1 files changed, 32 insertions, 1 deletions
diff --git a/lib/v8.js b/lib/v8.js
index acadfa64e0..551b2ada98 100644
--- a/lib/v8.js
+++ b/lib/v8.js
@@ -16,9 +16,9 @@
const v8binding = process.binding('v8');
+// Properties for heap statistics buffer extraction.
const heapStatisticsBuffer =
new Uint32Array(v8binding.heapStatisticsArrayBuffer);
-
const kTotalHeapSizeIndex = v8binding.kTotalHeapSizeIndex;
const kTotalHeapSizeExecutableIndex = v8binding.kTotalHeapSizeExecutableIndex;
const kTotalPhysicalSizeIndex = v8binding.kTotalPhysicalSizeIndex;
@@ -26,6 +26,18 @@ const kTotalAvailableSize = v8binding.kTotalAvailableSize;
const kUsedHeapSizeIndex = v8binding.kUsedHeapSizeIndex;
const kHeapSizeLimitIndex = v8binding.kHeapSizeLimitIndex;
+// Properties for heap space statistics buffer extraction.
+const heapSpaceStatisticsBuffer =
+ new Uint32Array(v8binding.heapSpaceStatisticsArrayBuffer);
+const kHeapSpaces = v8binding.kHeapSpaces;
+const kNumberOfHeapSpaces = kHeapSpaces.length;
+const kHeapSpaceStatisticsPropertiesCount =
+ v8binding.kHeapSpaceStatisticsPropertiesCount;
+const kSpaceSizeIndex = v8binding.kSpaceSizeIndex;
+const kSpaceUsedSizeIndex = v8binding.kSpaceUsedSizeIndex;
+const kSpaceAvailableSizeIndex = v8binding.kSpaceAvailableSizeIndex;
+const kPhysicalSpaceSizeIndex = v8binding.kPhysicalSpaceSizeIndex;
+
exports.getHeapStatistics = function() {
const buffer = heapStatisticsBuffer;
@@ -42,3 +54,22 @@ exports.getHeapStatistics = function() {
};
exports.setFlagsFromString = v8binding.setFlagsFromString;
+
+exports.getHeapSpaceStatistics = function() {
+ const heapSpaceStatistics = new Array(kNumberOfHeapSpaces);
+ const buffer = heapSpaceStatisticsBuffer;
+ v8binding.updateHeapSpaceStatisticsArrayBuffer();
+
+ for (let i = 0; i < kNumberOfHeapSpaces; i++) {
+ const propertyOffset = i * kHeapSpaceStatisticsPropertiesCount;
+ heapSpaceStatistics[i] = {
+ space_name: kHeapSpaces[i],
+ space_size: buffer[propertyOffset + kSpaceSizeIndex],
+ space_used_size: buffer[propertyOffset + kSpaceUsedSizeIndex],
+ space_available_size: buffer[propertyOffset + kSpaceAvailableSizeIndex],
+ physical_space_size: buffer[propertyOffset + kPhysicalSpaceSizeIndex]
+ };
+ }
+
+ return heapSpaceStatistics;
+};