src,lib: add constrainedMemory API for process · nodejs/node@f09b838 · GitHub
Skip to content

Commit f09b838

Browse files
theanarkhjuanarbol
authored andcommitted
src,lib: add constrainedMemory API for process
PR-URL: #46218 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Darshan Sen <raisinten@gmail.com>
1 parent 116a336 commit f09b838

4 files changed

Lines changed: 40 additions & 0 deletions

File tree

doc/api/process.md

Lines changed: 18 additions & 0 deletions

lib/internal/bootstrap/node.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ const rawMethods = internalBinding('process_methods');
200200
process.cpuUsage = wrapped.cpuUsage;
201201
process.resourceUsage = wrapped.resourceUsage;
202202
process.memoryUsage = wrapped.memoryUsage;
203+
process.constrainedMemory = rawMethods.constrainedMemory;
203204
process.kill = wrapped.kill;
204205
process.exit = wrapped.exit;
205206

src/node_process_methods.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,13 @@ static void MemoryUsage(const FunctionCallbackInfo<Value>& args) {
206206
: static_cast<double>(array_buffer_allocator->total_mem_usage());
207207
}
208208

209+
static void GetConstrainedMemory(const FunctionCallbackInfo<Value>& args) {
210+
uint64_t value = uv_get_constrained_memory();
211+
if (value != 0) {
212+
args.GetReturnValue().Set(static_cast<double>(value));
213+
}
214+
}
215+
209216
void RawDebug(const FunctionCallbackInfo<Value>& args) {
210217
CHECK(args.Length() == 1 && args[0]->IsString() &&
211218
"must be called with a single string");
@@ -577,6 +584,7 @@ static void Initialize(Local<Object> target,
577584

578585
SetMethod(context, target, "umask", Umask);
579586
SetMethod(context, target, "memoryUsage", MemoryUsage);
587+
SetMethod(context, target, "constrainedMemory", GetConstrainedMemory);
580588
SetMethod(context, target, "rss", Rss);
581589
SetMethod(context, target, "cpuUsage", CPUUsage);
582590
SetMethod(context, target, "resourceUsage", ResourceUsage);
@@ -607,6 +615,7 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
607615
registry->Register(Umask);
608616
registry->Register(RawDebug);
609617
registry->Register(MemoryUsage);
618+
registry->Register(GetConstrainedMemory);
610619
registry->Register(Rss);
611620
registry->Register(CPUUsage);
612621
registry->Register(ResourceUsage);
Lines changed: 12 additions & 0 deletions

0 commit comments

Comments
 (0)