Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTrevor Norris <trev.norris@gmail.com>2020-08-25 22:36:37 +0300
committerRich Trott <rtrott@gmail.com>2020-08-29 17:02:31 +0300
commit589b2a1244da2f04843652bda97ef55397cdf5b7 (patch)
tree7b4e1c235a42fa5e0db6ff00c6a19a32238a952a /src
parent47f4080db4c16d6433be7f16e67fccef020c2e5d (diff)
perf_hooks: add idleTime and event loop util
Use uv_metrics_idle_time() to return a high resolution millisecond timer of the amount of time the event loop has been idle since it was initialized. Include performance.eventLoopUtilization() API to handle the math of calculating the idle and active times. This has been added to prevent accidental miscalculations of the event loop utilization. Such as not taking into consideration offsetting nodeTiming.loopStart or timing differences when being called from a Worker thread. PR-URL: https://github.com/nodejs/node/pull/34938 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Adrian Estrada <edsadr@gmail.com> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
Diffstat (limited to 'src')
-rw-r--r--src/node.cc1
-rw-r--r--src/node_perf.cc8
-rw-r--r--src/node_worker.cc1
3 files changed, 10 insertions, 0 deletions
diff --git a/src/node.cc b/src/node.cc
index d68c6d8d148..dd2cd0db75d 100644
--- a/src/node.cc
+++ b/src/node.cc
@@ -1079,6 +1079,7 @@ int Start(int argc, char** argv) {
env_info = NodeMainInstance::GetEnvSerializeInfo();
}
}
+ uv_loop_configure(uv_default_loop(), UV_METRICS_IDLE_TIME);
NodeMainInstance main_instance(&params,
uv_default_loop(),
diff --git a/src/node_perf.cc b/src/node_perf.cc
index d71afc2d81c..5fa4eabc993 100644
--- a/src/node_perf.cc
+++ b/src/node_perf.cc
@@ -440,6 +440,13 @@ void Notify(const FunctionCallbackInfo<Value>& args) {
}
}
+// Return idle time of the event loop
+void LoopIdleTime(const FunctionCallbackInfo<Value>& args) {
+ Environment* env = Environment::GetCurrent(args);
+ uint64_t idle_time = uv_metrics_idle_time(env->event_loop());
+ args.GetReturnValue().Set(1.0 * idle_time / 1e6);
+}
+
// Event Loop Timing Histogram
namespace {
@@ -629,6 +636,7 @@ void Initialize(Local<Object> target,
"removeGarbageCollectionTracking",
RemoveGarbageCollectionTracking);
env->SetMethod(target, "notify", Notify);
+ env->SetMethod(target, "loopIdleTime", LoopIdleTime);
Local<Object> constants = Object::New(isolate);
diff --git a/src/node_worker.cc b/src/node_worker.cc
index 2b7cc156db9..b3dd29bf9fb 100644
--- a/src/node_worker.cc
+++ b/src/node_worker.cc
@@ -135,6 +135,7 @@ class WorkerThreadData {
return;
}
loop_init_failed_ = false;
+ uv_loop_configure(&loop_, UV_METRICS_IDLE_TIME);
std::shared_ptr<ArrayBufferAllocator> allocator =
ArrayBufferAllocator::Create();