diff options
author | vmarchaud <contact@vmarchaud.fr> | 2019-06-02 14:33:47 +0300 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2019-07-01 17:02:17 +0300 |
commit | 6271ef005eb311c819b7ab041e09f50e4155ec1e (patch) | |
tree | e16ef8aa0f1db3fcdcd6cd1405ddf4412da18a2d /src/node_process_methods.cc | |
parent | 20d099af7a1fc103ecfb9a4afe59fd2fdcbe7802 (diff) |
process: expose uv_rusage on process.resourcesUsage()
As discussed in https://github.com/nodejs/diagnostics/issues/161,
the core should expose important metrics about the runtime, this PR's
goal is to let user get the number of io request made, and lower level
mertrics like the page faults and context switches.
PR-URL: https://github.com/nodejs/node/pull/28018
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'src/node_process_methods.cc')
-rw-r--r-- | src/node_process_methods.cc | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/node_process_methods.cc b/src/node_process_methods.cc index b34cbf89b6c..3a2c1efd812 100644 --- a/src/node_process_methods.cc +++ b/src/node_process_methods.cc @@ -285,6 +285,38 @@ void GetActiveHandles(const FunctionCallbackInfo<Value>& args) { Array::New(env->isolate(), handle_v.data(), handle_v.size())); } +static void ResourceUsage(const FunctionCallbackInfo<Value>& args) { + Environment* env = Environment::GetCurrent(args); + + uv_rusage_t rusage; + int err = uv_getrusage(&rusage); + if (err) + return env->ThrowUVException(err, "uv_getrusage"); + + CHECK(args[0]->IsFloat64Array()); + Local<Float64Array> array = args[0].As<Float64Array>(); + CHECK_EQ(array->Length(), 16); + Local<ArrayBuffer> ab = array->Buffer(); + double* fields = static_cast<double*>(ab->GetContents().Data()); + + fields[0] = MICROS_PER_SEC * rusage.ru_utime.tv_sec + rusage.ru_utime.tv_usec; + fields[1] = MICROS_PER_SEC * rusage.ru_stime.tv_sec + rusage.ru_stime.tv_usec; + fields[2] = rusage.ru_maxrss; + fields[3] = rusage.ru_ixrss; + fields[4] = rusage.ru_idrss; + fields[5] = rusage.ru_isrss; + fields[6] = rusage.ru_minflt; + fields[7] = rusage.ru_majflt; + fields[8] = rusage.ru_nswap; + fields[9] = rusage.ru_inblock; + fields[10] = rusage.ru_oublock; + fields[11] = rusage.ru_msgsnd; + fields[12] = rusage.ru_msgrcv; + fields[13] = rusage.ru_nsignals; + fields[14] = rusage.ru_nvcsw; + fields[15] = rusage.ru_nivcsw; +} + #ifdef __POSIX__ static void DebugProcess(const FunctionCallbackInfo<Value>& args) { Environment* env = Environment::GetCurrent(args); @@ -426,6 +458,7 @@ static void InitializeProcessMethods(Local<Object> target, env->SetMethod(target, "cpuUsage", CPUUsage); env->SetMethod(target, "hrtime", Hrtime); env->SetMethod(target, "hrtimeBigInt", HrtimeBigInt); + env->SetMethod(target, "resourceUsage", ResourceUsage); env->SetMethod(target, "_getActiveRequests", GetActiveRequests); env->SetMethod(target, "_getActiveHandles", GetActiveHandles); |