diff options
author | Kyle Farnung <kfarnung@microsoft.com> | 2018-01-22 22:43:35 +0300 |
---|---|---|
committer | Kyle Farnung <kfarnung@microsoft.com> | 2018-01-25 04:29:45 +0300 |
commit | be2cbccf003d110cad00317090072788021efa56 (patch) | |
tree | 6a5431d3abcd80b1b7a13335988f22b34df698e8 /src/node_perf.cc | |
parent | 142d6237b6b24d80c96fd2c68be471d29bb079e3 (diff) |
http2,perf_hooks: perf state using AliasedBuffer
Update performance_state to use AliasedBuffer and update usage sites.
PR-URL: https://github.com/nodejs/node/pull/18300
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/node_perf.cc')
-rw-r--r-- | src/node_perf.cc | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/src/node_perf.cc b/src/node_perf.cc index 34e6a35000e..4c3dfbe4eb7 100644 --- a/src/node_perf.cc +++ b/src/node_perf.cc @@ -85,9 +85,9 @@ void PerformanceEntry::Notify(Environment* env, PerformanceEntryType type, Local<Value> object) { Context::Scope scope(env->context()); - uint32_t* observers = env->performance_state()->observers; - if (observers != nullptr && - type != NODE_PERFORMANCE_ENTRY_TYPE_INVALID && + AliasedBuffer<uint32_t, v8::Uint32Array>& observers = + env->performance_state()->observers; + if (type != NODE_PERFORMANCE_ENTRY_TYPE_INVALID && observers[type]) { node::MakeCallback(env->isolate(), env->process_object(), @@ -130,7 +130,8 @@ void Measure(const FunctionCallbackInfo<Value>& args) { Utf8Value startMark(env->isolate(), args[1]); Utf8Value endMark(env->isolate(), args[2]); - double* milestones = env->performance_state()->milestones; + AliasedBuffer<double, v8::Float64Array>& milestones = + env->performance_state()->milestones; uint64_t startTimestamp = timeOrigin; uint64_t start = GetPerformanceMark(env, *startMark); @@ -165,7 +166,8 @@ void Measure(const FunctionCallbackInfo<Value>& args) { void MarkMilestone(const FunctionCallbackInfo<Value>& args) { Environment* env = Environment::GetCurrent(args); Local<Context> context = env->context(); - double* milestones = env->performance_state()->milestones; + AliasedBuffer<double, v8::Float64Array>& milestones = + env->performance_state()->milestones; PerformanceMilestone milestone = static_cast<PerformanceMilestone>( args[0]->Int32Value(context).ToChecked()); @@ -187,7 +189,8 @@ void PerformanceGCCallback(Environment* env, void* ptr) { HandleScope scope(env->isolate()); Local<Context> context = env->context(); - uint32_t* observers = env->performance_state()->observers; + AliasedBuffer<uint32_t, v8::Uint32Array>& observers = + env->performance_state()->observers; if (observers[NODE_PERFORMANCE_ENTRY_TYPE_GC]) { Local<Object> obj = entry->ToObject(); v8::PropertyAttribute attr = @@ -289,8 +292,8 @@ void TimerFunctionCall(const FunctionCallbackInfo<Value>& args) { args.GetReturnValue().Set(ret.ToLocalChecked()); } - - uint32_t* observers = env->performance_state()->observers; + AliasedBuffer<uint32_t, v8::Uint32Array>& observers = + env->performance_state()->observers; if (!observers[NODE_PERFORMANCE_ENTRY_TYPE_FUNCTION]) return; @@ -323,16 +326,12 @@ void Init(Local<Object> target, performance_state* state = env->performance_state(); auto state_ab = ArrayBuffer::New(isolate, state, sizeof(*state)); - #define SET_STATE_TYPEDARRAY(name, type, field) \ - target->Set(context, \ - FIXED_ONE_BYTE_STRING(isolate, (name)), \ - type::New(state_ab, \ - offsetof(performance_state, field), \ - arraysize(state->field))) \ - .FromJust() - SET_STATE_TYPEDARRAY("observerCounts", v8::Uint32Array, observers); - SET_STATE_TYPEDARRAY("milestones", v8::Float64Array, milestones); - #undef SET_STATE_TYPEDARRAY + target->Set(context, + FIXED_ONE_BYTE_STRING(isolate, "observerCounts"), + state->observers.GetJSArray()).FromJust(); + target->Set(context, + FIXED_ONE_BYTE_STRING(isolate, "milestones"), + state->milestones.GetJSArray()).FromJust(); Local<String> performanceEntryString = FIXED_ONE_BYTE_STRING(isolate, "PerformanceEntry"); |