Skip to content

Commit 758c02e

Browse files
legendecasjuanarbol
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 <raisinten@gmail.com>
1 parent 80df97c commit 758c02e

File tree

4 files changed

+16
-52
lines changed

4 files changed

+16
-52
lines changed

src/api/hooks.cc

+1-2
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

+6-10
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

+9-23
Original file line numberDiff line numberDiff line change
@@ -732,11 +732,10 @@ void ContextifyScript::New(const FunctionCallbackInfo<Value>& args) {
732732
if (*TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(
733733
TRACING_CATEGORY_NODE2(vm, script)) != 0) {
734734
Utf8Value fn(isolate, filename);
735-
TRACE_EVENT_NESTABLE_ASYNC_BEGIN1(
736-
TRACING_CATEGORY_NODE2(vm, script),
737-
"ContextifyScript::New",
738-
contextify_script,
739-
"filename", TRACE_STR_COPY(*fn));
735+
TRACE_EVENT_BEGIN1(TRACING_CATEGORY_NODE2(vm, script),
736+
"ContextifyScript::New",
737+
"filename",
738+
TRACE_STR_COPY(*fn));
740739
}
741740

742741
ScriptCompiler::CachedData* cached_data = nullptr;
@@ -786,10 +785,8 @@ void ContextifyScript::New(const FunctionCallbackInfo<Value>& args) {
786785
no_abort_scope.Close();
787786
if (!try_catch.HasTerminated())
788787
try_catch.ReThrow();
789-
TRACE_EVENT_NESTABLE_ASYNC_END0(
790-
TRACING_CATEGORY_NODE2(vm, script),
791-
"ContextifyScript::New",
792-
contextify_script);
788+
TRACE_EVENT_END0(TRACING_CATEGORY_NODE2(vm, script),
789+
"ContextifyScript::New");
793790
return;
794791
}
795792
contextify_script->script_.Reset(isolate, v8_script.ToLocalChecked());
@@ -818,10 +815,7 @@ void ContextifyScript::New(const FunctionCallbackInfo<Value>& args) {
818815
env->cached_data_produced_string(),
819816
Boolean::New(isolate, cached_data_produced)).Check();
820817
}
821-
TRACE_EVENT_NESTABLE_ASYNC_END0(
822-
TRACING_CATEGORY_NODE2(vm, script),
823-
"ContextifyScript::New",
824-
contextify_script);
818+
TRACE_EVENT_END0(TRACING_CATEGORY_NODE2(vm, script), "ContextifyScript::New");
825819
}
826820

827821
bool ContextifyScript::InstanceOf(Environment* env,
@@ -857,8 +851,7 @@ void ContextifyScript::RunInThisContext(
857851
ContextifyScript* wrapped_script;
858852
ASSIGN_OR_RETURN_UNWRAP(&wrapped_script, args.Holder());
859853

860-
TRACE_EVENT_NESTABLE_ASYNC_BEGIN0(
861-
TRACING_CATEGORY_NODE2(vm, script), "RunInThisContext", wrapped_script);
854+
TRACE_EVENT0(TRACING_CATEGORY_NODE2(vm, script), "RunInThisContext");
862855

863856
// TODO(addaleax): Use an options object or otherwise merge this with
864857
// RunInContext().
@@ -884,9 +877,6 @@ void ContextifyScript::RunInThisContext(
884877
break_on_first_line,
885878
nullptr, // microtask_queue
886879
args);
887-
888-
TRACE_EVENT_NESTABLE_ASYNC_END0(
889-
TRACING_CATEGORY_NODE2(vm, script), "RunInThisContext", wrapped_script);
890880
}
891881

892882
void ContextifyScript::RunInContext(const FunctionCallbackInfo<Value>& args) {
@@ -908,8 +898,7 @@ void ContextifyScript::RunInContext(const FunctionCallbackInfo<Value>& args) {
908898
if (context.IsEmpty())
909899
return;
910900

911-
TRACE_EVENT_NESTABLE_ASYNC_BEGIN0(
912-
TRACING_CATEGORY_NODE2(vm, script), "RunInContext", wrapped_script);
901+
TRACE_EVENT0(TRACING_CATEGORY_NODE2(vm, script), "RunInContext");
913902

914903
CHECK(args[1]->IsNumber());
915904
int64_t timeout = args[1]->IntegerValue(env->context()).FromJust();
@@ -932,9 +921,6 @@ void ContextifyScript::RunInContext(const FunctionCallbackInfo<Value>& args) {
932921
break_on_first_line,
933922
contextify_context->microtask_queue(),
934923
args);
935-
936-
TRACE_EVENT_NESTABLE_ASYNC_END0(
937-
TRACING_CATEGORY_NODE2(vm, script), "RunInContext", wrapped_script);
938924
}
939925

940926
bool ContextifyScript::EvalMachine(Environment* env,

src/node_internals.h

-17
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)