Skip to content

Commit

Permalink
src,lib: optimize nodeTiming.uvMetricsInfo
Browse files Browse the repository at this point in the history
PR-URL: #55614
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: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
  • Loading branch information
RafaelGSS committed Nov 1, 2024
1 parent 3234dc6 commit cfa4d96
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
9 changes: 8 additions & 1 deletion lib/internal/perf/nodetiming.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,14 @@ class PerformanceNodeTiming {
__proto__: null,
enumerable: true,
configurable: true,
get: uvMetricsInfo,
get: () => {
const metrics = uvMetricsInfo();
return {
loopCount: metrics[0],
events: metrics[1],
eventsWaiting: metrics[2],
};
},
},
});
}
Expand Down
26 changes: 9 additions & 17 deletions src/node_perf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace node {
namespace performance {

using v8::Array;
using v8::Context;
using v8::DontDelete;
using v8::Function;
Expand Down Expand Up @@ -264,26 +265,17 @@ void LoopIdleTime(const FunctionCallbackInfo<Value>& args) {

void UvMetricsInfo(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
Isolate* isolate = env->isolate();
uv_metrics_t metrics;

// uv_metrics_info always return 0
CHECK_EQ(uv_metrics_info(env->event_loop(), &metrics), 0);

Local<Object> obj = Object::New(env->isolate());
obj->Set(env->context(),
env->loop_count(),
Integer::NewFromUnsigned(env->isolate(), metrics.loop_count))
.Check();
obj->Set(env->context(),
env->events(),
Integer::NewFromUnsigned(env->isolate(), metrics.events))
.Check();
obj->Set(env->context(),
env->events_waiting(),
Integer::NewFromUnsigned(env->isolate(), metrics.events_waiting))
.Check();

args.GetReturnValue().Set(obj);
Local<Value> data[] = {
Integer::New(isolate, metrics.loop_count),
Integer::New(isolate, metrics.events),
Integer::New(isolate, metrics.events_waiting),
};
Local<Array> arr = Array::New(env->isolate(), data, arraysize(data));
args.GetReturnValue().Set(arr);
}

void CreateELDHistogram(const FunctionCallbackInfo<Value>& args) {
Expand Down

0 comments on commit cfa4d96

Please sign in to comment.