GeezerVison is showing github.com — src,lib: optimize nodeTiming.uvMetricsInfo · nodejs/node@cfa4d96
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/perf/nodetiming.js +8-1Lines changed: 8 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -128,7 +128,14 @@ class PerformanceNodeTiming { | 128 | 128 | __proto__: null, | 129 | 129 | enumerable: true, | 130 | 130 | 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 | + }, | 132 | 139 | }, | 133 | 140 | }); | 134 | 141 | } | |
Collapse file Copy file name to clipboardExpand all lines: src/node_perf.cc +9-17Lines changed: 9 additions & 17 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 14 | 14 | namespace node { | 15 | 15 | namespace performance { | 16 | 16 |
| | 17 | +using v8::Array; | 17 | 18 | using v8::Context; | 18 | 19 | using v8::DontDelete; | 19 | 20 | using v8::Function; | @@ -264,26 +265,17 @@ void LoopIdleTime(const FunctionCallbackInfo<Value>& args) { | 264 | 265 |
| 265 | 266 | void UvMetricsInfo(const FunctionCallbackInfo<Value>& args) { | 266 | 267 | Environment* env = Environment::GetCurrent(args); | | 268 | + Isolate* isolate = env->isolate(); | 267 | 269 | uv_metrics_t metrics; | 268 | | - | 269 | 270 | // uv_metrics_info always return 0 | 270 | 271 | 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); | 287 | 279 | } | 288 | 280 |
| 289 | 281 | void CreateELDHistogram(const FunctionCallbackInfo<Value>& args) { | |
|