diff --git a/lib/internal/perf/nodetiming.js b/lib/internal/perf/nodetiming.js index d19bc021263..a9e0c3f252c 100644 --- a/lib/internal/perf/nodetiming.js +++ b/lib/internal/perf/nodetiming.js @@ -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], + }; + }, }, }); } diff --git a/src/node_perf.cc b/src/node_perf.cc index a868b0e82e0..d8b26f5c845 100644 --- a/src/node_perf.cc +++ b/src/node_perf.cc @@ -14,6 +14,7 @@ namespace node { namespace performance { +using v8::Array; using v8::Context; using v8::DontDelete; using v8::Function; @@ -264,26 +265,17 @@ void LoopIdleTime(const FunctionCallbackInfo& args) { void UvMetricsInfo(const FunctionCallbackInfo& 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 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 data[] = { + Integer::New(isolate, metrics.loop_count), + Integer::New(isolate, metrics.events), + Integer::New(isolate, metrics.events_waiting), + }; + Local arr = Array::New(env->isolate(), data, arraysize(data)); + args.GetReturnValue().Set(arr); } void CreateELDHistogram(const FunctionCallbackInfo& args) {