diff options
author | Adrien Maret <adrien@maret.email> | 2020-12-29 17:36:41 +0300 |
---|---|---|
committer | Node.js GitHub Bot <github-bot@iojs.org> | 2021-01-03 16:16:36 +0300 |
commit | 83ab5433ff2d5f4895d0275ae2a264bc4bb977a7 (patch) | |
tree | 7f0cfdf7bc6552dabc7abee037ed76dff6af96c3 /src/node_process_methods.cc | |
parent | d548f4d1164a5dc9e1390fcaaafbbf2feddaf28e (diff) |
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
PR-URL: https://github.com/nodejs/node/pull/34291
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/node_process_methods.cc')
-rw-r--r-- | src/node_process_methods.cc | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/node_process_methods.cc b/src/node_process_methods.cc index 40164fc990e..2c303a7693b 100644 --- a/src/node_process_methods.cc +++ b/src/node_process_methods.cc @@ -172,7 +172,7 @@ static void Kill(const FunctionCallbackInfo<Value>& args) { args.GetReturnValue().Set(err); } -static void MemoryUsage(const FunctionCallbackInfo<Value>& args) { +static void Rss(const FunctionCallbackInfo<Value>& args) { Environment* env = Environment::GetCurrent(args); size_t rss; @@ -180,6 +180,12 @@ static void MemoryUsage(const FunctionCallbackInfo<Value>& args) { if (err) return env->ThrowUVException(err, "uv_resident_set_memory"); + args.GetReturnValue().Set(static_cast<double>(rss)); +} + +static void MemoryUsage(const FunctionCallbackInfo<Value>& args) { + Environment* env = Environment::GetCurrent(args); + Isolate* isolate = env->isolate(); // V8 memory usage HeapStatistics v8_heap_stats; @@ -192,6 +198,11 @@ static void MemoryUsage(const FunctionCallbackInfo<Value>& args) { Local<ArrayBuffer> ab = get_fields_array_buffer(args, 0, 5); double* fields = static_cast<double*>(ab->GetBackingStore()->Data()); + size_t rss; + int err = uv_resident_set_memory(&rss); + if (err) + return env->ThrowUVException(err, "uv_resident_set_memory"); + fields[0] = rss; fields[1] = v8_heap_stats.total_heap_size(); fields[2] = v8_heap_stats.used_heap_size(); @@ -542,6 +553,7 @@ static void InitializeProcessMethods(Local<Object> target, env->SetMethod(target, "umask", Umask); env->SetMethod(target, "_rawDebug", RawDebug); env->SetMethod(target, "memoryUsage", MemoryUsage); + env->SetMethod(target, "rss", Rss); env->SetMethod(target, "cpuUsage", CPUUsage); env->SetMethod(target, "resourceUsage", ResourceUsage); @@ -568,6 +580,7 @@ void RegisterProcessMethodsExternalReferences( registry->Register(Umask); registry->Register(RawDebug); registry->Register(MemoryUsage); + registry->Register(Rss); registry->Register(CPUUsage); registry->Register(ResourceUsage); |