Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 23a573f

Browse filesBrowse files
indutnyMylesBorins
authored andcommitted
process: add process.memoryUsage.external
PR-URL: #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>
1 parent 2269d7d commit 23a573f
Copy full SHA for 23a573f

File tree

Expand file treeCollapse file tree

4 files changed

+21
-3
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+21
-3
lines changed
Open diff view settings
Collapse file

‎doc/api/process.md‎

Copy file name to clipboardExpand all lines: doc/api/process.md
+15-3Lines changed: 15 additions & 3 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -764,8 +764,16 @@ As with `require.main`, it will be `undefined` if there was no entry script.
764764
added: v0.1.16
765765
-->
766766

767-
Returns an object describing the memory usage of the Node.js process
768-
measured in bytes.
767+
* Returns: {Object}
768+
* `rss` {Integer}
769+
* `heapTotal` {Integer}
770+
* `heapUsed` {Integer}
771+
* `external` {Integer}
772+
773+
The `process.memoryUsage()` method returns an object describing the memory usage
774+
of the Node.js process measured in bytes.
775+
776+
For example, the code:
769777

770778
```js
771779
console.log(process.memoryUsage());
@@ -776,10 +784,14 @@ This will generate:
776784
```js
777785
{ rss: 4935680,
778786
heapTotal: 1826816,
779-
heapUsed: 650472 }
787+
heapUsed: 650472,
788+
external: 49879
789+
}
780790
```
781791

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

784796

785797
## process.nextTick(callback[, arg][, ...])
Collapse file

‎src/env.h‎

Copy file name to clipboardExpand all lines: src/env.h
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ namespace node {
9090
V(exponent_string, "exponent") \
9191
V(exports_string, "exports") \
9292
V(ext_key_usage_string, "ext_key_usage") \
93+
V(external_string, "external") \
9394
V(external_stream_string, "_externalStream") \
9495
V(family_string, "family") \
9596
V(fatal_exception_string, "_fatalException") \
Collapse file

‎src/node.cc‎

Copy file name to clipboardExpand all lines: src/node.cc
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2145,11 +2145,15 @@ void MemoryUsage(const FunctionCallbackInfo<Value>& args) {
21452145
Number::New(env->isolate(), v8_heap_stats.total_heap_size());
21462146
Local<Number> heap_used =
21472147
Number::New(env->isolate(), v8_heap_stats.used_heap_size());
2148+
Local<Number> external_mem =
2149+
Number::New(env->isolate(),
2150+
env->isolate()->AdjustAmountOfExternalAllocatedMemory(0));
21482151

21492152
Local<Object> info = Object::New(env->isolate());
21502153
info->Set(env->rss_string(), Number::New(env->isolate(), rss));
21512154
info->Set(env->heap_total_string(), heap_total);
21522155
info->Set(env->heap_used_string(), heap_used);
2156+
info->Set(env->external_string(), external_mem);
21532157

21542158
args.GetReturnValue().Set(info);
21552159
}
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-memory-usage.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ var r = process.memoryUsage();
66
assert.ok(r.rss > 0);
77
assert.ok(r.heapTotal > 0);
88
assert.ok(r.heapUsed > 0);
9+
assert.ok(r.external > 0);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.