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>
v4.x
Fedor Indutny 8 years ago
committed by Myles Borins
parent
commit
23a573f7cb
No known key found for this signature in database GPG Key ID: 933B01F40B5CA946
  1. 18
      doc/api/process.md
  2. 1
      src/env.h
  3. 4
      src/node.cc
  4. 1
      test/parallel/test-memory-usage.js

18
doc/api/process.md

@ -764,8 +764,16 @@ As with `require.main`, it will be `undefined` if there was no entry script.
added: v0.1.16
-->
Returns an object describing the memory usage of the Node.js process
measured in bytes.
* Returns: {Object}
* `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.
For example, the code:
```js
console.log(process.memoryUsage());
@ -776,10 +784,14 @@ This will generate:
```js
{ 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[, arg][, ...])

1
src/env.h

@ -90,6 +90,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

@ -2145,11 +2145,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