Browse Source

process: add `process.memoryUsage.external`

PR-URL: https://github.com/nodejs/node/pull/9587
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
v7.x
Fedor Indutny 8 years ago
committed by Anna Henningsen
parent
commit
163397a206
No known key found for this signature in database GPG Key ID: D8B9F5AEAE84E4CF
  1. 6
      doc/api/process.md
  2. 1
      src/env.h
  3. 4
      src/node.cc
  4. 1
      test/parallel/test-memory-usage.js

6
doc/api/process.md

@ -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.
@ -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

1
src/env.h

@ -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") \

4
src/node.cc

@ -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);
}

1
test/parallel/test-memory-usage.js

@ -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);

Loading…
Cancel
Save