Skip to content

Commit 6d65809

Browse files
legendecastargos
authored andcommitted
src: replace TraceEventScope with sync events
According to the chrome trace event format document, works that are performed on one single thread should be traced with sync duration events. In this way, these events can be grouped under one thread and the trace event viewer can estimate the CPU usage of that thread. PR-URL: #42977 Reviewed-By: Darshan Sen <[email protected]>
1 parent fb507a9 commit 6d65809

File tree

4 files changed

+16
-52
lines changed

4 files changed

+16
-52
lines changed

src/api/hooks.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ void EmitBeforeExit(Environment* env) {
3232
}
3333

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

src/env.cc

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -673,8 +673,7 @@ void Environment::PrintSyncTrace() const {
673673

674674
void Environment::RunCleanup() {
675675
started_cleanup_ = true;
676-
TraceEventScope trace_scope(TRACING_CATEGORY_NODE1(environment),
677-
"RunCleanup", this);
676+
TRACE_EVENT0(TRACING_CATEGORY_NODE1(environment), "RunCleanup");
678677
bindings_.clear();
679678
CleanupHandles();
680679

@@ -716,8 +715,7 @@ void Environment::RunCleanup() {
716715
}
717716

718717
void Environment::RunAtExitCallbacks() {
719-
TraceEventScope trace_scope(TRACING_CATEGORY_NODE1(environment),
720-
"AtExit", this);
718+
TRACE_EVENT0(TRACING_CATEGORY_NODE1(environment), "AtExit");
721719
for (ExitCallback at_exit : at_exit_functions_) {
722720
at_exit.cb_(at_exit.arg_);
723721
}
@@ -743,8 +741,8 @@ void Environment::RunAndClearInterrupts() {
743741
}
744742

745743
void Environment::RunAndClearNativeImmediates(bool only_refed) {
746-
TraceEventScope trace_scope(TRACING_CATEGORY_NODE1(environment),
747-
"RunAndClearNativeImmediates", this);
744+
TRACE_EVENT0(TRACING_CATEGORY_NODE1(environment),
745+
"RunAndClearNativeImmediates");
748746
HandleScope handle_scope(isolate_);
749747
InternalCallbackScope cb_scope(this, Object::New(isolate_), { 0, 0 });
750748

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

849847
void Environment::RunTimers(uv_timer_t* handle) {
850848
Environment* env = Environment::from_timer_handle(handle);
851-
TraceEventScope trace_scope(TRACING_CATEGORY_NODE1(environment),
852-
"RunTimers", env);
849+
TRACE_EVENT0(TRACING_CATEGORY_NODE1(environment), "RunTimers");
853850

854851
if (!env->can_call_into_js())
855852
return;
@@ -910,8 +907,7 @@ void Environment::RunTimers(uv_timer_t* handle) {
910907

911908
void Environment::CheckImmediate(uv_check_t* handle) {
912909
Environment* env = Environment::from_immediate_check_handle(handle);
913-
TraceEventScope trace_scope(TRACING_CATEGORY_NODE1(environment),
914-
"CheckImmediate", env);
910+
TRACE_EVENT0(TRACING_CATEGORY_NODE1(environment), "CheckImmediate");
915911

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

src/node_contextify.cc

Lines changed: 9 additions & 23 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_EVENT0(TRACING_CATEGORY_NODE2(vm, script), "RunInThisContext");
870863

871864
// TODO(addaleax): Use an options object or otherwise merge this with
872865
// RunInContext().
@@ -892,9 +885,6 @@ void ContextifyScript::RunInThisContext(
892885
break_on_first_line,
893886
nullptr, // microtask_queue
894887
args);
895-
896-
TRACE_EVENT_NESTABLE_ASYNC_END0(
897-
TRACING_CATEGORY_NODE2(vm, script), "RunInThisContext", wrapped_script);
898888
}
899889

900890
void ContextifyScript::RunInContext(const FunctionCallbackInfo<Value>& args) {
@@ -916,8 +906,7 @@ void ContextifyScript::RunInContext(const FunctionCallbackInfo<Value>& args) {
916906
if (context.IsEmpty())
917907
return;
918908

919-
TRACE_EVENT_NESTABLE_ASYNC_BEGIN0(
920-
TRACING_CATEGORY_NODE2(vm, script), "RunInContext", wrapped_script);
909+
TRACE_EVENT0(TRACING_CATEGORY_NODE2(vm, script), "RunInContext");
921910

922911
CHECK(args[1]->IsNumber());
923912
int64_t timeout = args[1]->IntegerValue(env->context()).FromJust();
@@ -940,9 +929,6 @@ void ContextifyScript::RunInContext(const FunctionCallbackInfo<Value>& args) {
940929
break_on_first_line,
941930
contextify_context->microtask_queue(),
942931
args);
943-
944-
TRACE_EVENT_NESTABLE_ASYNC_END0(
945-
TRACING_CATEGORY_NODE2(vm, script), "RunInContext", wrapped_script);
946932
}
947933

948934
bool ContextifyScript::EvalMachine(Environment* env,

src/node_internals.h

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -383,23 +383,6 @@ namespace heap {
383383
bool WriteSnapshot(v8::Isolate* isolate, const char* filename);
384384
}
385385

386-
class TraceEventScope {
387-
public:
388-
TraceEventScope(const char* category,
389-
const char* name,
390-
void* id) : category_(category), name_(name), id_(id) {
391-
TRACE_EVENT_NESTABLE_ASYNC_BEGIN0(category_, name_, id_);
392-
}
393-
~TraceEventScope() {
394-
TRACE_EVENT_NESTABLE_ASYNC_END0(category_, name_, id_);
395-
}
396-
397-
private:
398-
const char* category_;
399-
const char* name_;
400-
void* id_;
401-
};
402-
403386
namespace heap {
404387

405388
void DeleteHeapSnapshot(const v8::HeapSnapshot* snapshot);

0 commit comments

Comments
 (0)