mirror of
https://github.com/nodejs/node.git
synced 2026-11-25 23:01:06 -05:00
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>
This commit is contained in:
1 parent
142d6237b6
commit
be2cbccf00
5 files changed
+50
-28
No files matched your search
+2
-3
@@ -344,7 +344,7 @@ inline Environment::Environment(IsolateData* isolate_data,
|
|||||||
AssignToContext(context, ContextInfo(""));
|
AssignToContext(context, ContextInfo(""));
|
||||||
|
|
||||||
destroy_async_id_list_.reserve(512);
|
destroy_async_id_list_.reserve(512);
|
||||||
performance_state_ = Calloc<performance::performance_state>(1);
|
performance_state_.reset(new performance::performance_state(isolate()));
|
||||||
performance_state_->milestones[
|
performance_state_->milestones[
|
||||||
performance::NODE_PERFORMANCE_MILESTONE_ENVIRONMENT] =
|
performance::NODE_PERFORMANCE_MILESTONE_ENVIRONMENT] =
|
||||||
PERFORMANCE_NOW();
|
PERFORMANCE_NOW();
|
||||||
@@ -377,7 +377,6 @@ inline Environment::~Environment() {
|
|||||||
delete[] heap_statistics_buffer_;
|
delete[] heap_statistics_buffer_;
|
||||||
delete[] heap_space_statistics_buffer_;
|
delete[] heap_space_statistics_buffer_;
|
||||||
delete[] http_parser_buffer_;
|
delete[] http_parser_buffer_;
|
||||||
free(performance_state_);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline v8::Isolate* Environment::isolate() const {
|
inline v8::Isolate* Environment::isolate() const {
|
||||||
@@ -583,7 +582,7 @@ void Environment::SetUnrefImmediate(native_immediate_callback cb,
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline performance::performance_state* Environment::performance_state() {
|
inline performance::performance_state* Environment::performance_state() {
|
||||||
return performance_state_;
|
return performance_state_.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::map<std::string, uint64_t>* Environment::performance_marks() {
|
inline std::map<std::string, uint64_t>* Environment::performance_marks() {
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ struct nghttp2_rcbuf;
|
|||||||
namespace node {
|
namespace node {
|
||||||
|
|
||||||
namespace performance {
|
namespace performance {
|
||||||
struct performance_state;
|
class performance_state;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace loader {
|
namespace loader {
|
||||||
@@ -758,7 +758,7 @@ class Environment {
|
|||||||
|
|
||||||
int should_not_abort_scope_counter_ = 0;
|
int should_not_abort_scope_counter_ = 0;
|
||||||
|
|
||||||
performance::performance_state* performance_state_ = nullptr;
|
std::unique_ptr<performance::performance_state> performance_state_;
|
||||||
std::map<std::string, uint64_t> performance_marks_;
|
std::map<std::string, uint64_t> performance_marks_;
|
||||||
|
|
||||||
#if HAVE_INSPECTOR
|
#if HAVE_INSPECTOR
|
||||||
|
|||||||
+2
-1
@@ -554,7 +554,8 @@ Http2Session::~Http2Session() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline bool HasHttp2Observer(Environment* env) {
|
inline bool HasHttp2Observer(Environment* env) {
|
||||||
uint32_t* observers = env->performance_state()->observers;
|
AliasedBuffer<uint32_t, v8::Uint32Array>& observers =
|
||||||
|
env->performance_state()->observers;
|
||||||
return observers[performance::NODE_PERFORMANCE_ENTRY_TYPE_HTTP2] != 0;
|
return observers[performance::NODE_PERFORMANCE_ENTRY_TYPE_HTTP2] != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+17
-18
@@ -85,9 +85,9 @@ void PerformanceEntry::Notify(Environment* env,
|
|||||||
PerformanceEntryType type,
|
PerformanceEntryType type,
|
||||||
Local<Value> object) {
|
Local<Value> object) {
|
||||||
Context::Scope scope(env->context());
|
Context::Scope scope(env->context());
|
||||||
uint32_t* observers = env->performance_state()->observers;
|
AliasedBuffer<uint32_t, v8::Uint32Array>& observers =
|
||||||
if (observers != nullptr &&
|
env->performance_state()->observers;
|
||||||
type != NODE_PERFORMANCE_ENTRY_TYPE_INVALID &&
|
if (type != NODE_PERFORMANCE_ENTRY_TYPE_INVALID &&
|
||||||
observers[type]) {
|
observers[type]) {
|
||||||
node::MakeCallback(env->isolate(),
|
node::MakeCallback(env->isolate(),
|
||||||
env->process_object(),
|
env->process_object(),
|
||||||
@@ -130,7 +130,8 @@ void Measure(const FunctionCallbackInfo<Value>& args) {
|
|||||||
Utf8Value startMark(env->isolate(), args[1]);
|
Utf8Value startMark(env->isolate(), args[1]);
|
||||||
Utf8Value endMark(env->isolate(), args[2]);
|
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 startTimestamp = timeOrigin;
|
||||||
uint64_t start = GetPerformanceMark(env, *startMark);
|
uint64_t start = GetPerformanceMark(env, *startMark);
|
||||||
@@ -165,7 +166,8 @@ void Measure(const FunctionCallbackInfo<Value>& args) {
|
|||||||
void MarkMilestone(const FunctionCallbackInfo<Value>& args) {
|
void MarkMilestone(const FunctionCallbackInfo<Value>& args) {
|
||||||
Environment* env = Environment::GetCurrent(args);
|
Environment* env = Environment::GetCurrent(args);
|
||||||
Local<Context> context = env->context();
|
Local<Context> context = env->context();
|
||||||
double* milestones = env->performance_state()->milestones;
|
AliasedBuffer<double, v8::Float64Array>& milestones =
|
||||||
|
env->performance_state()->milestones;
|
||||||
PerformanceMilestone milestone =
|
PerformanceMilestone milestone =
|
||||||
static_cast<PerformanceMilestone>(
|
static_cast<PerformanceMilestone>(
|
||||||
args[0]->Int32Value(context).ToChecked());
|
args[0]->Int32Value(context).ToChecked());
|
||||||
@@ -187,7 +189,8 @@ void PerformanceGCCallback(Environment* env, void* ptr) {
|
|||||||
HandleScope scope(env->isolate());
|
HandleScope scope(env->isolate());
|
||||||
Local<Context> context = env->context();
|
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]) {
|
if (observers[NODE_PERFORMANCE_ENTRY_TYPE_GC]) {
|
||||||
Local<Object> obj = entry->ToObject();
|
Local<Object> obj = entry->ToObject();
|
||||||
v8::PropertyAttribute attr =
|
v8::PropertyAttribute attr =
|
||||||
@@ -289,8 +292,8 @@ void TimerFunctionCall(const FunctionCallbackInfo<Value>& args) {
|
|||||||
args.GetReturnValue().Set(ret.ToLocalChecked());
|
args.GetReturnValue().Set(ret.ToLocalChecked());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AliasedBuffer<uint32_t, v8::Uint32Array>& observers =
|
||||||
uint32_t* observers = env->performance_state()->observers;
|
env->performance_state()->observers;
|
||||||
if (!observers[NODE_PERFORMANCE_ENTRY_TYPE_FUNCTION])
|
if (!observers[NODE_PERFORMANCE_ENTRY_TYPE_FUNCTION])
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -323,16 +326,12 @@ void Init(Local<Object> target,
|
|||||||
performance_state* state = env->performance_state();
|
performance_state* state = env->performance_state();
|
||||||
auto state_ab = ArrayBuffer::New(isolate, state, sizeof(*state));
|
auto state_ab = ArrayBuffer::New(isolate, state, sizeof(*state));
|
||||||
|
|
||||||
#define SET_STATE_TYPEDARRAY(name, type, field) \
|
target->Set(context,
|
||||||
target->Set(context, \
|
FIXED_ONE_BYTE_STRING(isolate, "observerCounts"),
|
||||||
FIXED_ONE_BYTE_STRING(isolate, (name)), \
|
state->observers.GetJSArray()).FromJust();
|
||||||
type::New(state_ab, \
|
target->Set(context,
|
||||||
offsetof(performance_state, field), \
|
FIXED_ONE_BYTE_STRING(isolate, "milestones"),
|
||||||
arraysize(state->field))) \
|
state->milestones.GetJSArray()).FromJust();
|
||||||
.FromJust()
|
|
||||||
SET_STATE_TYPEDARRAY("observerCounts", v8::Uint32Array, observers);
|
|
||||||
SET_STATE_TYPEDARRAY("milestones", v8::Float64Array, milestones);
|
|
||||||
#undef SET_STATE_TYPEDARRAY
|
|
||||||
|
|
||||||
Local<String> performanceEntryString =
|
Local<String> performanceEntryString =
|
||||||
FIXED_ONE_BYTE_STRING(isolate, "PerformanceEntry");
|
FIXED_ONE_BYTE_STRING(isolate, "PerformanceEntry");
|
||||||
|
|||||||
+27
-4
@@ -61,10 +61,33 @@ enum PerformanceEntryType {
|
|||||||
node::performance::NODE_PERFORMANCE_MILESTONE_##n); \
|
node::performance::NODE_PERFORMANCE_MILESTONE_##n); \
|
||||||
} while (0);
|
} while (0);
|
||||||
|
|
||||||
struct performance_state {
|
class performance_state {
|
||||||
// doubles first so that they are always sizeof(double)-aligned
|
public:
|
||||||
double milestones[NODE_PERFORMANCE_MILESTONE_INVALID];
|
explicit performance_state(v8::Isolate* isolate) :
|
||||||
uint32_t observers[NODE_PERFORMANCE_ENTRY_TYPE_INVALID];
|
root(
|
||||||
|
isolate,
|
||||||
|
sizeof(performance_state_internal)),
|
||||||
|
milestones(
|
||||||
|
isolate,
|
||||||
|
offsetof(performance_state_internal, milestones),
|
||||||
|
NODE_PERFORMANCE_MILESTONE_INVALID,
|
||||||
|
root),
|
||||||
|
observers(
|
||||||
|
isolate,
|
||||||
|
offsetof(performance_state_internal, observers),
|
||||||
|
NODE_PERFORMANCE_ENTRY_TYPE_INVALID,
|
||||||
|
root) {}
|
||||||
|
|
||||||
|
AliasedBuffer<uint8_t, v8::Uint8Array> root;
|
||||||
|
AliasedBuffer<double, v8::Float64Array> milestones;
|
||||||
|
AliasedBuffer<uint32_t, v8::Uint32Array> observers;
|
||||||
|
|
||||||
|
private:
|
||||||
|
struct performance_state_internal {
|
||||||
|
// doubles first so that they are always sizeof(double)-aligned
|
||||||
|
double milestones[NODE_PERFORMANCE_MILESTONE_INVALID];
|
||||||
|
uint32_t observers[NODE_PERFORMANCE_ENTRY_TYPE_INVALID];
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace performance
|
} // namespace performance
|
||||||
|
|||||||
Reference in new issue
Block a user