From e46b2e5e32319ced9a67c5f3f16804b54aa78ffa 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 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 PR-URL: https://github.com/nodejs/node/pull/34291 Reviewed-By: Gerhard Stöbich Reviewed-By: James M Snell --- doc/api/process.md | 22 ++++++++++++++++++++++ lib/internal/process/per_thread.js | 3 +++ src/node_process_methods.cc | 14 +++++++++++++- test/parallel/test-memory-usage.js | 2 ++ 4 files changed, 40 insertions(+), 1 deletion(-) diff --git a/doc/api/process.md b/doc/api/process.md index 6eaf5b511323c9..ca073b9ed56e8e 100644 --- a/doc/api/process.md +++ b/doc/api/process.md @@ -1610,6 +1610,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])`