Skip to content
This repository was archived by the owner on Apr 3, 2020. It is now read-only.

Commit 9a76647

Browse files
dp7darktears
authored andcommitted
Chromium CPU profiler: source line support
This is the second and final part of adding source line support in Chromium CPU profiler that needs to be done to move XDK CPU profiler on the same way as CDT uses. In brief, we need to do two things: 1) Map the samples to source lines during profiling session and add new V8 public API to get the hit source lines. These changes are already merged into v8-crosswalk. 2) The Chrome profilers works as follows: Chrome Browser ==(a "start/stop profiling" command)==> WebKit (WebSocket) ==> WebKit(InspectorBackendDispatcher) =="start/stop profiling"==> WebKit(InspectorProfilerAgent) ==V8 Public APIs (StartProfiling/Stopprofiling)==> V8. So, on StopProfiling command, WebKit(InspectorProfilerAgent) gets the collected results (using V8 public API) and packs them into JSON to send back to Chrome browser. This patch implements writing info about the hit source lines in JSON data to be sent back to Chromium browser. (cherry picked from commit f16d920) Re-enabling CPU profiling feature broken after migration to new v8.
1 parent eb70753 commit 9a76647

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

Source/core/inspector/ScriptProfile.cpp

+23
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,26 @@ double ScriptProfile::endTime() const
6464
return static_cast<double>(m_profile->GetEndTime()) / 1000000;
6565
}
6666

67+
static RefPtr<TypeBuilder::Array<TypeBuilder::Profiler::LineTick> > buildInspectorObjectForLineTicks(const v8::CpuProfileNode* node)
68+
{
69+
RefPtr<TypeBuilder::Array<TypeBuilder::Profiler::LineTick> > array = TypeBuilder::Array<TypeBuilder::Profiler::LineTick>::create();
70+
unsigned int lineCount = node->GetHitLineCount();
71+
if (lineCount) {
72+
Vector<v8::CpuProfileNode::LineTick> entries(lineCount);
73+
bool res = node->GetLineTicks(&entries[0], lineCount);
74+
if (res) {
75+
for (unsigned int i = 0; i < lineCount; i++) {
76+
RefPtr<TypeBuilder::Profiler::LineTick> line = TypeBuilder::Profiler::LineTick::create()
77+
.setLine(entries[i].line)
78+
.setTicks(entries[i].hit_count);
79+
array->addItem(line);
80+
line.release();
81+
}
82+
}
83+
}
84+
return array;
85+
}
86+
6787
static PassRefPtr<TypeBuilder::Profiler::CPUProfileNode> buildInspectorObjectFor(const v8::CpuProfileNode* node)
6888
{
6989
v8::HandleScope handleScope(v8::Isolate::GetCurrent());
@@ -75,6 +95,8 @@ static PassRefPtr<TypeBuilder::Profiler::CPUProfileNode> buildInspectorObjectFor
7595
children->addItem(buildInspectorObjectFor(child));
7696
}
7797

98+
RefPtr<TypeBuilder::Array<TypeBuilder::Profiler::LineTick> > lineTicks = buildInspectorObjectForLineTicks(node);
99+
78100
RefPtr<TypeBuilder::Profiler::CPUProfileNode> result = TypeBuilder::Profiler::CPUProfileNode::create()
79101
.setFunctionName(toCoreString(node->GetFunctionName()))
80102
.setScriptId(String::number(node->GetScriptId()))
@@ -84,6 +106,7 @@ static PassRefPtr<TypeBuilder::Profiler::CPUProfileNode> buildInspectorObjectFor
84106
.setHitCount(node->GetHitCount())
85107
.setCallUID(node->GetCallUid())
86108
.setChildren(children.release())
109+
.setLineTicks(lineTicks.release())
87110
.setDeoptReason(node->GetBailoutReason())
88111
.setId(node->GetNodeId());
89112
return result.release();

Source/devtools/protocol.json

+11-1
Original file line numberDiff line numberDiff line change
@@ -3638,7 +3638,8 @@
36383638
{ "name": "callUID", "type": "number", "description": "Call UID." },
36393639
{ "name": "children", "type": "array", "items": { "$ref": "CPUProfileNode" }, "description": "Child nodes." },
36403640
{ "name": "deoptReason", "type": "string", "description": "The reason of being not optimized. The function may be deoptimized or marked as don't optimize."},
3641-
{ "name": "id", "type": "integer", "description": "Unique id of the node." }
3641+
{ "name": "id", "type": "integer", "description": "Unique id of the node." },
3642+
{ "name": "lineTicks", "type": "array", "items": { "$ref": "LineTick" }, "description": "A set of source line ticks." }
36423643
]
36433644
},
36443645
{
@@ -3652,6 +3653,15 @@
36523653
{ "name": "samples", "optional": true, "type": "array", "items": { "type": "integer" }, "description": "Ids of samples top nodes." },
36533654
{ "name": "timestamps", "optional": true, "type": "array", "items": { "type": "number" }, "description": "Timestamps of the samples in microseconds." }
36543655
]
3656+
},
3657+
{
3658+
"id": "LineTick",
3659+
"type": "object",
3660+
"description": "Specifies a number of samples attributed to a certain source line.",
3661+
"properties": [
3662+
{ "name": "line", "type": "integer", "description": "Source line number." },
3663+
{ "name": "ticks", "type": "integer", "description": "Number of samples attributed to a source line number." }
3664+
]
36553665
}
36563666
],
36573667
"commands": [

0 commit comments

Comments
 (0)