Skip to content

Commit 5d629e3

Browse files
committed
src: TraceEventScope should mark sync duration events
1 parent deb713e commit 5d629e3

File tree

4 files changed

+29
-45
lines changed

4 files changed

+29
-45
lines changed

src/api/hooks.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void EmitBeforeExit(Environment* env) {
3333

3434
Maybe<bool> EmitProcessBeforeExit(Environment* env) {
3535
TraceEventScope trace_scope(TRACING_CATEGORY_NODE1(environment),
36-
"BeforeExit", env);
36+
"BeforeExit");
3737
if (!env->destroy_async_id_list()->empty())
3838
AsyncWrap::DestroyAsyncIdsCallback(env);
3939

src/env.cc

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -412,11 +412,10 @@ Environment::Environment(IsolateData* isolate_data,
412412
traced_value->BeginArray("exec_args");
413413
for (const std::string& arg : exec_args) traced_value->AppendString(arg);
414414
traced_value->EndArray();
415-
TRACE_EVENT_NESTABLE_ASYNC_BEGIN1(TRACING_CATEGORY_NODE1(environment),
416-
"Environment",
417-
this,
418-
"args",
419-
std::move(traced_value));
415+
TRACE_EVENT_BEGIN1(TRACING_CATEGORY_NODE1(environment),
416+
"Environment",
417+
"args",
418+
std::move(traced_value));
420419
}
421420
}
422421

@@ -520,8 +519,7 @@ Environment::~Environment() {
520519
tracing_controller->RemoveTraceStateObserver(trace_state_observer_.get());
521520
}
522521

523-
TRACE_EVENT_NESTABLE_ASYNC_END0(
524-
TRACING_CATEGORY_NODE1(environment), "Environment", this);
522+
TRACE_EVENT_END0(TRACING_CATEGORY_NODE1(environment), "Environment");
525523

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

@@ -717,8 +715,7 @@ void Environment::RunCleanup() {
717715
}
718716

719717
void Environment::RunAtExitCallbacks() {
720-
TraceEventScope trace_scope(TRACING_CATEGORY_NODE1(environment),
721-
"AtExit", this);
718+
TraceEventScope trace_scope(TRACING_CATEGORY_NODE1(environment), "AtExit");
722719
for (ExitCallback at_exit : at_exit_functions_) {
723720
at_exit.cb_(at_exit.arg_);
724721
}
@@ -745,7 +742,7 @@ void Environment::RunAndClearInterrupts() {
745742

746743
void Environment::RunAndClearNativeImmediates(bool only_refed) {
747744
TraceEventScope trace_scope(TRACING_CATEGORY_NODE1(environment),
748-
"RunAndClearNativeImmediates", this);
745+
"RunAndClearNativeImmediates");
749746
HandleScope handle_scope(isolate_);
750747
InternalCallbackScope cb_scope(this, Object::New(isolate_), { 0, 0 });
751748

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

850847
void Environment::RunTimers(uv_timer_t* handle) {
851848
Environment* env = Environment::from_timer_handle(handle);
852-
TraceEventScope trace_scope(TRACING_CATEGORY_NODE1(environment),
853-
"RunTimers", env);
849+
TraceEventScope trace_scope(TRACING_CATEGORY_NODE1(environment), "RunTimers");
854850

855851
if (!env->can_call_into_js())
856852
return;
@@ -912,7 +908,7 @@ void Environment::RunTimers(uv_timer_t* handle) {
912908
void Environment::CheckImmediate(uv_check_t* handle) {
913909
Environment* env = Environment::from_immediate_check_handle(handle);
914910
TraceEventScope trace_scope(TRACING_CATEGORY_NODE1(environment),
915-
"CheckImmediate", env);
911+
"CheckImmediate");
916912

917913
HandleScope scope(env->isolate());
918914
Context::Scope context_scope(env->context());

src/node_contextify.cc

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -740,11 +740,10 @@ void ContextifyScript::New(const FunctionCallbackInfo<Value>& args) {
740740
if (*TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(
741741
TRACING_CATEGORY_NODE2(vm, script)) != 0) {
742742
Utf8Value fn(isolate, filename);
743-
TRACE_EVENT_NESTABLE_ASYNC_BEGIN1(
744-
TRACING_CATEGORY_NODE2(vm, script),
745-
"ContextifyScript::New",
746-
contextify_script,
747-
"filename", TRACE_STR_COPY(*fn));
743+
TRACE_EVENT_BEGIN1(TRACING_CATEGORY_NODE2(vm, script),
744+
"ContextifyScript::New",
745+
"filename",
746+
TRACE_STR_COPY(*fn));
748747
}
749748

750749
ScriptCompiler::CachedData* cached_data = nullptr;
@@ -794,10 +793,8 @@ void ContextifyScript::New(const FunctionCallbackInfo<Value>& args) {
794793
no_abort_scope.Close();
795794
if (!try_catch.HasTerminated())
796795
try_catch.ReThrow();
797-
TRACE_EVENT_NESTABLE_ASYNC_END0(
798-
TRACING_CATEGORY_NODE2(vm, script),
799-
"ContextifyScript::New",
800-
contextify_script);
796+
TRACE_EVENT_END0(TRACING_CATEGORY_NODE2(vm, script),
797+
"ContextifyScript::New");
801798
return;
802799
}
803800
contextify_script->script_.Reset(isolate, v8_script.ToLocalChecked());
@@ -826,10 +823,7 @@ void ContextifyScript::New(const FunctionCallbackInfo<Value>& args) {
826823
env->cached_data_produced_string(),
827824
Boolean::New(isolate, cached_data_produced)).Check();
828825
}
829-
TRACE_EVENT_NESTABLE_ASYNC_END0(
830-
TRACING_CATEGORY_NODE2(vm, script),
831-
"ContextifyScript::New",
832-
contextify_script);
826+
TRACE_EVENT_END0(TRACING_CATEGORY_NODE2(vm, script), "ContextifyScript::New");
833827
}
834828

835829
bool ContextifyScript::InstanceOf(Environment* env,
@@ -865,8 +859,7 @@ void ContextifyScript::RunInThisContext(
865859
ContextifyScript* wrapped_script;
866860
ASSIGN_OR_RETURN_UNWRAP(&wrapped_script, args.Holder());
867861

868-
TRACE_EVENT_NESTABLE_ASYNC_BEGIN0(
869-
TRACING_CATEGORY_NODE2(vm, script), "RunInThisContext", wrapped_script);
862+
TRACE_EVENT_BEGIN0(TRACING_CATEGORY_NODE2(vm, script), "RunInThisContext");
870863

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

896-
TRACE_EVENT_NESTABLE_ASYNC_END0(
897-
TRACING_CATEGORY_NODE2(vm, script), "RunInThisContext", wrapped_script);
889+
TRACE_EVENT_END0(TRACING_CATEGORY_NODE2(vm, script), "RunInThisContext");
898890
}
899891

900892
void ContextifyScript::RunInContext(const FunctionCallbackInfo<Value>& args) {
@@ -916,8 +908,8 @@ void ContextifyScript::RunInContext(const FunctionCallbackInfo<Value>& args) {
916908
if (context.IsEmpty())
917909
return;
918910

919-
TRACE_EVENT_NESTABLE_ASYNC_BEGIN0(
920-
TRACING_CATEGORY_NODE2(vm, script), "RunInContext", wrapped_script);
911+
TraceEventScope trace_event(TRACING_CATEGORY_NODE2(vm, script),
912+
"RunInContext");
921913

922914
CHECK(args[1]->IsNumber());
923915
int64_t timeout = args[1]->IntegerValue(env->context()).FromJust();
@@ -940,9 +932,6 @@ void ContextifyScript::RunInContext(const FunctionCallbackInfo<Value>& args) {
940932
break_on_first_line,
941933
contextify_context->microtask_queue(),
942934
args);
943-
944-
TRACE_EVENT_NESTABLE_ASYNC_END0(
945-
TRACING_CATEGORY_NODE2(vm, script), "RunInContext", wrapped_script);
946935
}
947936

948937
bool ContextifyScript::EvalMachine(Environment* env,

src/node_internals.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -382,21 +382,20 @@ namespace heap {
382382
v8::Maybe<void> WriteSnapshot(Environment* env, const char* filename);
383383
}
384384

385+
/**
386+
* Convenient RAII helper to mark a duration of work on a thread.
387+
*/
385388
class TraceEventScope {
386389
public:
387-
TraceEventScope(const char* category,
388-
const char* name,
389-
void* id) : category_(category), name_(name), id_(id) {
390-
TRACE_EVENT_NESTABLE_ASYNC_BEGIN0(category_, name_, id_);
391-
}
392-
~TraceEventScope() {
393-
TRACE_EVENT_NESTABLE_ASYNC_END0(category_, name_, id_);
390+
TraceEventScope(const char* category, const char* name)
391+
: category_(category), name_(name) {
392+
TRACE_EVENT_BEGIN0(category_, name_);
394393
}
394+
~TraceEventScope() { TRACE_EVENT_END0(category_, name_); }
395395

396396
private:
397397
const char* category_;
398398
const char* name_;
399-
void* id_;
400399
};
401400

402401
namespace heap {

0 commit comments

Comments
 (0)