From 30d60cf81c66d9a67464ff68d1109e14b7207f2a Mon Sep 17 00:00:00 2001 From: Ben Ripkens Date: Tue, 29 Dec 2015 11:54:35 +0100 Subject: [PATCH] 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 Reviewed-By: Trevor Norris Reviewed-By: Ben Noordhuis Reviewed-By: James M Snell --- doc/api/v8.md | 49 +++++++++++++++++++ lib/v8.js | 33 ++++++++++++- src/env-inl.h | 12 +++++ src/env.h | 4 ++ src/node_v8.cc | 87 +++++++++++++++++++++++++++++++++- test/parallel/test-v8-stats.js | 19 ++++++++ 6 files changed, 202 insertions(+), 2 deletions(-) diff --git a/doc/api/v8.md b/doc/api/v8.md index f74d76820c..8b8a78d121 100644 --- a/doc/api/v8.md +++ b/doc/api/v8.md @@ -24,6 +24,55 @@ Returns an object with the following properties } ``` +## getHeapSpaceStatistics() + +Returns statistics about the V8 heap spaces, i.e. the segments which make up +the V8 heap. Order of heap spaces nor availability of a heap space can be +guaranteed as the statistics are provided via the V8 `GetHeapSpaceStatistics` +function. + +Example result: + +``` +[ + { + "space_name": "new_space", + "space_size": 2063872, + "space_used_size": 951112, + "space_available_size": 80824, + "physical_space_size": 2063872 + }, + { + "space_name": "old_space", + "space_size": 3090560, + "space_used_size": 2493792, + "space_available_size": 0, + "physical_space_size": 3090560 + }, + { + "space_name": "code_space", + "space_size": 1260160, + "space_used_size": 644256, + "space_available_size": 960, + "physical_space_size": 1260160 + }, + { + "space_name": "map_space", + "space_size": 1094160, + "space_used_size": 201608, + "space_available_size": 0, + "physical_space_size": 1094160 + }, + { + "space_name": "large_object_space", + "space_size": 0, + "space_used_size": 0, + "space_available_size": 1490980608, + "physical_space_size": 0 + } +] +``` + ## setFlagsFromString(string)