Web Inspector: Hook the sampling profiler into the Timelines UI
authorsbarati@apple.com <sbarati@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 20 Jan 2016 21:51:00 +0000 (21:51 +0000)
committersbarati@apple.com <sbarati@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 20 Jan 2016 21:51:00 +0000 (21:51 +0000)
commit0271235be54c2d1a629cc25e1e27fe5b589d2ef4
treea72502ca2f693c2f0583e2abba72311c4a5dc979
parent47f705c8fa35c656fabf3db318a23070aab24a3e
Web Inspector: Hook the sampling profiler into the Timelines UI
https://bugs.webkit.org/show_bug.cgi?id=152766
<rdar://problem/24066360>

Reviewed by Joseph Pecoraro.

Source/JavaScriptCore:

This patch adds some necessary functions to SamplingProfiler::StackFrame
to allow it to give data to the Inspector for the timelines UI. i.e, the
sourceID of the executable of a stack frame.

This patch also swaps in the SamplingProfiler in place of the
LegacyProfiler inside InspectorScriptProfilerAgent. It adds
the necessary protocol data to allow the SamplingProfiler's
data to hook into the timelines UI.

* debugger/Debugger.cpp:
(JSC::Debugger::setProfilingClient):
(JSC::Debugger::willEvaluateScript):
(JSC::Debugger::didEvaluateScript):
(JSC::Debugger::toggleBreakpoint):
* debugger/Debugger.h:
* debugger/ScriptProfilingScope.h:
(JSC::ScriptProfilingScope::ScriptProfilingScope):
(JSC::ScriptProfilingScope::~ScriptProfilingScope):
* inspector/agents/InspectorScriptProfilerAgent.cpp:
(Inspector::InspectorScriptProfilerAgent::willDestroyFrontendAndBackend):
(Inspector::InspectorScriptProfilerAgent::startTracking):
(Inspector::InspectorScriptProfilerAgent::stopTracking):
(Inspector::InspectorScriptProfilerAgent::isAlreadyProfiling):
(Inspector::InspectorScriptProfilerAgent::willEvaluateScript):
(Inspector::InspectorScriptProfilerAgent::didEvaluateScript):
(Inspector::InspectorScriptProfilerAgent::addEvent):
(Inspector::buildSamples):
(Inspector::InspectorScriptProfilerAgent::trackingComplete):
(Inspector::buildAggregateCallInfoInspectorObject): Deleted.
(Inspector::buildInspectorObject): Deleted.
(Inspector::buildProfileInspectorObject): Deleted.
* inspector/agents/InspectorScriptProfilerAgent.h:
* inspector/protocol/ScriptProfiler.json:
* jsc.cpp:
(functionSamplingProfilerStackTraces):
* runtime/SamplingProfiler.cpp:
(JSC::SamplingProfiler::start):
(JSC::SamplingProfiler::stop):
(JSC::SamplingProfiler::clearData):
(JSC::SamplingProfiler::StackFrame::displayName):
(JSC::SamplingProfiler::StackFrame::displayNameForJSONTests):
(JSC::SamplingProfiler::StackFrame::startLine):
(JSC::SamplingProfiler::StackFrame::startColumn):
(JSC::SamplingProfiler::StackFrame::sourceID):
(JSC::SamplingProfiler::StackFrame::url):
(JSC::SamplingProfiler::stackTraces):
(JSC::SamplingProfiler::stackTracesAsJSON):
(JSC::displayName): Deleted.
(JSC::SamplingProfiler::stacktracesAsJSON): Deleted.
* runtime/SamplingProfiler.h:
(JSC::SamplingProfiler::StackFrame::StackFrame):
(JSC::SamplingProfiler::getLock):
(JSC::SamplingProfiler::setTimingInterval):
(JSC::SamplingProfiler::totalTime):
(JSC::SamplingProfiler::setStopWatch):
(JSC::SamplingProfiler::stackTraces): Deleted.
* tests/stress/sampling-profiler-anonymous-function.js:
(platformSupportsSamplingProfiler.baz):
(platformSupportsSamplingProfiler):
* tests/stress/sampling-profiler-basic.js:
(platformSupportsSamplingProfiler.nothing):
(platformSupportsSamplingProfiler.top):
* tests/stress/sampling-profiler/samplingProfiler.js:
(doesTreeHaveStackTrace):

Source/WebInspectorUI:

The main change in this patch is to swap in the SamplingProfiler
in place of the LegacyProfiler. To do this, we've created a data
structure called CallingContextTree which aggregates the SamplingProfiler's
data into an easy to manage tree. To see how the data structure works,
consider the following program:
```
function bar() { // run code here for a long time. }
function baz() { // run code here for a long time. }
function foo() { bar(); baz(); }
foo();
```
From this program, we will create a tree like this:
                (program)
                    |
                    |
                   foo
                   | |
                  /   \
                 /     \
                bar     baz

From this type of tree, we can easily create a CPUProfile payload
object. Because the Timelines UI knows how to interact with the
CPUProfile object and display it, we currently map the tree to this object
to make it trivially easy to display the SamplingProfiler's data. In the future,
we may want to find ways to work directly with the CallingContextTree instead
of mapping it into another object.

* Localizations/en.lproj/localizedStrings.js:
* UserInterface/Controllers/TimelineManager.js:
* UserInterface/Main.html:
* UserInterface/Models/CallingContextTree.js: Added.
* UserInterface/Models/ScriptInstrument.js:
* UserInterface/Protocol/ScriptProfilerObserver.js:
* UserInterface/TestStub.html:
* UserInterface/Views/ScriptTimelineView.js:

LayoutTests:

* inspector/sampling-profiler: Added.
* inspector/sampling-profiler/basic-expected.txt: Added.
* inspector/sampling-profiler/basic.html: Added.
* inspector/sampling-profiler/call-frame-with-dom-functions-expected.txt: Added.
* inspector/sampling-profiler/call-frame-with-dom-functions.html: Added.
* inspector/sampling-profiler/eval-source-url-expected.txt: Added.
* inspector/sampling-profiler/eval-source-url.html: Added.
* inspector/sampling-profiler/many-call-frames-expected.txt: Added.
* inspector/sampling-profiler/many-call-frames.html: Added.
* inspector/sampling-profiler/named-function-expression-expected.txt: Added.
* inspector/sampling-profiler/named-function-expression.html: Added.
* inspector/script-profiler/event-type-API-expected.txt:
* inspector/script-profiler/event-type-API.html:
* inspector/script-profiler/event-type-Microtask-expected.txt:
* inspector/script-profiler/event-type-Microtask.html:
* inspector/script-profiler/event-type-Other-expected.txt:
* inspector/script-profiler/event-type-Other.html:
* inspector/script-profiler/tracking-expected.txt:
* inspector/script-profiler/tracking.html:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@195376 268f45cc-cd09-0410-ab3c-d52691b4dbfc
41 files changed:
LayoutTests/ChangeLog
LayoutTests/inspector/sampling-profiler/basic-expected.txt [new file with mode: 0644]
LayoutTests/inspector/sampling-profiler/basic.html [new file with mode: 0644]
LayoutTests/inspector/sampling-profiler/call-frame-with-dom-functions-expected.txt [new file with mode: 0644]
LayoutTests/inspector/sampling-profiler/call-frame-with-dom-functions.html [new file with mode: 0644]
LayoutTests/inspector/sampling-profiler/eval-source-url-expected.txt [new file with mode: 0644]
LayoutTests/inspector/sampling-profiler/eval-source-url.html [new file with mode: 0644]
LayoutTests/inspector/sampling-profiler/many-call-frames-expected.txt [new file with mode: 0644]
LayoutTests/inspector/sampling-profiler/many-call-frames.html [new file with mode: 0644]
LayoutTests/inspector/sampling-profiler/named-function-expression-expected.txt [new file with mode: 0644]
LayoutTests/inspector/sampling-profiler/named-function-expression.html [new file with mode: 0644]
LayoutTests/inspector/script-profiler/event-type-API-expected.txt
LayoutTests/inspector/script-profiler/event-type-API.html
LayoutTests/inspector/script-profiler/event-type-Microtask-expected.txt
LayoutTests/inspector/script-profiler/event-type-Microtask.html
LayoutTests/inspector/script-profiler/event-type-Other-expected.txt
LayoutTests/inspector/script-profiler/event-type-Other.html
LayoutTests/inspector/script-profiler/tracking-expected.txt
LayoutTests/inspector/script-profiler/tracking.html
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/debugger/Debugger.cpp
Source/JavaScriptCore/debugger/Debugger.h
Source/JavaScriptCore/debugger/ScriptProfilingScope.h
Source/JavaScriptCore/inspector/agents/InspectorScriptProfilerAgent.cpp
Source/JavaScriptCore/inspector/agents/InspectorScriptProfilerAgent.h
Source/JavaScriptCore/inspector/protocol/ScriptProfiler.json
Source/JavaScriptCore/jsc.cpp
Source/JavaScriptCore/runtime/SamplingProfiler.cpp
Source/JavaScriptCore/runtime/SamplingProfiler.h
Source/JavaScriptCore/tests/stress/sampling-profiler-anonymous-function.js
Source/JavaScriptCore/tests/stress/sampling-profiler-basic.js
Source/JavaScriptCore/tests/stress/sampling-profiler/samplingProfiler.js
Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js
Source/WebInspectorUI/UserInterface/Controllers/TimelineManager.js
Source/WebInspectorUI/UserInterface/Main.html
Source/WebInspectorUI/UserInterface/Models/CallingContextTree.js [new file with mode: 0644]
Source/WebInspectorUI/UserInterface/Models/ScriptInstrument.js
Source/WebInspectorUI/UserInterface/Protocol/ScriptProfilerObserver.js
Source/WebInspectorUI/UserInterface/TestStub.html
Source/WebInspectorUI/UserInterface/Views/ScriptTimelineView.js