Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2013-11-16 01:19:31 +0400
committerTimothy J Fontaine <tjfontaine@gmail.com>2014-02-05 23:49:01 +0400
commitd23ac0ea9cb11c90a385a8235e5ae51b486ffcb7 (patch)
treea0a372570378d89495ec48555000a8bba0819cff /src/node_v8.cc
parent010222d39fbbf766b9c24a448a804d23928929f4 (diff)
src: add v8.getHeapStatistics() function
Add a one-to-one binding to v8::GetHeapStatistics(). Returns info on the current state of the JS heap, like total size and amount used.
Diffstat (limited to 'src/node_v8.cc')
-rw-r--r--src/node_v8.cc24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/node_v8.cc b/src/node_v8.cc
index 2fd276342d1..25f73d61832 100644
--- a/src/node_v8.cc
+++ b/src/node_v8.cc
@@ -35,6 +35,7 @@ using v8::GCCallbackFlags;
using v8::GCType;
using v8::Handle;
using v8::HandleScope;
+using v8::HeapStatistics;
using v8::Isolate;
using v8::Local;
using v8::Null;
@@ -178,6 +179,28 @@ void StartGarbageCollectionTracking(const FunctionCallbackInfo<Value>& args) {
}
+void GetHeapStatistics(const FunctionCallbackInfo<Value>& args) {
+ Isolate* isolate = args.GetIsolate();
+ HandleScope handle_scope(isolate);
+ Environment* env = Environment::GetCurrent(isolate);
+ HeapStatistics s;
+ isolate->GetHeapStatistics(&s);
+ Local<Object> info = Object::New();
+ // TODO(trevnorris): Setting many object properties in C++ is a significant
+ // performance hit. Redo this to pass the results to JS and create/set the
+ // properties there.
+#define V(name) \
+ info->Set(env->name ## _string(), Uint32::NewFromUnsigned(s.name(), isolate))
+ V(total_heap_size);
+ V(total_heap_size_executable);
+ V(total_physical_size);
+ V(used_heap_size);
+ V(heap_size_limit);
+#undef V
+ args.GetReturnValue().Set(info);
+}
+
+
void StopGarbageCollectionTracking(const FunctionCallbackInfo<Value>& args) {
HandleScope handle_scope(args.GetIsolate());
Environment::GetCurrent(args.GetIsolate())->StopGarbageCollectionTracking();
@@ -193,6 +216,7 @@ void InitializeV8Bindings(Handle<Object> target,
NODE_SET_METHOD(target,
"stopGarbageCollectionTracking",
StopGarbageCollectionTracking);
+ NODE_SET_METHOD(target, "getHeapStatistics", GetHeapStatistics);
}
} // namespace node