Skip to content

Commit 9a31804

Browse files
LeszekSwirskiCommit Bot
authored andcommitted
[profiler] Clean up CodeEvent tags
Clean-up and slightly unify the CodeEvent tags: * Remove INTERPRETED_FUNCTION_TAG. It was only used for interpreter trampoline copies, which are used for --interpreted-frames-native-stack. However, even actual bytecode compilation doesn't use INTERPRETED_FUNCTION_TAG, so we can remove it for simplicity. * The tag used by the above is now the same as for the bytecode creation event, i.e. EVAL_TAG, SCRIPT_TAG, FUNCTION_TAG or LAZY_COMPILE, depending on whether this was a script, and eval, an eager or a lazy compile (respectively. * Baseline was also using INTERPRETED_FUNCTION_TAG, so now it does the same thing as above. * Existing code is now logged as FUNCTION_TAG rather than LAZY_COMPILE, because we lost the laziness information. * The SCRIPT_TAG is set based on the SharedFunctionInfo flags, not the compilation flags, so that eager inner functions are labelled as FUNCTION_TAG rather than SCRIPT_TAG. Bug: v8:11420,v8:11429 Change-Id: I0286002674255ff4ba8f5d865df372a3e2975b16 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2713104 Reviewed-by: Yang Guo <yangguo@chromium.org> Commit-Queue: Leszek Swirski <leszeks@chromium.org> Cr-Commit-Position: refs/heads/master@{#73047}
1 parent d7be571 commit 9a31804

8 files changed

Lines changed: 89 additions & 69 deletions

File tree

src/codegen/compiler.cc

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -516,8 +516,9 @@ bool UseAsmWasm(FunctionLiteral* literal, bool asm_wasm_broken) {
516516
}
517517
#endif
518518

519-
void InstallInterpreterTrampolineCopy(Isolate* isolate,
520-
Handle<SharedFunctionInfo> shared_info) {
519+
void InstallInterpreterTrampolineCopy(
520+
Isolate* isolate, Handle<SharedFunctionInfo> shared_info,
521+
CodeEventListener::LogEventsAndTags log_tag) {
521522
DCHECK(FLAG_interpreted_frames_native_stack);
522523
if (!shared_info->function_data(kAcquireLoad).IsBytecodeArray()) {
523524
DCHECK(!shared_info->HasBytecodeArray());
@@ -548,8 +549,6 @@ void InstallInterpreterTrampolineCopy(Isolate* isolate,
548549
handle(script->name().IsString() ? String::cast(script->name())
549550
: ReadOnlyRoots(isolate).empty_string(),
550551
isolate);
551-
CodeEventListener::LogEventsAndTags log_tag = Logger::ToNativeByScript(
552-
CodeEventListener::INTERPRETED_FUNCTION_TAG, *script);
553552
PROFILE(isolate, CodeCreateEvent(log_tag, abstract_code, shared_info,
554553
script_name, line_num, column_num));
555554
}
@@ -586,18 +585,9 @@ void InstallUnoptimizedCode(UnoptimizedCompilationInfo* compilation_info,
586585

587586
void LogUnoptimizedCompilation(Isolate* isolate,
588587
Handle<SharedFunctionInfo> shared_info,
589-
UnoptimizedCompileFlags flags,
588+
CodeEventListener::LogEventsAndTags log_tag,
590589
base::TimeDelta time_taken_to_execute,
591590
base::TimeDelta time_taken_to_finalize) {
592-
CodeEventListener::LogEventsAndTags log_tag;
593-
if (flags.is_toplevel()) {
594-
log_tag = flags.is_eval() ? CodeEventListener::EVAL_TAG
595-
: CodeEventListener::SCRIPT_TAG;
596-
} else {
597-
log_tag = flags.is_lazy_compile() ? CodeEventListener::LAZY_COMPILE_TAG
598-
: CodeEventListener::FUNCTION_TAG;
599-
}
600-
601591
RecordUnoptimizedFunctionCompilation(isolate, log_tag, shared_info,
602592
time_taken_to_execute,
603593
time_taken_to_finalize);
@@ -1341,8 +1331,17 @@ void FinalizeUnoptimizedCompilation(
13411331
if (need_source_positions) {
13421332
SharedFunctionInfo::EnsureSourcePositionsAvailable(isolate, shared_info);
13431333
}
1334+
CodeEventListener::LogEventsAndTags log_tag;
1335+
if (shared_info->is_toplevel()) {
1336+
log_tag = flags.is_eval() ? CodeEventListener::EVAL_TAG
1337+
: CodeEventListener::SCRIPT_TAG;
1338+
} else {
1339+
log_tag = flags.is_lazy_compile() ? CodeEventListener::LAZY_COMPILE_TAG
1340+
: CodeEventListener::FUNCTION_TAG;
1341+
}
1342+
log_tag = Logger::ToNativeByScript(log_tag, *script);
13441343
if (FLAG_interpreted_frames_native_stack) {
1345-
InstallInterpreterTrampolineCopy(isolate, shared_info);
1344+
InstallInterpreterTrampolineCopy(isolate, shared_info, log_tag);
13461345
}
13471346
if (FLAG_always_sparkplug) {
13481347
CompileSharedWithBaseline(isolate, shared_info, Compiler::KEEP_EXCEPTION,
@@ -1353,7 +1352,7 @@ void FinalizeUnoptimizedCompilation(
13531352
isolate->debug()->InstallCoverageInfo(shared_info, coverage_info);
13541353
}
13551354

1356-
LogUnoptimizedCompilation(isolate, shared_info, flags,
1355+
LogUnoptimizedCompilation(isolate, shared_info, log_tag,
13571356
finalize_data.time_taken_to_execute(),
13581357
finalize_data.time_taken_to_finalize());
13591358
}

src/logging/code-events.h

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,19 @@ using WasmName = Vector<const char>;
4141
V(BYTECODE_FLUSH_EVENT, bytecode-flush)
4242
// clang-format on
4343

44-
#define TAGS_LIST(V) \
45-
V(BUILTIN_TAG, Builtin) \
46-
V(CALLBACK_TAG, Callback) \
47-
V(EVAL_TAG, Eval) \
48-
V(FUNCTION_TAG, Function) \
49-
V(INTERPRETED_FUNCTION_TAG, InterpretedFunction) \
50-
V(HANDLER_TAG, Handler) \
51-
V(BYTECODE_HANDLER_TAG, BytecodeHandler) \
52-
V(LAZY_COMPILE_TAG, LazyCompile) \
53-
V(REG_EXP_TAG, RegExp) \
54-
V(SCRIPT_TAG, Script) \
55-
V(STUB_TAG, Stub) \
56-
V(NATIVE_FUNCTION_TAG, Function) \
57-
V(NATIVE_LAZY_COMPILE_TAG, LazyCompile) \
44+
#define TAGS_LIST(V) \
45+
V(BUILTIN_TAG, Builtin) \
46+
V(CALLBACK_TAG, Callback) \
47+
V(EVAL_TAG, Eval) \
48+
V(FUNCTION_TAG, Function) \
49+
V(HANDLER_TAG, Handler) \
50+
V(BYTECODE_HANDLER_TAG, BytecodeHandler) \
51+
V(LAZY_COMPILE_TAG, LazyCompile) \
52+
V(REG_EXP_TAG, RegExp) \
53+
V(SCRIPT_TAG, Script) \
54+
V(STUB_TAG, Stub) \
55+
V(NATIVE_FUNCTION_TAG, Function) \
56+
V(NATIVE_LAZY_COMPILE_TAG, LazyCompile) \
5857
V(NATIVE_SCRIPT_TAG, Script)
5958
// Note that 'NATIVE_' cases for functions and scripts are mapped onto
6059
// original tags when writing to the log.

src/logging/log.cc

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,20 @@ static v8::CodeEventType GetCodeEventTypeForTag(
8181
}
8282

8383
static const char* ComputeMarker(SharedFunctionInfo shared, AbstractCode code) {
84+
CodeKind kind = code.kind();
85+
// We record interpreter trampoline builting copies as having the
86+
// "interpreted" marker.
87+
if (FLAG_interpreted_frames_native_stack && kind == CodeKind::BUILTIN &&
88+
code.GetCode().is_interpreter_trampoline_builtin() &&
89+
code.GetCode() !=
90+
*BUILTIN_CODE(shared.GetIsolate(), InterpreterEntryTrampoline)) {
91+
kind = CodeKind::INTERPRETED_FUNCTION;
92+
}
8493
if (shared.optimization_disabled() &&
85-
code.kind() == CodeKind::INTERPRETED_FUNCTION) {
94+
kind == CodeKind::INTERPRETED_FUNCTION) {
8695
return "";
8796
}
88-
return CodeKindToMarker(code.kind());
97+
return CodeKindToMarker(kind);
8998
}
9099

91100
static const char* ComputeMarker(const wasm::WasmCode* code) {
@@ -2183,17 +2192,14 @@ void ExistingCodeLogger::LogCompiledFunctions() {
21832192
LogExistingFunction(
21842193
shared,
21852194
Handle<AbstractCode>(
2186-
AbstractCode::cast(shared->InterpreterTrampoline()), isolate_),
2187-
CodeEventListener::INTERPRETED_FUNCTION_TAG);
2195+
AbstractCode::cast(shared->InterpreterTrampoline()), isolate_));
21882196
}
21892197
if (shared->HasBaselineData()) {
2190-
// TODO(v8:11429): Add a tag for baseline code. Or use CodeKind?
21912198
LogExistingFunction(
21922199
shared,
21932200
Handle<AbstractCode>(
21942201
AbstractCode::cast(shared->baseline_data().baseline_code()),
2195-
isolate_),
2196-
CodeEventListener::INTERPRETED_FUNCTION_TAG);
2202+
isolate_));
21972203
}
21982204
if (pair.second.is_identical_to(BUILTIN_CODE(isolate_, CompileLazy)))
21992205
continue;
@@ -2218,7 +2224,7 @@ void ExistingCodeLogger::LogExistingFunction(
22182224
Script::GetColumnNumber(script, shared->StartPosition()) + 1;
22192225
if (script->name().IsString()) {
22202226
Handle<String> script_name(String::cast(script->name()), isolate_);
2221-
if (line_num > 0) {
2227+
if (!shared->is_toplevel()) {
22222228
CALL_CODE_EVENT_HANDLER(
22232229
CodeCreateEvent(Logger::ToNativeByScript(tag, *script), code,
22242230
shared, script_name, line_num, column_num))

src/logging/log.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class ExistingCodeLogger {
9191
void LogExistingFunction(Handle<SharedFunctionInfo> shared,
9292
Handle<AbstractCode> code,
9393
CodeEventListener::LogEventsAndTags tag =
94-
CodeEventListener::LAZY_COMPILE_TAG);
94+
CodeEventListener::FUNCTION_TAG);
9595
void LogCodeObject(Object object);
9696

9797
private:

src/profiler/profile-generator.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,6 @@ CpuProfileNode::SourceType ProfileNode::source_type() const {
314314
case CodeEventListener::SCRIPT_TAG:
315315
case CodeEventListener::LAZY_COMPILE_TAG:
316316
case CodeEventListener::FUNCTION_TAG:
317-
case CodeEventListener::INTERPRETED_FUNCTION_TAG:
318317
return CpuProfileNode::kScript;
319318
case CodeEventListener::BUILTIN_TAG:
320319
case CodeEventListener::HANDLER_TAG:

src/snapshot/code-serializer.cc

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,8 @@ void CreateInterpreterDataForDeserializedCode(Isolate* isolate,
252252
int line_num = script->GetLineNumber(info->StartPosition()) + 1;
253253
int column_num = script->GetColumnNumber(info->StartPosition()) + 1;
254254
PROFILE(isolate,
255-
CodeCreateEvent(CodeEventListener::INTERPRETED_FUNCTION_TAG,
256-
abstract_code, info, name_handle, line_num,
257-
column_num));
255+
CodeCreateEvent(CodeEventListener::FUNCTION_TAG, abstract_code,
256+
info, name_handle, line_num, column_num));
258257
}
259258
}
260259
#endif // V8_TARGET_ARCH_ARM
@@ -385,11 +384,13 @@ MaybeHandle<SharedFunctionInfo> CodeSerializer::Deserialize(
385384
script->GetLineNumber(shared_info->StartPosition()) + 1;
386385
int column_num =
387386
script->GetColumnNumber(shared_info->StartPosition()) + 1;
388-
PROFILE(isolate,
389-
CodeCreateEvent(
390-
CodeEventListener::SCRIPT_TAG,
391-
handle(shared_info->abstract_code(isolate), isolate),
392-
shared_info, name, line_num, column_num));
387+
PROFILE(
388+
isolate,
389+
CodeCreateEvent(
390+
shared_info->is_toplevel() ? CodeEventListener::SCRIPT_TAG
391+
: CodeEventListener::FUNCTION_TAG,
392+
handle(shared_info->abstract_code(isolate), isolate),
393+
shared_info, name, line_num, column_num));
393394
}
394395
}
395396
}

test/cctest/test-cpu-profiler.cc

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2212,16 +2212,22 @@ TEST(FunctionDetails) {
22122212
const v8::CpuProfile* profile = i::ProfilerExtension::last_profile;
22132213
reinterpret_cast<const i::CpuProfile*>(profile)->Print();
22142214
// The tree should look like this:
2215-
// 0 (root) 0 #1
2216-
// 0 "" 19 #2 no reason script_b:1
2217-
// 0 baz 19 #3 TryCatchStatement script_b:3
2218-
// 0 foo 18 #4 TryCatchStatement script_a:2
2219-
// 1 bar 18 #5 no reason script_a:3
2215+
// 0 (root):0 3 0 #1
2216+
// 0 :0 0 5 #2 script_b:0
2217+
// 0 baz:3 0 5 #3 script_b:3
2218+
// bailed out due to 'Optimization is always disabled'
2219+
// 0 foo:4 0 4 #4 script_a:4
2220+
// bailed out due to 'Optimization is always disabled'
2221+
// 0 bar:5 0 4 #5 script_a:5
2222+
// bailed out due to 'Optimization is always disabled'
2223+
// 0 startProfiling:0 2 0 #6
22202224
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
22212225
CHECK_EQ(root->GetParent(), nullptr);
22222226
const v8::CpuProfileNode* script = GetChild(env, root, "");
22232227
CheckFunctionDetails(env->GetIsolate(), script, "", "script_b", true,
2224-
script_b->GetUnboundScript()->GetId(), 1, 1, root);
2228+
script_b->GetUnboundScript()->GetId(),
2229+
v8::CpuProfileNode::kNoLineNumberInfo,
2230+
CpuProfileNode::kNoColumnNumberInfo, root);
22252231
const v8::CpuProfileNode* baz = GetChild(env, script, "baz");
22262232
CheckFunctionDetails(env->GetIsolate(), baz, "baz", "script_b", true,
22272233
script_b->GetUnboundScript()->GetId(), 3, 16, script);
@@ -2290,7 +2296,7 @@ TEST(FunctionDetailsInlining) {
22902296
// The tree should look like this:
22912297
// 0 (root) 0 #1
22922298
// 5 (program) 0 #6
2293-
// 2 14 #2 script_a:1
2299+
// 2 14 #2 script_a:0
22942300
// ;;; deopted at script_id: 14 position: 299 with reason 'Insufficient
22952301
// type feedback for call'.
22962302
// 1 alpha 14 #4 script_a:1
@@ -2301,7 +2307,9 @@ TEST(FunctionDetailsInlining) {
23012307
CHECK_EQ(root->GetParent(), nullptr);
23022308
const v8::CpuProfileNode* script = GetChild(env, root, "");
23032309
CheckFunctionDetails(env->GetIsolate(), script, "", "script_a", false,
2304-
script_a->GetUnboundScript()->GetId(), 1, 1, root);
2310+
script_a->GetUnboundScript()->GetId(),
2311+
v8::CpuProfileNode::kNoLineNumberInfo,
2312+
v8::CpuProfileNode::kNoColumnNumberInfo, root);
23052313
const v8::CpuProfileNode* alpha = FindChild(env, script, "alpha");
23062314
// Return early if profiling didn't sample alpha.
23072315
if (!alpha) return;

test/cctest/test-log.cc

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -577,8 +577,9 @@ UNINITIALIZED_TEST(LogInterpretedFramesNativeStack) {
577577

578578
logger.StopLogging();
579579

580-
CHECK(logger.ContainsLine(
581-
{"InterpretedFunction", "testLogInterpretedFramesNativeStack"}));
580+
CHECK(logger.ContainsLinesInOrder(
581+
{{"LazyCompile", "testLogInterpretedFramesNativeStack"},
582+
{"LazyCompile", "testLogInterpretedFramesNativeStack"}}));
582583
}
583584
isolate->Dispose();
584585
}
@@ -629,7 +630,11 @@ UNINITIALIZED_TEST(LogInterpretedFramesNativeStackWithSerialization) {
629630
.ToLocalChecked();
630631
if (has_cache) {
631632
logger.StopLogging();
632-
CHECK(logger.ContainsLine({"InterpretedFunction", "eyecatcher"}));
633+
logger.PrintLog();
634+
// Function is logged twice: once as interpreted, and once as the
635+
// interpreter entry trampoline builtin.
636+
CHECK(logger.ContainsLinesInOrder(
637+
{{"Function", "eyecatcher"}, {"Function", "eyecatcher"}}));
633638
}
634639
v8::Local<v8::Value> arg = v8_num(3);
635640
v8::Local<v8::Value> result =
@@ -667,13 +672,16 @@ UNINITIALIZED_TEST(ExternalCodeEventListener) {
667672
"testCodeEventListenerBeforeStart('1', 1);";
668673
CompileRun(source_text_before_start);
669674

675+
CHECK_EQ(code_event_handler.CountLines("Function",
676+
"testCodeEventListenerBeforeStart"),
677+
0);
670678
CHECK_EQ(code_event_handler.CountLines("LazyCompile",
671679
"testCodeEventListenerBeforeStart"),
672680
0);
673681

674682
code_event_handler.Enable();
675683

676-
CHECK_GE(code_event_handler.CountLines("LazyCompile",
684+
CHECK_GE(code_event_handler.CountLines("Function",
677685
"testCodeEventListenerBeforeStart"),
678686
1);
679687

@@ -715,9 +723,9 @@ UNINITIALIZED_TEST(ExternalCodeEventListenerInnerFunctions) {
715723
v8::Local<v8::UnboundScript> script =
716724
v8::ScriptCompiler::CompileUnboundScript(isolate1, &source)
717725
.ToLocalChecked();
718-
CHECK_EQ(code_event_handler.CountLines("Script", "f1"),
726+
CHECK_EQ(code_event_handler.CountLines("Function", "f1"),
719727
i::FLAG_stress_background_compile ? 2 : 1);
720-
CHECK_EQ(code_event_handler.CountLines("Script", "f2"),
728+
CHECK_EQ(code_event_handler.CountLines("Function", "f2"),
721729
i::FLAG_stress_background_compile ? 2 : 1);
722730
cache = v8::ScriptCompiler::CreateCodeCache(script);
723731
}
@@ -743,8 +751,8 @@ UNINITIALIZED_TEST(ExternalCodeEventListenerInnerFunctions) {
743751
isolate2, &source, v8::ScriptCompiler::kConsumeCodeCache)
744752
.ToLocalChecked();
745753
}
746-
CHECK_EQ(code_event_handler.CountLines("Script", "f1"), 1);
747-
CHECK_EQ(code_event_handler.CountLines("Script", "f2"), 1);
754+
CHECK_EQ(code_event_handler.CountLines("Function", "f1"), 1);
755+
CHECK_EQ(code_event_handler.CountLines("Function", "f2"), 1);
748756
}
749757
isolate2->Dispose();
750758
}
@@ -772,24 +780,24 @@ UNINITIALIZED_TEST(ExternalCodeEventListenerWithInterpretedFramesNativeStack) {
772780
"testCodeEventListenerBeforeStart('1', 1);";
773781
CompileRun(source_text_before_start);
774782

775-
CHECK_EQ(code_event_handler.CountLines("InterpretedFunction",
783+
CHECK_EQ(code_event_handler.CountLines("Function",
776784
"testCodeEventListenerBeforeStart"),
777785
0);
778786

779787
code_event_handler.Enable();
780788

781-
CHECK_GE(code_event_handler.CountLines("InterpretedFunction",
789+
CHECK_GE(code_event_handler.CountLines("Function",
782790
"testCodeEventListenerBeforeStart"),
783-
1);
791+
2);
784792

785793
const char* source_text_after_start =
786794
"function testCodeEventListenerAfterStart(a,b) { return a + b };"
787795
"testCodeEventListenerAfterStart('1', 1);";
788796
CompileRun(source_text_after_start);
789797

790-
CHECK_GE(code_event_handler.CountLines("InterpretedFunction",
798+
CHECK_GE(code_event_handler.CountLines("LazyCompile",
791799
"testCodeEventListenerAfterStart"),
792-
1);
800+
2);
793801

794802
CHECK_EQ(
795803
code_event_handler.CountLines("Builtin", "InterpreterEntryTrampoline"),

0 commit comments

Comments
 (0)