Web Inspector: Remove unused Timeline GCEvent Record type
[WebKit-https.git] / Source / WebCore / inspector / TimelineRecordFactory.cpp
1 /*
2  * Copyright (C) 2009 Google Inc. All rights reserved.
3  * Copyright (C) 2014 University of Washington.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  *     * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *     * Redistributions in binary form must reproduce the above
12  * copyright notice, this list of conditions and the following disclaimer
13  * in the documentation and/or other materials provided with the
14  * distribution.
15  *     * Neither the name of Google Inc. nor the names of its
16  * contributors may be used to endorse or promote products derived from
17  * this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31
32 #include "config.h"
33 #include "TimelineRecordFactory.h"
34
35 #include "Event.h"
36 #include "FloatQuad.h"
37 #include "IntRect.h"
38 #include "JSMainThreadExecState.h"
39 #include "LayoutRect.h"
40 #include "ResourceRequest.h"
41 #include "ResourceResponse.h"
42 #include <inspector/InspectorProtocolObjects.h>
43 #include <inspector/ScriptBreakpoint.h>
44 #include <inspector/ScriptCallStack.h>
45 #include <inspector/ScriptCallStackFactory.h>
46 #include <profiler/Profile.h>
47
48 using namespace Inspector;
49
50 namespace WebCore {
51
52 Ref<InspectorObject> TimelineRecordFactory::createGenericRecord(double startTime, int maxCallStackDepth)
53 {
54     Ref<InspectorObject> record = InspectorObject::create();
55     record->setDouble("startTime", startTime);
56
57     if (maxCallStackDepth) {
58         RefPtr<ScriptCallStack> stackTrace = createScriptCallStack(JSMainThreadExecState::currentState(), maxCallStackDepth);
59         if (stackTrace && stackTrace->size())
60             record->setValue("stackTrace", stackTrace->buildInspectorArray());
61     }
62     return WTF::move(record);
63 }
64
65 Ref<InspectorObject> TimelineRecordFactory::createBackgroundRecord(double startTime, const String& threadName)
66 {
67     Ref<InspectorObject> record = InspectorObject::create();
68     record->setDouble("startTime", startTime);
69     record->setString("thread", threadName);
70     return WTF::move(record);
71 }
72
73 Ref<InspectorObject> TimelineRecordFactory::createFunctionCallData(const String& scriptName, int scriptLine)
74 {
75     Ref<InspectorObject> data = InspectorObject::create();
76     data->setString("scriptName", scriptName);
77     data->setInteger("scriptLine", scriptLine);
78     return WTF::move(data);
79 }
80
81 Ref<InspectorObject> TimelineRecordFactory::createConsoleProfileData(const String& title)
82 {
83     Ref<InspectorObject> data = InspectorObject::create();
84     data->setString("title", title);
85     return WTF::move(data);
86 }
87
88 Ref<InspectorObject> TimelineRecordFactory::createProbeSampleData(const ScriptBreakpointAction& action, unsigned sampleId)
89 {
90     Ref<InspectorObject> data = InspectorObject::create();
91     data->setInteger(ASCIILiteral("probeId"), action.identifier);
92     data->setInteger(ASCIILiteral("sampleId"), sampleId);
93     return WTF::move(data);
94 }
95
96 Ref<InspectorObject> TimelineRecordFactory::createEventDispatchData(const Event& event)
97 {
98     Ref<InspectorObject> data = InspectorObject::create();
99     data->setString("type", event.type().string());
100     return WTF::move(data);
101 }
102
103 Ref<InspectorObject> TimelineRecordFactory::createGenericTimerData(int timerId)
104 {
105     Ref<InspectorObject> data = InspectorObject::create();
106     data->setInteger("timerId", timerId);
107     return WTF::move(data);
108 }
109
110 Ref<InspectorObject> TimelineRecordFactory::createTimerInstallData(int timerId, int timeout, bool singleShot)
111 {
112     Ref<InspectorObject> data = InspectorObject::create();
113     data->setInteger("timerId", timerId);
114     data->setInteger("timeout", timeout);
115     data->setBoolean("singleShot", singleShot);
116     return WTF::move(data);
117 }
118
119 Ref<InspectorObject> TimelineRecordFactory::createXHRReadyStateChangeData(const String& url, int readyState)
120 {
121     Ref<InspectorObject> data = InspectorObject::create();
122     data->setString("url", url);
123     data->setInteger("readyState", readyState);
124     return WTF::move(data);
125 }
126
127 Ref<InspectorObject> TimelineRecordFactory::createXHRLoadData(const String& url)
128 {
129     Ref<InspectorObject> data = InspectorObject::create();
130     data->setString("url", url);
131     return WTF::move(data);
132 }
133
134 Ref<InspectorObject> TimelineRecordFactory::createEvaluateScriptData(const String& url, double lineNumber)
135 {
136     Ref<InspectorObject> data = InspectorObject::create();
137     data->setString("url", url);
138     data->setInteger("lineNumber", lineNumber);
139     return WTF::move(data);
140 }
141
142 Ref<InspectorObject> TimelineRecordFactory::createTimeStampData(const String& message)
143 {
144     Ref<InspectorObject> data = InspectorObject::create();
145     data->setString("message", message);
146     return WTF::move(data);
147 }
148
149 Ref<InspectorObject> TimelineRecordFactory::createLayoutData(unsigned dirtyObjects, unsigned totalObjects, bool partialLayout)
150 {
151     Ref<InspectorObject> data = InspectorObject::create();
152     data->setInteger("dirtyObjects", dirtyObjects);
153     data->setInteger("totalObjects", totalObjects);
154     data->setBoolean("partialLayout", partialLayout);
155     return WTF::move(data);
156 }
157
158 Ref<InspectorObject> TimelineRecordFactory::createMarkData(bool isMainFrame)
159 {
160     Ref<InspectorObject> data = InspectorObject::create();
161     data->setBoolean("isMainFrame", isMainFrame);
162     return WTF::move(data);
163 }
164
165 Ref<InspectorObject> TimelineRecordFactory::createParseHTMLData(unsigned startLine)
166 {
167     Ref<InspectorObject> data = InspectorObject::create();
168     data->setInteger("startLine", startLine);
169     return WTF::move(data);
170 }
171
172 Ref<InspectorObject> TimelineRecordFactory::createAnimationFrameData(int callbackId)
173 {
174     Ref<InspectorObject> data = InspectorObject::create();
175     data->setInteger("id", callbackId);
176     return WTF::move(data);
177 }
178
179 static Ref<InspectorArray> createQuad(const FloatQuad& quad)
180 {
181     Ref<InspectorArray> array = InspectorArray::create();
182     array->pushDouble(quad.p1().x());
183     array->pushDouble(quad.p1().y());
184     array->pushDouble(quad.p2().x());
185     array->pushDouble(quad.p2().y());
186     array->pushDouble(quad.p3().x());
187     array->pushDouble(quad.p3().y());
188     array->pushDouble(quad.p4().x());
189     array->pushDouble(quad.p4().y());
190     return WTF::move(array);
191 }
192
193 Ref<InspectorObject> TimelineRecordFactory::createPaintData(const FloatQuad& quad)
194 {
195     Ref<InspectorObject> data = InspectorObject::create();
196     data->setArray("clip", createQuad(quad));
197     return WTF::move(data);
198 }
199
200 void TimelineRecordFactory::appendLayoutRoot(InspectorObject* data, const FloatQuad& quad)
201 {
202     data->setArray("root", createQuad(quad));
203 }
204
205 static Ref<Protocol::Timeline::CPUProfileNodeAggregateCallInfo> buildAggregateCallInfoInspectorObject(const JSC::ProfileNode* node)
206 {
207     double startTime = node->calls()[0].startTime();
208     double endTime = node->calls().last().startTime() + node->calls().last().elapsedTime();
209
210     double totalTime = 0;
211     for (const JSC::ProfileNode::Call& call : node->calls())
212         totalTime += call.elapsedTime();
213
214     return Protocol::Timeline::CPUProfileNodeAggregateCallInfo::create()
215         .setCallCount(node->calls().size())
216         .setStartTime(startTime)
217         .setEndTime(endTime)
218         .setTotalTime(totalTime)
219         .release();
220 }
221
222 static Ref<Protocol::Timeline::CPUProfileNode> buildInspectorObject(const JSC::ProfileNode* node)
223 {
224     auto result = Protocol::Timeline::CPUProfileNode::create()
225         .setId(node->id())
226         .setCallInfo(buildAggregateCallInfoInspectorObject(node))
227         .release();
228
229     if (!node->functionName().isEmpty())
230         result->setFunctionName(node->functionName());
231
232     if (!node->url().isEmpty()) {
233         result->setUrl(node->url());
234         result->setLineNumber(node->lineNumber());
235         result->setColumnNumber(node->columnNumber());
236     }
237
238     if (!node->children().isEmpty()) {
239         auto children = Protocol::Array<Protocol::Timeline::CPUProfileNode>::create();
240         for (RefPtr<JSC::ProfileNode> profileNode : node->children())
241             children->addItem(buildInspectorObject(profileNode.get()));
242         result->setChildren(WTF::move(children));
243     }
244
245     return WTF::move(result);
246 }
247
248 static Ref<Protocol::Timeline::CPUProfile> buildProfileInspectorObject(const JSC::Profile* profile)
249 {
250     auto rootNodes = Protocol::Array<Protocol::Timeline::CPUProfileNode>::create();
251     for (RefPtr<JSC::ProfileNode> profileNode : profile->rootNode()->children())
252         rootNodes->addItem(buildInspectorObject(profileNode.get()));
253
254     return Protocol::Timeline::CPUProfile::create()
255         .setRootNodes(WTF::move(rootNodes))
256         .release();
257 }
258
259 void TimelineRecordFactory::appendProfile(InspectorObject* data, RefPtr<JSC::Profile>&& profile)
260 {
261     data->setValue(ASCIILiteral("profile"), buildProfileInspectorObject(profile.get()));
262 }
263
264 } // namespace WebCore