Skip to content

Commit ab00559

Browse files
ofrobotsMylesBorins
authored andcommitted
deps: V8: backport 76c3ac5 from upstream
This fixes a bug in the CPU profiler where some ticks were attributed to the wrong file. Original commit message: [cpu-profiler] Fix script name when recording inlining info Use the script name from the shared function info to create an inline entry. Otherwise functions are attributed to the wrong file in the CpuProfileNode. See googleapis/cloud-profiler-nodejs#89 Bug: v8:7203, v8:7241 Change-Id: I8ea31943741770e6611275a9c93375922b934547 Reviewed-on: https://chromium-review.googlesource.com/848093 Reviewed-by: Jaroslav Sevcik <jarin@chromium.org> Commit-Queue: Franziska Hinkelmann <franzih@chromium.org> Cr-Commit-Position: refs/heads/master@{#50339} Refs: v8/v8@76c3ac5 PR-URL: #18298 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 9236332 commit ab00559

File tree

3 files changed

+92
-6
lines changed

3 files changed

+92
-6
lines changed

deps/v8/include/v8-version.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#define V8_MAJOR_VERSION 6
1212
#define V8_MINOR_VERSION 2
1313
#define V8_BUILD_NUMBER 414
14-
#define V8_PATCH_LEVEL 53
14+
#define V8_PATCH_LEVEL 54
1515

1616
// Use 1 for candidates and 0 otherwise.
1717
// (Boolean macro values are not supported by all preprocessors.)

deps/v8/src/profiler/profiler-listener.cc

+12-5
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,18 @@ void ProfilerListener::RecordInliningInfo(CodeEntry* entry,
226226
SharedFunctionInfo* shared_info = SharedFunctionInfo::cast(
227227
deopt_input_data->LiteralArray()->get(shared_info_id));
228228
if (!depth++) continue; // Skip the current function itself.
229-
CodeEntry* inline_entry = new CodeEntry(
230-
entry->tag(), GetFunctionName(shared_info->DebugName()),
231-
CodeEntry::kEmptyNamePrefix, entry->resource_name(),
232-
CpuProfileNode::kNoLineNumberInfo,
233-
CpuProfileNode::kNoColumnNumberInfo, NULL, code->instruction_start());
229+
const char* resource_name =
230+
(shared_info->script()->IsScript() &&
231+
Script::cast(shared_info->script())->name()->IsName())
232+
? GetName(Name::cast(Script::cast(shared_info->script())->name()))
233+
: CodeEntry::kEmptyResourceName;
234+
235+
CodeEntry* inline_entry =
236+
new CodeEntry(entry->tag(), GetFunctionName(shared_info->DebugName()),
237+
CodeEntry::kEmptyNamePrefix, resource_name,
238+
CpuProfileNode::kNoLineNumberInfo,
239+
CpuProfileNode::kNoColumnNumberInfo, nullptr,
240+
code->instruction_start());
234241
inline_entry->FillFunctionInfo(shared_info);
235242
inline_stack.push_back(inline_entry);
236243
}

deps/v8/test/cctest/test-cpu-profiler.cc

+79
Original file line numberDiff line numberDiff line change
@@ -1745,6 +1745,85 @@ TEST(FunctionDetails) {
17451745
script_a->GetUnboundScript()->GetId(), 5, 14);
17461746
}
17471747

1748+
TEST(FunctionDetailsInlining) {
1749+
if (!CcTest::i_isolate()->use_optimizer() || i::FLAG_always_opt) return;
1750+
i::FLAG_allow_natives_syntax = true;
1751+
v8::HandleScope scope(CcTest::isolate());
1752+
v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION);
1753+
v8::Context::Scope context_scope(env);
1754+
ProfilerHelper helper(env);
1755+
1756+
// alpha is in a_script, beta in b_script. beta is
1757+
// inlined in alpha, but it should be attributed to b_script.
1758+
1759+
v8::Local<v8::Script> script_b = CompileWithOrigin(
1760+
"function beta(k) {\n"
1761+
" let sum = 2;\n"
1762+
" for(let i = 0; i < k; i ++) {\n"
1763+
" sum += i;\n"
1764+
" sum = sum + 'a';\n"
1765+
" }\n"
1766+
" return sum;\n"
1767+
"}\n"
1768+
"\n",
1769+
"script_b");
1770+
1771+
v8::Local<v8::Script> script_a = CompileWithOrigin(
1772+
"function alpha(p) {\n"
1773+
" let res = beta(p);\n"
1774+
" res = res + res;\n"
1775+
" return res;\n"
1776+
"}\n"
1777+
"let p = 2;\n"
1778+
"\n"
1779+
"\n"
1780+
"// Warm up before profiling or the inlining doesn't happen.\n"
1781+
"p = alpha(p);\n"
1782+
"p = alpha(p);\n"
1783+
"%OptimizeFunctionOnNextCall(alpha);\n"
1784+
"p = alpha(p);\n"
1785+
"\n"
1786+
"\n"
1787+
"startProfiling();\n"
1788+
"for(let i = 0; i < 10000; i++) {\n"
1789+
" p = alpha(p);\n"
1790+
"}\n"
1791+
"stopProfiling();\n"
1792+
"\n"
1793+
"\n",
1794+
"script_a");
1795+
1796+
script_b->Run(env).ToLocalChecked();
1797+
script_a->Run(env).ToLocalChecked();
1798+
1799+
const v8::CpuProfile* profile = i::ProfilerExtension::last_profile;
1800+
const v8::CpuProfileNode* current = profile->GetTopDownRoot();
1801+
reinterpret_cast<ProfileNode*>(const_cast<v8::CpuProfileNode*>(current))
1802+
->Print(0);
1803+
// The tree should look like this:
1804+
// 0 (root) 0 #1
1805+
// 5 (program) 0 #6
1806+
// 2 14 #2 script_a:1
1807+
// ;;; deopted at script_id: 14 position: 299 with reason 'Insufficient
1808+
// type feedback for call'.
1809+
// 1 alpha 14 #4 script_a:1
1810+
// 9 beta 13 #5 script_b:0
1811+
// 0 startProfiling 0 #3
1812+
1813+
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
1814+
const v8::CpuProfileNode* script = GetChild(env, root, "");
1815+
CheckFunctionDetails(env->GetIsolate(), script, "", "script_a",
1816+
script_a->GetUnboundScript()->GetId(), 1, 1);
1817+
const v8::CpuProfileNode* alpha = FindChild(env, script, "alpha");
1818+
// Return early if profiling didn't sample alpha.
1819+
if (!alpha) return;
1820+
CheckFunctionDetails(env->GetIsolate(), alpha, "alpha", "script_a",
1821+
script_a->GetUnboundScript()->GetId(), 1, 15);
1822+
const v8::CpuProfileNode* beta = FindChild(env, alpha, "beta");
1823+
if (!beta) return;
1824+
CheckFunctionDetails(env->GetIsolate(), beta, "beta", "script_b",
1825+
script_b->GetUnboundScript()->GetId(), 0, 0);
1826+
}
17481827

17491828
TEST(DontStopOnFinishedProfileDelete) {
17501829
v8::HandleScope scope(CcTest::isolate());

0 commit comments

Comments
 (0)