InspectorTimelineAgent.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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. #ifndef InspectorTimelineAgent_h
  31. #define InspectorTimelineAgent_h
  32. #if ENABLE(INSPECTOR)
  33. #include "InspectorBaseAgent.h"
  34. #include "InspectorFrontend.h"
  35. #include "InspectorValues.h"
  36. #include "LayoutRect.h"
  37. #include "PlatformInstrumentation.h"
  38. #include "ScriptGCEvent.h"
  39. #include "ScriptGCEventListener.h"
  40. #include <wtf/PassOwnPtr.h>
  41. #include <wtf/Vector.h>
  42. #include <wtf/WeakPtr.h>
  43. namespace WebCore {
  44. class Event;
  45. class FloatQuad;
  46. class Frame;
  47. class InspectorClient;
  48. class InspectorFrontend;
  49. class InspectorMemoryAgent;
  50. class InspectorPageAgent;
  51. class InspectorState;
  52. class InstrumentingAgents;
  53. class IntRect;
  54. class KURL;
  55. class Page;
  56. class RenderObject;
  57. class ResourceRequest;
  58. class ResourceResponse;
  59. class TimelineTraceEventProcessor;
  60. typedef String ErrorString;
  61. namespace TimelineRecordType {
  62. extern const char DecodeImage[];
  63. extern const char Rasterize[];
  64. };
  65. class TimelineTimeConverter {
  66. public:
  67. TimelineTimeConverter()
  68. : m_startOffset(0)
  69. {
  70. }
  71. double fromMonotonicallyIncreasingTime(double time) const { return (time - m_startOffset) * 1000.0; }
  72. void reset();
  73. private:
  74. double m_startOffset;
  75. };
  76. class InspectorTimelineAgent
  77. : public InspectorBaseAgent<InspectorTimelineAgent>,
  78. public ScriptGCEventListener,
  79. public InspectorBackendDispatcher::TimelineCommandHandler,
  80. public PlatformInstrumentationClient {
  81. WTF_MAKE_NONCOPYABLE(InspectorTimelineAgent);
  82. public:
  83. enum InspectorType { PageInspector, WorkerInspector };
  84. static PassOwnPtr<InspectorTimelineAgent> create(InstrumentingAgents* instrumentingAgents, InspectorPageAgent* pageAgent, InspectorMemoryAgent* memoryAgent, InspectorCompositeState* state, InspectorType type, InspectorClient* client)
  85. {
  86. return adoptPtr(new InspectorTimelineAgent(instrumentingAgents, pageAgent, memoryAgent, state, type, client));
  87. }
  88. ~InspectorTimelineAgent();
  89. virtual void setFrontend(InspectorFrontend*);
  90. virtual void clearFrontend();
  91. virtual void restore();
  92. virtual void start(ErrorString*, const int* maxCallStackDepth, const bool* includeDomCounters, const bool* includeNativeMemoryStatistics);
  93. virtual void stop(ErrorString*);
  94. virtual void canMonitorMainThread(ErrorString*, bool*);
  95. virtual void supportsFrameInstrumentation(ErrorString*, bool*);
  96. int id() const { return m_id; }
  97. void didCommitLoad();
  98. // Methods called from WebCore.
  99. void willCallFunction(const String& scriptName, int scriptLine, Frame*);
  100. void didCallFunction();
  101. void willDispatchEvent(const Event&, Frame*);
  102. void didDispatchEvent();
  103. void didBeginFrame();
  104. void didCancelFrame();
  105. void didInvalidateLayout(Frame*);
  106. void willLayout(Frame*);
  107. void didLayout(RenderObject*);
  108. void didScheduleStyleRecalculation(Frame*);
  109. void willRecalculateStyle(Frame*);
  110. void didRecalculateStyle();
  111. void willPaint(Frame*);
  112. void didPaint(RenderObject*, const LayoutRect&);
  113. void willScroll(Frame*);
  114. void didScroll();
  115. void willComposite();
  116. void didComposite();
  117. void willWriteHTML(unsigned startLine, Frame*);
  118. void didWriteHTML(unsigned endLine);
  119. void didInstallTimer(int timerId, int timeout, bool singleShot, Frame*);
  120. void didRemoveTimer(int timerId, Frame*);
  121. void willFireTimer(int timerId, Frame*);
  122. void didFireTimer();
  123. void willDispatchXHRReadyStateChangeEvent(const String&, int, Frame*);
  124. void didDispatchXHRReadyStateChangeEvent();
  125. void willDispatchXHRLoadEvent(const String&, Frame*);
  126. void didDispatchXHRLoadEvent();
  127. void willEvaluateScript(const String&, int, Frame*);
  128. void didEvaluateScript();
  129. void didTimeStamp(Frame*, const String&);
  130. void didMarkDOMContentEvent(Frame*);
  131. void didMarkLoadEvent(Frame*);
  132. void time(Frame*, const String&);
  133. void timeEnd(Frame*, const String&);
  134. void didScheduleResourceRequest(const String& url, Frame*);
  135. void willSendResourceRequest(unsigned long, const ResourceRequest&, Frame*);
  136. void willReceiveResourceResponse(unsigned long, const ResourceResponse&, Frame*);
  137. void didReceiveResourceResponse();
  138. void didFinishLoadingResource(unsigned long, bool didFail, double finishTime, Frame*);
  139. void willReceiveResourceData(unsigned long identifier, Frame*, int length);
  140. void didReceiveResourceData();
  141. void didRequestAnimationFrame(int callbackId, Frame*);
  142. void didCancelAnimationFrame(int callbackId, Frame*);
  143. void willFireAnimationFrame(int callbackId, Frame*);
  144. void didFireAnimationFrame();
  145. void willProcessTask();
  146. void didProcessTask();
  147. #if ENABLE(WEB_SOCKETS)
  148. void didCreateWebSocket(unsigned long identifier, const KURL&, const String& protocol, Frame*);
  149. void willSendWebSocketHandshakeRequest(unsigned long identifier, Frame*);
  150. void didReceiveWebSocketHandshakeResponse(unsigned long identifier, Frame*);
  151. void didDestroyWebSocket(unsigned long identifier, Frame*);
  152. #endif
  153. // ScriptGCEventListener methods.
  154. virtual void didGC(double, double, size_t);
  155. // PlatformInstrumentationClient methods.
  156. virtual void willDecodeImage(const String& imageType) OVERRIDE;
  157. virtual void didDecodeImage() OVERRIDE;
  158. virtual void willResizeImage(bool shouldCache) OVERRIDE;
  159. virtual void didResizeImage() OVERRIDE;
  160. private:
  161. friend class TimelineRecordStack;
  162. friend class TimelineTraceEventProcessor;
  163. struct TimelineRecordEntry {
  164. TimelineRecordEntry(PassRefPtr<InspectorObject> record, PassRefPtr<InspectorObject> data, PassRefPtr<InspectorArray> children, const String& type, size_t usedHeapSizeAtStart)
  165. : record(record), data(data), children(children), type(type), usedHeapSizeAtStart(usedHeapSizeAtStart)
  166. {
  167. }
  168. RefPtr<InspectorObject> record;
  169. RefPtr<InspectorObject> data;
  170. RefPtr<InspectorArray> children;
  171. String type;
  172. size_t usedHeapSizeAtStart;
  173. };
  174. InspectorTimelineAgent(InstrumentingAgents*, InspectorPageAgent*, InspectorMemoryAgent*, InspectorCompositeState*, InspectorType, InspectorClient*);
  175. void sendEvent(PassRefPtr<InspectorObject>);
  176. void appendRecord(PassRefPtr<InspectorObject> data, const String& type, bool captureCallStack, Frame*);
  177. void pushCurrentRecord(PassRefPtr<InspectorObject>, const String& type, bool captureCallStack, Frame*, bool hasLowLevelDetails = false);
  178. void setDOMCounters(TypeBuilder::Timeline::TimelineEvent* record);
  179. void setNativeHeapStatistics(TypeBuilder::Timeline::TimelineEvent* record);
  180. void setFrameIdentifier(InspectorObject* record, Frame*);
  181. void pushGCEventRecords();
  182. void didCompleteCurrentRecord(const String& type);
  183. void setHeapSizeStatistics(InspectorObject* record);
  184. void commitFrameRecord();
  185. void addRecordToTimeline(PassRefPtr<InspectorObject>, const String& type);
  186. void innerAddRecordToTimeline(PassRefPtr<InspectorObject>, const String& type);
  187. void clearRecordStack();
  188. void localToPageQuad(const RenderObject& renderer, const LayoutRect&, FloatQuad*);
  189. const TimelineTimeConverter& timeConverter() const { return m_timeConverter; }
  190. double timestamp();
  191. Page* page();
  192. InspectorPageAgent* m_pageAgent;
  193. InspectorMemoryAgent* m_memoryAgent;
  194. TimelineTimeConverter m_timeConverter;
  195. InspectorFrontend::Timeline* m_frontend;
  196. double m_timestampOffset;
  197. Vector<TimelineRecordEntry> m_recordStack;
  198. int m_id;
  199. struct GCEvent {
  200. GCEvent(double startTime, double endTime, size_t collectedBytes)
  201. : startTime(startTime), endTime(endTime), collectedBytes(collectedBytes)
  202. {
  203. }
  204. double startTime;
  205. double endTime;
  206. size_t collectedBytes;
  207. };
  208. typedef Vector<GCEvent> GCEvents;
  209. GCEvents m_gcEvents;
  210. int m_maxCallStackDepth;
  211. unsigned m_platformInstrumentationClientInstalledAtStackDepth;
  212. RefPtr<InspectorObject> m_pendingFrameRecord;
  213. InspectorType m_inspectorType;
  214. InspectorClient* m_client;
  215. WeakPtrFactory<InspectorTimelineAgent> m_weakFactory;
  216. RefPtr<TimelineTraceEventProcessor> m_traceEventProcessor;
  217. };
  218. } // namespace WebCore
  219. #endif // !ENABLE(INSPECTOR)
  220. #endif // !defined(InspectorTimelineAgent_h)