From 38e425d9bfe3e5fc728576f623fdedf27432f106 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Sat, 28 Nov 2009 16:31:29 +0100 Subject: [PATCH] Add V8 heap info to process.memoryUsage() --- doc/api.txt | 13 ++++++++++++- src/node.cc | 8 ++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/doc/api.txt b/doc/api.txt index cabe9ddec3..ed3cc5161d 100644 --- a/doc/api.txt +++ b/doc/api.txt @@ -110,7 +110,18 @@ The PID of the process. What platform you're running on. +"linux2"+, +"darwin"+, etc. +process.memoryUsage()+ :: -Returns the memory usage of the Node process: e.g. +{"rss":5828608,"vsize":3112529920}+ +Returns the memory usage of the Node process. It looks like this ++ +---------------------- +{ + "rss": 4935680, + "vsize": 41893888, + "heapTotal": 1826816, + "heapUsed": 650472 +} +---------------------- ++ ++heapTotal+ and +heapUsed+ refer to V8's memory usage. +process.exit(code=0)+:: Ends the process with the specified code. By default it exits with the diff --git a/src/node.cc b/src/node.cc index 7df8502801..e722fbe89c 100644 --- a/src/node.cc +++ b/src/node.cc @@ -513,6 +513,14 @@ v8::Handle MemoryUsage(const v8::Arguments& args) { info->Set(String::NewSymbol("rss"), Integer::NewFromUnsigned(rss)); info->Set(String::NewSymbol("vsize"), Integer::NewFromUnsigned(vsize)); + // V8 memory usage + HeapStatistics v8_heap_stats; + V8::GetHeapStatistics(&v8_heap_stats); + info->Set(String::NewSymbol("heapTotal"), + Integer::NewFromUnsigned(v8_heap_stats.total_heap_size())); + info->Set(String::NewSymbol("heapUsed"), + Integer::NewFromUnsigned(v8_heap_stats.used_heap_size())); + return scope.Close(info); #endif }