1 /* 2 * Copyright (C) 2009 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 "InspectorFrontend.h" 37 #include "InspectorValues.h" 38 #include "ScriptGCEvent.h" 39 #include "ScriptGCEventListener.h" 40 #include <wtf/PassOwnPtr.h> 41 #include <wtf/Vector.h> 42 43 namespace WebCore { 44 class Event; 45 class InspectorFrontend; 46 class InspectorState; 47 class InstrumentingAgents; 48 class IntRect; 49 class ResourceRequest; 50 class ResourceResponse; 51 52 typedef String ErrorString; 53 54 class InspectorTimelineAgent : ScriptGCEventListener { 55 WTF_MAKE_NONCOPYABLE(InspectorTimelineAgent); 56 public: create(InstrumentingAgents * instrumentingAgents,InspectorState * state)57 static PassOwnPtr<InspectorTimelineAgent> create(InstrumentingAgents* instrumentingAgents, InspectorState* state) 58 { 59 return adoptPtr(new InspectorTimelineAgent(instrumentingAgents, state)); 60 } 61 62 ~InspectorTimelineAgent(); 63 64 void setFrontend(InspectorFrontend*); 65 void clearFrontend(); 66 void restore(); 67 68 void start(ErrorString* error); 69 void stop(ErrorString* error); 70 bool started() const; 71 id()72 int id() const { return m_id; } 73 74 void didCommitLoad(); 75 76 // Methods called from WebCore. 77 void willCallFunction(const String& scriptName, int scriptLine); 78 void didCallFunction(); 79 80 void willDispatchEvent(const Event&); 81 void didDispatchEvent(); 82 83 void willLayout(); 84 void didLayout(); 85 86 void willRecalculateStyle(); 87 void didRecalculateStyle(); 88 89 void willPaint(const IntRect&); 90 void didPaint(); 91 92 // FIXME: |length| should be passed in didWrite instead willWrite 93 // as the parser can not know how much it will process until it tries. 94 void willWriteHTML(unsigned int length, unsigned int startLine); 95 void didWriteHTML(unsigned int endLine); 96 97 void didInstallTimer(int timerId, int timeout, bool singleShot); 98 void didRemoveTimer(int timerId); 99 void willFireTimer(int timerId); 100 void didFireTimer(); 101 102 void willChangeXHRReadyState(const String&, int); 103 void didChangeXHRReadyState(); 104 void willLoadXHR(const String&); 105 void didLoadXHR(); 106 107 void willEvaluateScript(const String&, int); 108 void didEvaluateScript(); 109 110 void didMarkTimeline(const String&); 111 void didMarkDOMContentEvent(); 112 void didMarkLoadEvent(); 113 114 void didScheduleResourceRequest(const String& url); 115 void willSendResourceRequest(unsigned long, const ResourceRequest&); 116 void willReceiveResourceResponse(unsigned long, const ResourceResponse&); 117 void didReceiveResourceResponse(); 118 void didFinishLoadingResource(unsigned long, bool didFail, double finishTime); 119 void willReceiveResourceData(unsigned long identifier); 120 void didReceiveResourceData(); 121 122 virtual void didGC(double, double, size_t); 123 124 private: 125 struct TimelineRecordEntry { TimelineRecordEntryTimelineRecordEntry126 TimelineRecordEntry(PassRefPtr<InspectorObject> record, PassRefPtr<InspectorObject> data, PassRefPtr<InspectorArray> children, const String& type) 127 : record(record), data(data), children(children), type(type) 128 { 129 } 130 RefPtr<InspectorObject> record; 131 RefPtr<InspectorObject> data; 132 RefPtr<InspectorArray> children; 133 String type; 134 }; 135 136 InspectorTimelineAgent(InstrumentingAgents*, InspectorState*); 137 138 void pushCurrentRecord(PassRefPtr<InspectorObject>, const String& type); 139 void setHeapSizeStatistic(InspectorObject* record); 140 141 void didCompleteCurrentRecord(const String& type); 142 143 void addRecordToTimeline(PassRefPtr<InspectorObject>, const String& type); 144 145 void pushGCEventRecords(); 146 void clearRecordStack(); 147 148 InstrumentingAgents* m_instrumentingAgents; 149 InspectorState* m_state; 150 InspectorFrontend::Timeline* m_frontend; 151 152 Vector<TimelineRecordEntry> m_recordStack; 153 154 int m_id; 155 struct GCEvent { GCEventGCEvent156 GCEvent(double startTime, double endTime, size_t collectedBytes) 157 : startTime(startTime), endTime(endTime), collectedBytes(collectedBytes) 158 { 159 } 160 double startTime; 161 double endTime; 162 size_t collectedBytes; 163 }; 164 typedef Vector<GCEvent> GCEvents; 165 GCEvents m_gcEvents; 166 }; 167 168 } // namespace WebCore 169 170 #endif // !ENABLE(INSPECTOR) 171 #endif // !defined(InspectorTimelineAgent_h) 172