Skip to content

Commit

Permalink
src: mark sync duration events in TraceEventScope
Browse files Browse the repository at this point in the history
  • Loading branch information
legendecas committed May 5, 2022
1 parent deb713e commit 9a27a76
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 44 deletions.
2 changes: 1 addition & 1 deletion src/api/hooks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void EmitBeforeExit(Environment* env) {

Maybe<bool> EmitProcessBeforeExit(Environment* env) {
TraceEventScope trace_scope(TRACING_CATEGORY_NODE1(environment),
"BeforeExit", env);
"BeforeExit");
if (!env->destroy_async_id_list()->empty())
AsyncWrap::DestroyAsyncIdsCallback(env);

Expand Down
24 changes: 10 additions & 14 deletions src/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -412,11 +412,10 @@ Environment::Environment(IsolateData* isolate_data,
traced_value->BeginArray("exec_args");
for (const std::string& arg : exec_args) traced_value->AppendString(arg);
traced_value->EndArray();
TRACE_EVENT_NESTABLE_ASYNC_BEGIN1(TRACING_CATEGORY_NODE1(environment),
"Environment",
this,
"args",
std::move(traced_value));
TRACE_EVENT_BEGIN1(TRACING_CATEGORY_NODE1(environment),
"Environment",
"args",
std::move(traced_value));
}
}

Expand Down Expand Up @@ -520,8 +519,7 @@ Environment::~Environment() {
tracing_controller->RemoveTraceStateObserver(trace_state_observer_.get());
}

TRACE_EVENT_NESTABLE_ASYNC_END0(
TRACING_CATEGORY_NODE1(environment), "Environment", this);
TRACE_EVENT_END0(TRACING_CATEGORY_NODE1(environment), "Environment");

// Do not unload addons on the main thread. Some addons need to retain memory
// beyond the Environment's lifetime, and unloading them early would break
Expand Down Expand Up @@ -675,7 +673,7 @@ void Environment::PrintSyncTrace() const {
void Environment::RunCleanup() {
started_cleanup_ = true;
TraceEventScope trace_scope(TRACING_CATEGORY_NODE1(environment),
"RunCleanup", this);
"RunCleanup");
bindings_.clear();
CleanupHandles();

Expand Down Expand Up @@ -717,8 +715,7 @@ void Environment::RunCleanup() {
}

void Environment::RunAtExitCallbacks() {
TraceEventScope trace_scope(TRACING_CATEGORY_NODE1(environment),
"AtExit", this);
TraceEventScope trace_scope(TRACING_CATEGORY_NODE1(environment), "AtExit");
for (ExitCallback at_exit : at_exit_functions_) {
at_exit.cb_(at_exit.arg_);
}
Expand All @@ -745,7 +742,7 @@ void Environment::RunAndClearInterrupts() {

void Environment::RunAndClearNativeImmediates(bool only_refed) {
TraceEventScope trace_scope(TRACING_CATEGORY_NODE1(environment),
"RunAndClearNativeImmediates", this);
"RunAndClearNativeImmediates");
HandleScope handle_scope(isolate_);
InternalCallbackScope cb_scope(this, Object::New(isolate_), { 0, 0 });

Expand Down Expand Up @@ -849,8 +846,7 @@ void Environment::ToggleTimerRef(bool ref) {

void Environment::RunTimers(uv_timer_t* handle) {
Environment* env = Environment::from_timer_handle(handle);
TraceEventScope trace_scope(TRACING_CATEGORY_NODE1(environment),
"RunTimers", env);
TraceEventScope trace_scope(TRACING_CATEGORY_NODE1(environment), "RunTimers");

if (!env->can_call_into_js())
return;
Expand Down Expand Up @@ -912,7 +908,7 @@ void Environment::RunTimers(uv_timer_t* handle) {
void Environment::CheckImmediate(uv_check_t* handle) {
Environment* env = Environment::from_immediate_check_handle(handle);
TraceEventScope trace_scope(TRACING_CATEGORY_NODE1(environment),
"CheckImmediate", env);
"CheckImmediate");

HandleScope scope(env->isolate());
Context::Scope context_scope(env->context());
Expand Down
32 changes: 11 additions & 21 deletions src/node_contextify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -740,11 +740,10 @@ void ContextifyScript::New(const FunctionCallbackInfo<Value>& args) {
if (*TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(
TRACING_CATEGORY_NODE2(vm, script)) != 0) {
Utf8Value fn(isolate, filename);
TRACE_EVENT_NESTABLE_ASYNC_BEGIN1(
TRACING_CATEGORY_NODE2(vm, script),
"ContextifyScript::New",
contextify_script,
"filename", TRACE_STR_COPY(*fn));
TRACE_EVENT_BEGIN1(TRACING_CATEGORY_NODE2(vm, script),
"ContextifyScript::New",
"filename",
TRACE_STR_COPY(*fn));
}

ScriptCompiler::CachedData* cached_data = nullptr;
Expand Down Expand Up @@ -794,10 +793,8 @@ void ContextifyScript::New(const FunctionCallbackInfo<Value>& args) {
no_abort_scope.Close();
if (!try_catch.HasTerminated())
try_catch.ReThrow();
TRACE_EVENT_NESTABLE_ASYNC_END0(
TRACING_CATEGORY_NODE2(vm, script),
"ContextifyScript::New",
contextify_script);
TRACE_EVENT_END0(TRACING_CATEGORY_NODE2(vm, script),
"ContextifyScript::New");
return;
}
contextify_script->script_.Reset(isolate, v8_script.ToLocalChecked());
Expand Down Expand Up @@ -826,10 +823,7 @@ void ContextifyScript::New(const FunctionCallbackInfo<Value>& args) {
env->cached_data_produced_string(),
Boolean::New(isolate, cached_data_produced)).Check();
}
TRACE_EVENT_NESTABLE_ASYNC_END0(
TRACING_CATEGORY_NODE2(vm, script),
"ContextifyScript::New",
contextify_script);
TRACE_EVENT_END0(TRACING_CATEGORY_NODE2(vm, script), "ContextifyScript::New");
}

bool ContextifyScript::InstanceOf(Environment* env,
Expand Down Expand Up @@ -865,8 +859,7 @@ void ContextifyScript::RunInThisContext(
ContextifyScript* wrapped_script;
ASSIGN_OR_RETURN_UNWRAP(&wrapped_script, args.Holder());

TRACE_EVENT_NESTABLE_ASYNC_BEGIN0(
TRACING_CATEGORY_NODE2(vm, script), "RunInThisContext", wrapped_script);
TRACE_EVENT_BEGIN0(TRACING_CATEGORY_NODE2(vm, script), "RunInThisContext");

// TODO(addaleax): Use an options object or otherwise merge this with
// RunInContext().
Expand All @@ -893,8 +886,7 @@ void ContextifyScript::RunInThisContext(
nullptr, // microtask_queue
args);

TRACE_EVENT_NESTABLE_ASYNC_END0(
TRACING_CATEGORY_NODE2(vm, script), "RunInThisContext", wrapped_script);
TRACE_EVENT_END0(TRACING_CATEGORY_NODE2(vm, script), "RunInThisContext");
}

void ContextifyScript::RunInContext(const FunctionCallbackInfo<Value>& args) {
Expand All @@ -916,8 +908,7 @@ void ContextifyScript::RunInContext(const FunctionCallbackInfo<Value>& args) {
if (context.IsEmpty())
return;

TRACE_EVENT_NESTABLE_ASYNC_BEGIN0(
TRACING_CATEGORY_NODE2(vm, script), "RunInContext", wrapped_script);
TRACE_EVENT_BEGIN0(TRACING_CATEGORY_NODE2(vm, script), "RunInContext");

CHECK(args[1]->IsNumber());
int64_t timeout = args[1]->IntegerValue(env->context()).FromJust();
Expand All @@ -941,8 +932,7 @@ void ContextifyScript::RunInContext(const FunctionCallbackInfo<Value>& args) {
contextify_context->microtask_queue(),
args);

TRACE_EVENT_NESTABLE_ASYNC_END0(
TRACING_CATEGORY_NODE2(vm, script), "RunInContext", wrapped_script);
TRACE_EVENT_END0(TRACING_CATEGORY_NODE2(vm, script), "RunInContext");
}

bool ContextifyScript::EvalMachine(Environment* env,
Expand Down
15 changes: 7 additions & 8 deletions src/node_internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -382,21 +382,20 @@ namespace heap {
v8::Maybe<void> WriteSnapshot(Environment* env, const char* filename);
}

/**
* Convenient RAII helper to mark a duration of work on a thread.
*/
class TraceEventScope {
public:
TraceEventScope(const char* category,
const char* name,
void* id) : category_(category), name_(name), id_(id) {
TRACE_EVENT_NESTABLE_ASYNC_BEGIN0(category_, name_, id_);
}
~TraceEventScope() {
TRACE_EVENT_NESTABLE_ASYNC_END0(category_, name_, id_);
TraceEventScope(const char* category, const char* name)
: category_(category), name_(name) {
TRACE_EVENT_BEGIN0(category_, name_);
}
~TraceEventScope() { TRACE_EVENT_END0(category_, name_); }

private:
const char* category_;
const char* name_;
void* id_;
};

namespace heap {
Expand Down

0 comments on commit 9a27a76

Please sign in to comment.