Remove TimelineTraceEventProcessor since no current ports use it
[WebKit-https.git] / Source / WebCore / inspector / InspectorTimelineAgent.h
1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 *     * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *     * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 *     * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #ifndef InspectorTimelineAgent_h
32 #define InspectorTimelineAgent_h
33
34 #if ENABLE(INSPECTOR)
35
36 #include "InspectorBaseAgent.h"
37 #include "InspectorFrontend.h"
38 #include "InspectorValues.h"
39 #include "LayoutRect.h"
40 #include "PlatformInstrumentation.h"
41 #include "ScriptGCEvent.h"
42 #include "ScriptGCEventListener.h"
43 #include <wtf/PassOwnPtr.h>
44 #include <wtf/Vector.h>
45 #include <wtf/WeakPtr.h>
46
47 namespace WebCore {
48 class Event;
49 class FloatQuad;
50 class Frame;
51 class InspectorClient;
52 class InspectorFrontend;
53 class InspectorMemoryAgent;
54 class InspectorPageAgent;
55 class InspectorState;
56 class InstrumentingAgents;
57 class IntRect;
58 class KURL;
59 class Page;
60 class RenderObject;
61 class ResourceRequest;
62 class ResourceResponse;
63
64 typedef String ErrorString;
65
66 namespace TimelineRecordType {
67 extern const char DecodeImage[];
68 extern const char Rasterize[];
69 };
70
71 class TimelineTimeConverter {
72 public:
73     TimelineTimeConverter()
74         : m_startOffset(0)
75     {
76     }
77     double fromMonotonicallyIncreasingTime(double time) const  { return (time - m_startOffset) * 1000.0; }
78     void reset();
79
80 private:
81     double m_startOffset;
82 };
83
84 class InspectorTimelineAgent
85     : public InspectorBaseAgent<InspectorTimelineAgent>,
86       public ScriptGCEventListener,
87       public InspectorBackendDispatcher::TimelineCommandHandler,
88       public PlatformInstrumentationClient {
89     WTF_MAKE_NONCOPYABLE(InspectorTimelineAgent);
90 public:
91     enum InspectorType { PageInspector, WorkerInspector };
92
93     static PassOwnPtr<InspectorTimelineAgent> create(InstrumentingAgents* instrumentingAgents, InspectorPageAgent* pageAgent, InspectorMemoryAgent* memoryAgent, InspectorCompositeState* state, InspectorType type, InspectorClient* client)
94     {
95         return adoptPtr(new InspectorTimelineAgent(instrumentingAgents, pageAgent, memoryAgent, state, type, client));
96     }
97
98     ~InspectorTimelineAgent();
99
100     virtual void setFrontend(InspectorFrontend*);
101     virtual void clearFrontend();
102     virtual void restore();
103
104     virtual void start(ErrorString*, const int* maxCallStackDepth, const bool* includeDomCounters, const bool* includeNativeMemoryStatistics);
105     virtual void stop(ErrorString*);
106     virtual void canMonitorMainThread(ErrorString*, bool*);
107     virtual void supportsFrameInstrumentation(ErrorString*, bool*);
108
109     int id() const { return m_id; }
110
111     void didCommitLoad();
112
113     // Methods called from WebCore.
114     void willCallFunction(const String& scriptName, int scriptLine, Frame*);
115     void didCallFunction();
116
117     void willDispatchEvent(const Event&, Frame*);
118     void didDispatchEvent();
119
120     void didBeginFrame();
121     void didCancelFrame();
122
123     void didInvalidateLayout(Frame*);
124     void willLayout(Frame*);
125     void didLayout(RenderObject*);
126
127     void didScheduleStyleRecalculation(Frame*);
128     void willRecalculateStyle(Frame*);
129     void didRecalculateStyle();
130
131     void willPaint(Frame*);
132     void didPaint(RenderObject*, const LayoutRect&);
133
134     void willScroll(Frame*);
135     void didScroll();
136
137     void willComposite();
138     void didComposite();
139
140     void willWriteHTML(unsigned startLine, Frame*);
141     void didWriteHTML(unsigned endLine);
142
143     void didInstallTimer(int timerId, int timeout, bool singleShot, Frame*);
144     void didRemoveTimer(int timerId, Frame*);
145     void willFireTimer(int timerId, Frame*);
146     void didFireTimer();
147
148     void willDispatchXHRReadyStateChangeEvent(const String&, int, Frame*);
149     void didDispatchXHRReadyStateChangeEvent();
150     void willDispatchXHRLoadEvent(const String&, Frame*);
151     void didDispatchXHRLoadEvent();
152
153     void willEvaluateScript(const String&, int, Frame*);
154     void didEvaluateScript();
155
156     void didTimeStamp(Frame*, const String&);
157     void didMarkDOMContentEvent(Frame*);
158     void didMarkLoadEvent(Frame*);
159
160     void time(Frame*, const String&);
161     void timeEnd(Frame*, const String&);
162
163     void didScheduleResourceRequest(const String& url, Frame*);
164     void willSendResourceRequest(unsigned long, const ResourceRequest&, Frame*);
165     void willReceiveResourceResponse(unsigned long, const ResourceResponse&, Frame*);
166     void didReceiveResourceResponse();
167     void didFinishLoadingResource(unsigned long, bool didFail, double finishTime, Frame*);
168     void willReceiveResourceData(unsigned long identifier, Frame*, int length);
169     void didReceiveResourceData();
170
171     void didRequestAnimationFrame(int callbackId, Frame*);
172     void didCancelAnimationFrame(int callbackId, Frame*);
173     void willFireAnimationFrame(int callbackId, Frame*);
174     void didFireAnimationFrame();
175
176     void willProcessTask();
177     void didProcessTask();
178
179 #if ENABLE(WEB_SOCKETS)
180     void didCreateWebSocket(unsigned long identifier, const KURL&, const String& protocol, Frame*);
181     void willSendWebSocketHandshakeRequest(unsigned long identifier, Frame*);
182     void didReceiveWebSocketHandshakeResponse(unsigned long identifier, Frame*);
183     void didDestroyWebSocket(unsigned long identifier, Frame*);
184 #endif
185
186     // ScriptGCEventListener methods.
187     virtual void didGC(double, double, size_t);
188
189     // PlatformInstrumentationClient methods.
190     virtual void willDecodeImage(const String& imageType) OVERRIDE;
191     virtual void didDecodeImage() OVERRIDE;
192     virtual void willResizeImage(bool shouldCache) OVERRIDE;
193     virtual void didResizeImage() OVERRIDE;
194
195 private:
196     friend class TimelineRecordStack;
197
198     struct TimelineRecordEntry {
199         TimelineRecordEntry(PassRefPtr<InspectorObject> record, PassRefPtr<InspectorObject> data, PassRefPtr<InspectorArray> children, const String& type, size_t usedHeapSizeAtStart)
200             : record(record), data(data), children(children), type(type), usedHeapSizeAtStart(usedHeapSizeAtStart)
201         {
202         }
203         RefPtr<InspectorObject> record;
204         RefPtr<InspectorObject> data;
205         RefPtr<InspectorArray> children;
206         String type;
207         size_t usedHeapSizeAtStart;
208     };
209         
210     InspectorTimelineAgent(InstrumentingAgents*, InspectorPageAgent*, InspectorMemoryAgent*, InspectorCompositeState*, InspectorType, InspectorClient*);
211
212     void sendEvent(PassRefPtr<InspectorObject>);
213     void appendRecord(PassRefPtr<InspectorObject> data, const String& type, bool captureCallStack, Frame*);
214     void pushCurrentRecord(PassRefPtr<InspectorObject>, const String& type, bool captureCallStack, Frame*, bool hasLowLevelDetails = false);
215
216     void setDOMCounters(TypeBuilder::Timeline::TimelineEvent* record);
217     void setNativeHeapStatistics(TypeBuilder::Timeline::TimelineEvent* record);
218     void setFrameIdentifier(InspectorObject* record, Frame*);
219     void pushGCEventRecords();
220
221     void didCompleteCurrentRecord(const String& type);
222
223     void setHeapSizeStatistics(InspectorObject* record);
224     void commitFrameRecord();
225
226     void addRecordToTimeline(PassRefPtr<InspectorObject>, const String& type);
227     void innerAddRecordToTimeline(PassRefPtr<InspectorObject>, const String& type);
228     void clearRecordStack();
229
230     void localToPageQuad(const RenderObject& renderer, const LayoutRect&, FloatQuad*);
231     const TimelineTimeConverter& timeConverter() const { return m_timeConverter; }
232     double timestamp();
233     Page* page();
234
235     InspectorPageAgent* m_pageAgent;
236     InspectorMemoryAgent* m_memoryAgent;
237     TimelineTimeConverter m_timeConverter;
238
239     InspectorFrontend::Timeline* m_frontend;
240     double m_timestampOffset;
241
242     Vector<TimelineRecordEntry> m_recordStack;
243
244     int m_id;
245     struct GCEvent {
246         GCEvent(double startTime, double endTime, size_t collectedBytes)
247             : startTime(startTime), endTime(endTime), collectedBytes(collectedBytes)
248         {
249         }
250         double startTime;
251         double endTime;
252         size_t collectedBytes;
253     };
254     typedef Vector<GCEvent> GCEvents;
255     GCEvents m_gcEvents;
256     int m_maxCallStackDepth;
257     unsigned m_platformInstrumentationClientInstalledAtStackDepth;
258     RefPtr<InspectorObject> m_pendingFrameRecord;
259     InspectorType m_inspectorType;
260     InspectorClient* m_client;
261     WeakPtrFactory<InspectorTimelineAgent> m_weakFactory;
262 };
263
264 } // namespace WebCore
265
266 #endif // !ENABLE(INSPECTOR)
267 #endif // !defined(InspectorTimelineAgent_h)