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 7, 2022
1 parent deb713e commit d927abd
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 52 deletions.
3 changes: 1 addition & 2 deletions src/api/hooks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ void EmitBeforeExit(Environment* env) {
}

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

Expand Down
16 changes: 6 additions & 10 deletions src/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -674,8 +674,7 @@ void Environment::PrintSyncTrace() const {

void Environment::RunCleanup() {
started_cleanup_ = true;
TraceEventScope trace_scope(TRACING_CATEGORY_NODE1(environment),
"RunCleanup", this);
TRACE_EVENT0(TRACING_CATEGORY_NODE1(environment), "RunCleanup");
bindings_.clear();
CleanupHandles();

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

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

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

Expand Down Expand Up @@ -849,8 +847,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);
TRACE_EVENT0(TRACING_CATEGORY_NODE1(environment), "RunTimers");

if (!env->can_call_into_js())
return;
Expand Down Expand Up @@ -911,8 +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);
TRACE_EVENT0(TRACING_CATEGORY_NODE1(environment), "CheckImmediate");

HandleScope scope(env->isolate());
Context::Scope context_scope(env->context());
Expand Down
32 changes: 9 additions & 23 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_EVENT0(TRACING_CATEGORY_NODE2(vm, script), "RunInThisContext");

// TODO(addaleax): Use an options object or otherwise merge this with
// RunInContext().
Expand All @@ -892,9 +885,6 @@ void ContextifyScript::RunInThisContext(
break_on_first_line,
nullptr, // microtask_queue
args);

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

void ContextifyScript::RunInContext(const FunctionCallbackInfo<Value>& args) {
Expand All @@ -916,8 +906,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_EVENT0(TRACING_CATEGORY_NODE2(vm, script), "RunInContext");

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

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

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

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_);
}

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

namespace heap {

void DeleteHeapSnapshot(const v8::HeapSnapshot* snapshot);
Expand Down

0 comments on commit d927abd

Please sign in to comment.