Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
src,lib: optimize nodeTiming.uvMetricsInfo
  • Loading branch information
RafaelGSS committed Oct 31, 2024
commit 4ff52971cfa4dcda11d01593b5d30d51d51121cc
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],
events_waiting: 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);
Comment thread
RafaelGSS marked this conversation as resolved.
}

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