Skip to content

Commit 38e425d

Browse files
committed
Add V8 heap info to process.memoryUsage()
1 parent 8a58e83 commit 38e425d

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

doc/api.txt

+12-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,18 @@ The PID of the process.
110110
What platform you're running on. +"linux2"+, +"darwin"+, etc.
111111

112112
+process.memoryUsage()+ ::
113-
Returns the memory usage of the Node process: e.g. +{"rss":5828608,"vsize":3112529920}+
113+
Returns the memory usage of the Node process. It looks like this
114+
+
115+
----------------------
116+
{
117+
"rss": 4935680,
118+
"vsize": 41893888,
119+
"heapTotal": 1826816,
120+
"heapUsed": 650472
121+
}
122+
----------------------
123+
+
124+
+heapTotal+ and +heapUsed+ refer to V8's memory usage.
114125

115126
+process.exit(code=0)+::
116127
Ends the process with the specified code. By default it exits with the

src/node.cc

+8
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,14 @@ v8::Handle<v8::Value> MemoryUsage(const v8::Arguments& args) {
513513
info->Set(String::NewSymbol("rss"), Integer::NewFromUnsigned(rss));
514514
info->Set(String::NewSymbol("vsize"), Integer::NewFromUnsigned(vsize));
515515

516+
// V8 memory usage
517+
HeapStatistics v8_heap_stats;
518+
V8::GetHeapStatistics(&v8_heap_stats);
519+
info->Set(String::NewSymbol("heapTotal"),
520+
Integer::NewFromUnsigned(v8_heap_stats.total_heap_size()));
521+
info->Set(String::NewSymbol("heapUsed"),
522+
Integer::NewFromUnsigned(v8_heap_stats.used_heap_size()));
523+
516524
return scope.Close(info);
517525
#endif
518526
}

0 commit comments

Comments
 (0)