Skip to content

Commit 6f47f53

Browse files
RafaelGSSmarco-ippolito
authored andcommittedJan 24, 2025
src,lib: optimize nodeTiming.uvMetricsInfo
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>
1 parent 4576d14 commit 6f47f53

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed
 

‎lib/internal/perf/nodetiming.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,14 @@ class PerformanceNodeTiming {
128128
__proto__: null,
129129
enumerable: true,
130130
configurable: true,
131-
get: uvMetricsInfo,
131+
get: () => {
132+
const metrics = uvMetricsInfo();
133+
return {
134+
loopCount: metrics[0],
135+
events: metrics[1],
136+
eventsWaiting: metrics[2],
137+
};
138+
},
132139
},
133140
});
134141
}

‎src/node_perf.cc

+9-17
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace node {
1515
namespace performance {
1616

17+
using v8::Array;
1718
using v8::Context;
1819
using v8::DontDelete;
1920
using v8::Function;
@@ -263,26 +264,17 @@ void LoopIdleTime(const FunctionCallbackInfo<Value>& args) {
263264

264265
void UvMetricsInfo(const FunctionCallbackInfo<Value>& args) {
265266
Environment* env = Environment::GetCurrent(args);
267+
Isolate* isolate = env->isolate();
266268
uv_metrics_t metrics;
267-
268269
// uv_metrics_info always return 0
269270
CHECK_EQ(uv_metrics_info(env->event_loop(), &metrics), 0);
270-
271-
Local<Object> obj = Object::New(env->isolate());
272-
obj->Set(env->context(),
273-
env->loop_count(),
274-
Integer::NewFromUnsigned(env->isolate(), metrics.loop_count))
275-
.Check();
276-
obj->Set(env->context(),
277-
env->events(),
278-
Integer::NewFromUnsigned(env->isolate(), metrics.events))
279-
.Check();
280-
obj->Set(env->context(),
281-
env->events_waiting(),
282-
Integer::NewFromUnsigned(env->isolate(), metrics.events_waiting))
283-
.Check();
284-
285-
args.GetReturnValue().Set(obj);
271+
Local<Value> data[] = {
272+
Integer::New(isolate, metrics.loop_count),
273+
Integer::New(isolate, metrics.events),
274+
Integer::New(isolate, metrics.events_waiting),
275+
};
276+
Local<Array> arr = Array::New(env->isolate(), data, arraysize(data));
277+
args.GetReturnValue().Set(arr);
286278
}
287279

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

0 commit comments

Comments
 (0)
Please sign in to comment.