Skip to content

Commit e14fb2d

Browse files
RafaelGSSruyadorno
authored andcommitted
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 d1cb7af commit e14fb2d

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;
@@ -264,26 +265,17 @@ void LoopIdleTime(const FunctionCallbackInfo<Value>& args) {
264265

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

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

0 commit comments

Comments
 (0)