From a865ea188e78fbb4918b7d6b8a9a912d60c8c660 Mon Sep 17 00:00:00 2001 From: Adrien Maret Date: Tue, 29 Dec 2020 15:36:41 +0100 Subject: [PATCH] process: add direct access to rss without iterating pages Accessing the rss value through memoryUsage() can be expensive because this method will also generate memory usage statistics by iterating on each page. This commit intend to offer a more direct access to rss value. Refs: #33384 --- doc/api/process.md | 22 ++++++++++++++++++++++ lib/internal/process/per_thread.js | 3 +++ src/node_process_methods.cc | 15 ++++++++++++++- test/parallel/test-memory-usage.js | 2 ++ 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/doc/api/process.md b/doc/api/process.md index 8f7a98503a6d48..6b72acd666c9a8 100644 --- a/doc/api/process.md +++ b/doc/api/process.md @@ -1589,6 +1589,28 @@ Will generate: When using [`Worker`][] threads, `rss` will be a value that is valid for the entire process, while the other fields will only refer to the current thread. +The `process.memoryUsage()` method iterate over each page to gather +informations about memory usage which can be slow depending on the +program memory allocations. + +## `process.memoryUsage.rss()` + +* Returns: {integer} + +The `process.memoryUsage.rss()` method returns an integer representing the +Resident Set Size (RSS) in bytes. + +The Resident Set Size, is the amount of space occupied in the main +memory device (that is a subset of the total allocated memory) for the +process, including all C++ and JavaScript objects and code. + +This is the same value as the one returned by `process.memoryUsage()`. + +```js +console.log(process.memoryUsage.rss()); +// 35655680 +``` + ## `process.nextTick(callback[, ...args])`