Skip to content

Commit

Permalink
process: add process.memoryUsage.external
Browse files Browse the repository at this point in the history
PR-URL: #9587
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Johan Bergström <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Roman Reiss <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
  • Loading branch information
indutny authored and addaleax committed Nov 22, 2016
1 parent d83cb48 commit 163397a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion doc/api/process.md
Original file line number Diff line number Diff line change
Expand Up @@ -1175,6 +1175,7 @@ added: v0.1.16
* `rss` {Integer}
* `heapTotal` {Integer}
* `heapUsed` {Integer}
* `external` {Integer}

The `process.memoryUsage()` method returns an object describing the memory usage
of the Node.js process measured in bytes.
Expand All @@ -1191,11 +1192,14 @@ Will generate:
{
rss: 4935680,
heapTotal: 1826816,
heapUsed: 650472
heapUsed: 650472,
external: 49879
}
```

`heapTotal` and `heapUsed` refer to V8's memory usage.
`external` refers to the memory usage of C++ objects bound to JavaScript
objects managed by V8.

## process.nextTick(callback[, ...args])
<!-- YAML
Expand Down
1 change: 1 addition & 0 deletions src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ namespace node {
V(exponent_string, "exponent") \
V(exports_string, "exports") \
V(ext_key_usage_string, "ext_key_usage") \
V(external_string, "external") \
V(external_stream_string, "_externalStream") \
V(family_string, "family") \
V(fatal_exception_string, "_fatalException") \
Expand Down
4 changes: 4 additions & 0 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2247,11 +2247,15 @@ void MemoryUsage(const FunctionCallbackInfo<Value>& args) {
Number::New(env->isolate(), v8_heap_stats.total_heap_size());
Local<Number> heap_used =
Number::New(env->isolate(), v8_heap_stats.used_heap_size());
Local<Number> external_mem =
Number::New(env->isolate(),
env->isolate()->AdjustAmountOfExternalAllocatedMemory(0));

Local<Object> info = Object::New(env->isolate());
info->Set(env->rss_string(), Number::New(env->isolate(), rss));
info->Set(env->heap_total_string(), heap_total);
info->Set(env->heap_used_string(), heap_used);
info->Set(env->external_string(), external_mem);

args.GetReturnValue().Set(info);
}
Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-memory-usage.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ var r = process.memoryUsage();
assert.ok(r.rss > 0);
assert.ok(r.heapTotal > 0);
assert.ok(r.heapUsed > 0);
assert.ok(r.external > 0);

0 comments on commit 163397a

Please sign in to comment.