Web Inspector: enable instrumentation of platform code
authorcaseq@chromium.org <caseq@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 16 Aug 2012 12:06:20 +0000 (12:06 +0000)
committercaseq@chromium.org <caseq@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 16 Aug 2012 12:06:20 +0000 (12:06 +0000)
https://bugs.webkit.org/show_bug.cgi?id=94125

Reviewed by Pavel Feldman.

- add PlatformInstrumentation class that exposes instrumentation methods that may be used by code under WebCore/platform;
- move TRACE_EVENT_XXX() macros into PlatformInstrumentation.h to minimize instrumentation hassle in the client code;
- implement PlatformInstrumentationClient by InspectorTimelineAgent;
- only install PlatformInstrumentationClient when we have outer events for which we expect low-level details

* CMakeLists.txt:
* GNUmakefile.list.am:
* Target.pri:
* WebCore.gypi:
* WebCore.vcproj/WebCore.vcproj:
* inspector/InspectorTimelineAgent.cpp:
(WebCore::InspectorTimelineAgent::willDecodeImage): to be implemented by subsequent change;
(WebCore::InspectorTimelineAgent::didDecodeImage): to be implemented by subsequent change;
(WebCore::InspectorTimelineAgent::willResizeImage): to be implemented by subsequent change;
(WebCore::InspectorTimelineAgent::didResizeImage): to be implemented by subsequent change;
(WebCore::InspectorTimelineAgent::didCompleteCurrentRecord):
(WebCore::InspectorTimelineAgent::InspectorTimelineAgent):
(WebCore::InspectorTimelineAgent::pushCurrentRecord):
(WebCore::InspectorTimelineAgent::clearRecordStack):
* inspector/InspectorTimelineAgent.h:
(InspectorTimelineAgent):
* platform/PlatformInstrumentation.cpp: Added.
(WebCore):
(WebCore::PlatformInstrumentation::setClient):
* platform/PlatformInstrumentation.h: Added.
(WebCore):
(PlatformInstrumentationClient):
(PlatformInstrumentation):
(WebCore::PlatformInstrumentation::hasClient):
(WebCore::PlatformInstrumentation::willDecodeImage):
(WebCore::PlatformInstrumentation::didDecodeImage):
(WebCore::PlatformInstrumentation::willResizeImage):
(WebCore::PlatformInstrumentation::didResizeImage):
* platform/graphics/skia/NativeImageSkia.cpp:
(WebCore::NativeImageSkia::resizedBitmap): added calls to PlatformInstrumentation, removed TRACE_EVENT();
* platform/image-decoders/bmp/BMPImageDecoder.cpp:
(WebCore::BMPImageDecoder::frameBufferAtIndex): added calls to PlatformInstrumentation;
(WebCore::BMPImageDecoder::decode): removed TRACE_EVENT()
* platform/image-decoders/gif/GIFImageDecoder.cpp:
(WebCore::GIFImageDecoder::frameBufferAtIndex): added calls to PlatformInstrumentation;
(WebCore::GIFImageDecoder::decode): removed TRACE_EVENT()
* platform/image-decoders/ico/ICOImageDecoder.cpp:
(WebCore::ICOImageDecoder::frameBufferAtIndex): added calls to PlatformInstrumentation;
(WebCore::ICOImageDecoder::decode): removed TRACE_EVENT()
* platform/image-decoders/jpeg/JPEGImageDecoder.cpp:
(WebCore::JPEGImageDecoder::frameBufferAtIndex): added calls to PlatformInstrumentation;
(WebCore::JPEGImageDecoder::decode): removed TRACE_EVENT()
* platform/image-decoders/png/PNGImageDecoder.cpp:
(WebCore::PNGImageDecoder::frameBufferAtIndex): added calls to PlatformInstrumentation;
* platform/image-decoders/webp/WEBPImageDecoder.cpp:
(WebCore::WEBPImageDecoder::frameBufferAtIndex): added calls to PlatformInstrumentation;
(WebCore::WEBPImageDecoder::decode): removed TRACE_EVENT();
* inspector/InspectorInstrumentation.cpp: removed orphan event support;
(WebCore):
* inspector/InspectorInstrumentation.h: ditto.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@125769 268f45cc-cd09-0410-ab3c-d52691b4dbfc

20 files changed:
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/GNUmakefile.list.am
Source/WebCore/Target.pri
Source/WebCore/WebCore.gypi
Source/WebCore/WebCore.vcproj/WebCore.vcproj
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/inspector/InspectorInstrumentation.cpp
Source/WebCore/inspector/InspectorInstrumentation.h
Source/WebCore/inspector/InspectorTimelineAgent.cpp
Source/WebCore/inspector/InspectorTimelineAgent.h
Source/WebCore/platform/PlatformInstrumentation.cpp [new file with mode: 0644]
Source/WebCore/platform/PlatformInstrumentation.h [new file with mode: 0644]
Source/WebCore/platform/graphics/skia/NativeImageSkia.cpp
Source/WebCore/platform/image-decoders/bmp/BMPImageDecoder.cpp
Source/WebCore/platform/image-decoders/gif/GIFImageDecoder.cpp
Source/WebCore/platform/image-decoders/ico/ICOImageDecoder.cpp
Source/WebCore/platform/image-decoders/jpeg/JPEGImageDecoder.cpp
Source/WebCore/platform/image-decoders/png/PNGImageDecoder.cpp
Source/WebCore/platform/image-decoders/webp/WEBPImageDecoder.cpp

index 930a91a..0aed392 100644 (file)
@@ -1750,6 +1750,7 @@ SET(WebCore_SOURCES
     platform/MIMETypeRegistry.cpp
     platform/MemoryPressureHandler.cpp
     platform/PlatformEvent.cpp
+    platform/PlatformInstrumentation.cpp
     platform/RunLoop.cpp
     platform/RuntimeApplicationChecks.cpp
     platform/ScrollAnimator.cpp
index 0362e70..8d0dbab 100644 (file)
@@ -1,3 +1,66 @@
+2012-08-16  Andrey Kosyakov  <caseq@chromium.org>
+
+        Web Inspector: enable instrumentation of platform code
+        https://bugs.webkit.org/show_bug.cgi?id=94125
+
+        Reviewed by Pavel Feldman.
+
+        - add PlatformInstrumentation class that exposes instrumentation methods that may be used by code under WebCore/platform;
+        - move TRACE_EVENT_XXX() macros into PlatformInstrumentation.h to minimize instrumentation hassle in the client code;
+        - implement PlatformInstrumentationClient by InspectorTimelineAgent;
+        - only install PlatformInstrumentationClient when we have outer events for which we expect low-level details
+
+        * CMakeLists.txt:
+        * GNUmakefile.list.am:
+        * Target.pri:
+        * WebCore.gypi:
+        * WebCore.vcproj/WebCore.vcproj:
+        * inspector/InspectorTimelineAgent.cpp:
+        (WebCore::InspectorTimelineAgent::willDecodeImage): to be implemented by subsequent change;
+        (WebCore::InspectorTimelineAgent::didDecodeImage): to be implemented by subsequent change;
+        (WebCore::InspectorTimelineAgent::willResizeImage): to be implemented by subsequent change;
+        (WebCore::InspectorTimelineAgent::didResizeImage): to be implemented by subsequent change;
+        (WebCore::InspectorTimelineAgent::didCompleteCurrentRecord):
+        (WebCore::InspectorTimelineAgent::InspectorTimelineAgent):
+        (WebCore::InspectorTimelineAgent::pushCurrentRecord):
+        (WebCore::InspectorTimelineAgent::clearRecordStack):
+        * inspector/InspectorTimelineAgent.h:
+        (InspectorTimelineAgent):
+        * platform/PlatformInstrumentation.cpp: Added.
+        (WebCore):
+        (WebCore::PlatformInstrumentation::setClient):
+        * platform/PlatformInstrumentation.h: Added.
+        (WebCore):
+        (PlatformInstrumentationClient):
+        (PlatformInstrumentation):
+        (WebCore::PlatformInstrumentation::hasClient):
+        (WebCore::PlatformInstrumentation::willDecodeImage):
+        (WebCore::PlatformInstrumentation::didDecodeImage):
+        (WebCore::PlatformInstrumentation::willResizeImage):
+        (WebCore::PlatformInstrumentation::didResizeImage):
+        * platform/graphics/skia/NativeImageSkia.cpp:
+        (WebCore::NativeImageSkia::resizedBitmap): added calls to PlatformInstrumentation, removed TRACE_EVENT();
+        * platform/image-decoders/bmp/BMPImageDecoder.cpp:
+        (WebCore::BMPImageDecoder::frameBufferAtIndex): added calls to PlatformInstrumentation;
+        (WebCore::BMPImageDecoder::decode): removed TRACE_EVENT()
+        * platform/image-decoders/gif/GIFImageDecoder.cpp:
+        (WebCore::GIFImageDecoder::frameBufferAtIndex): added calls to PlatformInstrumentation;
+        (WebCore::GIFImageDecoder::decode): removed TRACE_EVENT()
+        * platform/image-decoders/ico/ICOImageDecoder.cpp:
+        (WebCore::ICOImageDecoder::frameBufferAtIndex): added calls to PlatformInstrumentation;
+        (WebCore::ICOImageDecoder::decode): removed TRACE_EVENT()
+        * platform/image-decoders/jpeg/JPEGImageDecoder.cpp:
+        (WebCore::JPEGImageDecoder::frameBufferAtIndex): added calls to PlatformInstrumentation;
+        (WebCore::JPEGImageDecoder::decode): removed TRACE_EVENT()
+        * platform/image-decoders/png/PNGImageDecoder.cpp:
+        (WebCore::PNGImageDecoder::frameBufferAtIndex): added calls to PlatformInstrumentation;
+        * platform/image-decoders/webp/WEBPImageDecoder.cpp:
+        (WebCore::WEBPImageDecoder::frameBufferAtIndex): added calls to PlatformInstrumentation;
+        (WebCore::WEBPImageDecoder::decode): removed TRACE_EVENT();
+        * inspector/InspectorInstrumentation.cpp: removed orphan event support;
+        (WebCore):
+        * inspector/InspectorInstrumentation.h: ditto.
+
 2012-08-16  Vsevolod Vlasov  <vsevik@chromium.org>
 
         Web Inspector: Breakpoints are not correctly restored on reload.
index e676e77..2f5a8c7 100644 (file)
@@ -4139,6 +4139,8 @@ webcore_sources += \
        Source/WebCore/platform/EventLoop.h \
        Source/WebCore/platform/EventTracer.cpp \
        Source/WebCore/platform/EventTracer.h \
+       Source/WebCore/platform/PlatformInstrumentation.cpp \
+       Source/WebCore/platform/PlatformInstrumentation.h \
        Source/WebCore/platform/FileChooser.cpp \
        Source/WebCore/platform/FileChooser.h \
        Source/WebCore/platform/FileIconLoader.cpp \
index af77119..2f28141 100644 (file)
@@ -1036,6 +1036,7 @@ SOURCES += \
     platform/network/ResourceResponseBase.cpp \
     platform/text/RegularExpression.cpp \
     platform/PlatformEvent.cpp \
+    platform/PlatformInstrumentation.cpp \
     platform/RuntimeApplicationChecks.cpp \
     platform/RunLoop.cpp \
     platform/SchemeRegistry.cpp \
index 9a5c630..4ef29c5 100644 (file)
             'platform/PlatformEvent.cpp',
             'platform/PlatformEvent.h',
             'platform/PlatformGestureEvent.h',
+            'platform/PlatformInstrumentation.cpp',
+            'platform/PlatformInstrumentation.h',
             'platform/PlatformKeyboardEvent.h',
             'platform/PlatformMenuDescription.h',
             'platform/PlatformMouseEvent.h',
index 88e776b..f07a29e 100755 (executable)
                                >
                        </File>
                        <File
+                               RelativePath="..\platform\PlatformInstrumentation.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\platform\PlatformInstrumentation.h"
+                               >
+                       </File>
+                       <File
                                RelativePath="..\platform\PlatformKeyboardEvent.h"
                                >
                        </File>
index 5616f7e..441a404 100644 (file)
                46F9D5DF0B0D60170028EE36 /* progressCursor.png in Resources */ = {isa = PBXBuildFile; fileRef = 46F9D5DC0B0D60170028EE36 /* progressCursor.png */; };
                490707E61219C04300D90E51 /* ANGLEWebKitBridge.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 490707E41219C04300D90E51 /* ANGLEWebKitBridge.cpp */; };
                490707E71219C04300D90E51 /* ANGLEWebKitBridge.h in Headers */ = {isa = PBXBuildFile; fileRef = 490707E51219C04300D90E51 /* ANGLEWebKitBridge.h */; };
+               49182B5215DCE6F000548418 /* PlatformInstrumentation.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 49182B5015DCE6F000548418 /* PlatformInstrumentation.cpp */; };
+               49182B5315DCE6F000548418 /* PlatformInstrumentation.h in Headers */ = {isa = PBXBuildFile; fileRef = 49182B5115DCE6F000548418 /* PlatformInstrumentation.h */; };
                492863991253B8FC00F792D6 /* ResourceLoadInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 492863981253B8FC00F792D6 /* ResourceLoadInfo.h */; settings = {ATTRIBUTES = (Private, ); }; };
                49291E4B134172C800E753DE /* ImageRenderingMode.h in Headers */ = {isa = PBXBuildFile; fileRef = 49291E4A134172C800E753DE /* ImageRenderingMode.h */; };
                493E5E0912D6420500020081 /* PlatformCALayerClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 493E5E0812D6420500020081 /* PlatformCALayerClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
                46F9D5DC0B0D60170028EE36 /* progressCursor.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = progressCursor.png; sourceTree = "<group>"; };
                490707E41219C04300D90E51 /* ANGLEWebKitBridge.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ANGLEWebKitBridge.cpp; sourceTree = "<group>"; };
                490707E51219C04300D90E51 /* ANGLEWebKitBridge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ANGLEWebKitBridge.h; sourceTree = "<group>"; };
+               49182B5015DCE6F000548418 /* PlatformInstrumentation.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PlatformInstrumentation.cpp; sourceTree = "<group>"; };
+               49182B5115DCE6F000548418 /* PlatformInstrumentation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlatformInstrumentation.h; sourceTree = "<group>"; };
                492863981253B8FC00F792D6 /* ResourceLoadInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ResourceLoadInfo.h; sourceTree = "<group>"; };
                49291E4A134172C800E753DE /* ImageRenderingMode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ImageRenderingMode.h; sourceTree = "<group>"; };
                493E5E0812D6420500020081 /* PlatformCALayerClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PlatformCALayerClient.h; path = ca/PlatformCALayerClient.h; sourceTree = "<group>"; };
                                BC5C76291497FE1400BC4775 /* PlatformEvent.h */,
                                A723F77A1484CA4C008C6DBE /* PlatformExportMacros.h */,
                                BC9585DF12F0989500755821 /* PlatformGestureEvent.h */,
+                               49182B5015DCE6F000548418 /* PlatformInstrumentation.cpp */,
+                               49182B5115DCE6F000548418 /* PlatformInstrumentation.h */,
                                935C476609AC4D4300A6AAB4 /* PlatformKeyboardEvent.h */,
                                932871BF0B20DEB70049035A /* PlatformMenuDescription.h */,
                                935C476709AC4D4300A6AAB4 /* PlatformMouseEvent.h */,
                                E1BE512E0CF6C512002EA959 /* XSLTUnicodeSort.h in Headers */,
                                977E2E0F12F0FC9C00C13379 /* XSSAuditor.h in Headers */,
                                FD537353137B651800008DCE /* ZeroPole.h in Headers */,
+                               49182B5315DCE6F000548418 /* PlatformInstrumentation.h in Headers */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                                E1BE512D0CF6C512002EA959 /* XSLTUnicodeSort.cpp in Sources */,
                                977E2E0E12F0FC9C00C13379 /* XSSAuditor.cpp in Sources */,
                                FD537352137B651800008DCE /* ZeroPole.cpp in Sources */,
+                               49182B5215DCE6F000548418 /* PlatformInstrumentation.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index 24ba742..7ea314c 100644 (file)
@@ -69,7 +69,6 @@
 #include "WorkerThread.h"
 #include "XMLHttpRequest.h"
 #include <wtf/StdLibExtras.h>
-#include <wtf/ThreadSpecific.h>
 #include <wtf/text/CString.h>
 
 namespace WebCore {
@@ -1154,22 +1153,6 @@ void InspectorInstrumentation::didFireAnimationFrameImpl(const InspectorInstrume
         timelineAgent->didFireAnimationFrame();
 }
 
-InspectorTimelineAgent* InspectorInstrumentation::timelineAgentForOrphanEvents()
-{
-    return *threadSpecificTimelineAgentForOrphanEvents();
-}
-
-void InspectorInstrumentation::setTimelineAgentForOrphanEvents(InspectorTimelineAgent* inspectorTimelineAgent)
-{
-    *threadSpecificTimelineAgentForOrphanEvents() = inspectorTimelineAgent;
-}
-
-WTF::ThreadSpecific<InspectorTimelineAgent*>& InspectorInstrumentation::threadSpecificTimelineAgentForOrphanEvents()
-{
-    AtomicallyInitializedStatic(WTF::ThreadSpecific<InspectorTimelineAgent*>*, instance = new WTF::ThreadSpecific<InspectorTimelineAgent*>());
-    return *instance;
-}
-
 void InspectorInstrumentation::registerInstrumentingAgents(InstrumentingAgents* instrumentingAgents)
 {
     if (!instrumentingAgentsSet)
index 1dc2dfa..e4a79ed 100644 (file)
@@ -255,8 +255,6 @@ public:
     static bool hasFrontends() { return s_frontendCounter; }
     static bool hasFrontendForScriptContext(ScriptExecutionContext*);
     static bool collectingHTMLParseErrors(Page*);
-    static InspectorTimelineAgent* timelineAgentForOrphanEvents();
-    static void setTimelineAgentForOrphanEvents(InspectorTimelineAgent*);
 #else
     static bool hasFrontends() { return false; }
     static bool hasFrontendForScriptContext(ScriptExecutionContext*) { return false; }
@@ -274,8 +272,6 @@ public:
 
 private:
 #if ENABLE(INSPECTOR)
-    static WTF::ThreadSpecific<InspectorTimelineAgent*>& threadSpecificTimelineAgentForOrphanEvents();
-
     static void didClearWindowObjectInWorldImpl(InstrumentingAgents*, Frame*, DOMWrapperWorld*);
     static bool isDebuggerPausedImpl(InstrumentingAgents*);
 
index 8cc3439..887cde2 100644 (file)
@@ -255,6 +255,22 @@ void InspectorTimelineAgent::didPaint()
     didCompleteCurrentRecord(TimelineRecordType::Paint);
 }
 
+void InspectorTimelineAgent::willDecodeImage(const String&)
+{
+}
+
+void InspectorTimelineAgent::didDecodeImage()
+{
+}
+
+void InspectorTimelineAgent::willResizeImage(bool)
+{
+}
+
+void InspectorTimelineAgent::didResizeImage()
+{
+}
+
 void InspectorTimelineAgent::willComposite()
 {
     pushCurrentRecord(InspectorObject::create(), TimelineRecordType::CompositeLayers, false, 0);
@@ -486,9 +502,9 @@ void InspectorTimelineAgent::didCompleteCurrentRecord(const String& type)
     // An empty stack could merely mean that the timeline agent was turned on in the middle of
     // an event.  Don't treat as an error.
     if (!m_recordStack.isEmpty()) {
-        if (m_orphanEventsEnabledStackMark == m_recordStack.size()) {
-            m_orphanEventsEnabledStackMark = 0;
-            InspectorInstrumentation::setTimelineAgentForOrphanEvents(0);
+        if (m_platformInstrumentationClientInstalledAtStackDepth == m_recordStack.size()) {
+            m_platformInstrumentationClientInstalledAtStackDepth = 0;
+            PlatformInstrumentation::setClient(0);
         }
 
         pushGCEventRecords();
@@ -509,7 +525,7 @@ InspectorTimelineAgent::InspectorTimelineAgent(InstrumentingAgents* instrumentin
     , m_timestampOffset(0)
     , m_id(1)
     , m_maxCallStackDepth(5)
-    , m_orphanEventsEnabledStackMark(0)
+    , m_platformInstrumentationClientInstalledAtStackDepth(0)
     , m_inspectorType(type)
     , m_client(client)
 {
@@ -527,7 +543,7 @@ void InspectorTimelineAgent::appendRecord(PassRefPtr<InspectorObject> data, cons
     addRecordToTimeline(record.release(), type, frameId);
 }
 
-void InspectorTimelineAgent::pushCurrentRecord(PassRefPtr<InspectorObject> data, const String& type, bool captureCallStack, Frame* frame, bool hasOrphanDetails)
+void InspectorTimelineAgent::pushCurrentRecord(PassRefPtr<InspectorObject> data, const String& type, bool captureCallStack, Frame* frame, bool hasLowLevelDetails)
 {
     pushGCEventRecords();
     commitFrameRecord();
@@ -536,9 +552,9 @@ void InspectorTimelineAgent::pushCurrentRecord(PassRefPtr<InspectorObject> data,
     if (frame && m_pageAgent)
         frameId = m_pageAgent->frameId(frame);
     m_recordStack.append(TimelineRecordEntry(record.release(), data, InspectorArray::create(), type, frameId));
-    if (hasOrphanDetails && !m_orphanEventsEnabledStackMark && !InspectorInstrumentation::timelineAgentForOrphanEvents()) {
-        m_orphanEventsEnabledStackMark = m_recordStack.size();
-        InspectorInstrumentation::setTimelineAgentForOrphanEvents(this);
+    if (hasLowLevelDetails && !m_platformInstrumentationClientInstalledAtStackDepth && !PlatformInstrumentation::hasClient()) {
+        m_platformInstrumentationClientInstalledAtStackDepth = m_recordStack.size();
+        PlatformInstrumentation::setClient(this);
     }
 }
 
@@ -553,6 +569,10 @@ void InspectorTimelineAgent::commitFrameRecord()
 
 void InspectorTimelineAgent::clearRecordStack()
 {
+    if (m_platformInstrumentationClientInstalledAtStackDepth) {
+        m_platformInstrumentationClientInstalledAtStackDepth = 0;
+        PlatformInstrumentation::setClient(0);
+    }
     m_pendingFrameRecord.clear();
     m_recordStack.clear();
     m_id++;
index 0b4b90e..61e8ddc 100644 (file)
@@ -1,5 +1,5 @@
 /*
-* Copyright (C) 2009 Google Inc. All rights reserved.
+* Copyright (C) 2012 Google Inc. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
@@ -37,6 +37,7 @@
 #include "InspectorFrontend.h"
 #include "InspectorValues.h"
 #include "LayoutTypes.h"
+#include "PlatformInstrumentation.h"
 #include "ScriptGCEvent.h"
 #include "ScriptGCEventListener.h"
 #include <wtf/PassOwnPtr.h>
@@ -56,7 +57,11 @@ class ResourceResponse;
 
 typedef String ErrorString;
 
-class InspectorTimelineAgent : public InspectorBaseAgent<InspectorTimelineAgent>, ScriptGCEventListener, public InspectorBackendDispatcher::TimelineCommandHandler {
+class InspectorTimelineAgent
+    : public InspectorBaseAgent<InspectorTimelineAgent>,
+      public ScriptGCEventListener,
+      public InspectorBackendDispatcher::TimelineCommandHandler,
+      public PlatformInstrumentationClient {
     WTF_MAKE_NONCOPYABLE(InspectorTimelineAgent);
 public:
     enum InspectorType { PageInspector, WorkerInspector };
@@ -146,6 +151,12 @@ public:
     void willProcessTask();
     void didProcessTask();
 
+    // PlatformInstrumentationClient methods.
+    virtual void willDecodeImage(const String& imageType) OVERRIDE;
+    virtual void didDecodeImage() OVERRIDE;
+    virtual void willResizeImage(bool shouldCache) OVERRIDE;
+    virtual void didResizeImage() OVERRIDE;
+
 private:
     struct TimelineRecordEntry {
         TimelineRecordEntry(PassRefPtr<InspectorObject> record, PassRefPtr<InspectorObject> data, PassRefPtr<InspectorArray> children, const String& type, const String& frameId)
@@ -161,7 +172,7 @@ private:
         
     InspectorTimelineAgent(InstrumentingAgents*, InspectorPageAgent*, InspectorState*, InspectorType, InspectorClient*);
 
-    void pushCurrentRecord(PassRefPtr<InspectorObject>, const String& type, bool captureCallStack, Frame*, bool hasOrphanDetails = false);
+    void pushCurrentRecord(PassRefPtr<InspectorObject>, const String& type, bool captureCallStack, Frame*, bool hasLowLevelDetails = false);
     void setHeapSizeStatistics(InspectorObject* record);
 
     void didCompleteCurrentRecord(const String& type);
@@ -196,7 +207,7 @@ private:
     typedef Vector<GCEvent> GCEvents;
     GCEvents m_gcEvents;
     int m_maxCallStackDepth;
-    unsigned m_orphanEventsEnabledStackMark;
+    unsigned m_platformInstrumentationClientInstalledAtStackDepth;
     RefPtr<InspectorObject> m_pendingFrameRecord;
     InspectorType m_inspectorType;
     InspectorClient* m_client;
diff --git a/Source/WebCore/platform/PlatformInstrumentation.cpp b/Source/WebCore/platform/PlatformInstrumentation.cpp
new file mode 100644 (file)
index 0000000..6704eda
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#include "PlatformInstrumentation.h"
+
+namespace WebCore {
+
+PlatformInstrumentationClient* PlatformInstrumentation::m_client;
+
+PlatformInstrumentationClient::~PlatformInstrumentationClient()
+{
+}
+
+void PlatformInstrumentation::setClient(PlatformInstrumentationClient* client)
+{
+    m_client = client;
+}
+
+}
diff --git a/Source/WebCore/platform/PlatformInstrumentation.h b/Source/WebCore/platform/PlatformInstrumentation.h
new file mode 100644 (file)
index 0000000..1f95577
--- /dev/null
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef PlatformInstrumentation_h
+#define PlatformInstrumentation_h
+
+#include <wtf/text/WTFString.h>
+
+#if PLATFORM(CHROMIUM)
+#include "TraceEvent.h"
+#endif
+
+namespace WebCore {
+
+class PlatformInstrumentationClient {
+public:
+    virtual ~PlatformInstrumentationClient();
+
+    virtual void willDecodeImage(const String& imageType) = 0;
+    virtual void didDecodeImage() = 0;
+    virtual void willResizeImage(bool shouldCache) = 0;
+    virtual void didResizeImage() = 0;
+};
+
+class PlatformInstrumentation {
+public:
+    static void setClient(PlatformInstrumentationClient*);
+    static bool hasClient() { return m_client; }
+
+    static void willDecodeImage(const String& imageType);
+    static void didDecodeImage();
+    static void willResizeImage(bool shouldCache);
+    static void didResizeImage();
+
+private:
+    static PlatformInstrumentationClient* m_client;
+};
+
+#define FAST_RETURN_IF_NO_CLIENT() if (!m_client) return;
+
+inline void PlatformInstrumentation::willDecodeImage(const String& imageType)
+{
+#if PLATFORM(CHROMIUM)
+    TRACE_EVENT_BEGIN1("webkit", "Image Decode", "imageType", TRACE_STR_COPY(imageType.ascii().data()));
+#endif
+    FAST_RETURN_IF_NO_CLIENT();
+    m_client->willDecodeImage(imageType);
+}
+
+inline void PlatformInstrumentation::didDecodeImage()
+{
+#if PLATFORM(CHROMIUM)
+    TRACE_EVENT_END0("webkit", "Image Decode");
+#endif
+    FAST_RETURN_IF_NO_CLIENT();
+    m_client->didDecodeImage();
+}
+
+inline void PlatformInstrumentation::willResizeImage(bool shouldCache)
+{
+#if PLATFORM(CHROMIUM)
+    TRACE_EVENT_BEGIN1("webkit", "Image Resize", "cached", shouldCache);
+#endif
+    FAST_RETURN_IF_NO_CLIENT();
+    m_client->willResizeImage(shouldCache);
+}
+
+inline void PlatformInstrumentation::didResizeImage()
+{
+#if PLATFORM(CHROMIUM)
+    TRACE_EVENT_END0("webkit", "Image Resize");
+#endif
+    FAST_RETURN_IF_NO_CLIENT();
+    m_client->didResizeImage();
+}
+
+} // namespace WebCore
+
+#endif // PlatformInstrumentation_h
index 7e34c07..2c4baed 100644 (file)
 
 #include "NativeImageSkia.h"
 #include "GraphicsContext3D.h"
+#include "PlatformInstrumentation.h"
 #include "SkiaUtils.h"
 
-#if PLATFORM(CHROMIUM)
-#include "TraceEvent.h"
-#endif
-
 namespace WebCore {
 
 NativeImageSkia::NativeImageSkia()
@@ -74,9 +71,6 @@ SkBitmap NativeImageSkia::resizedBitmap(const SkIRect& srcSubset,
                                         int destHeight,
                                         const SkIRect& destVisibleSubset) const
 {
-#if PLATFORM(CHROMIUM)
-    TRACE_EVENT0("skia", "NativeImageSkia::resizedBitmap");
-#endif
     if (!hasResizedBitmap(srcSubset, destWidth, destHeight)) {
         bool shouldCache = isDataComplete()
             && shouldCacheResampling(srcSubset, destWidth, destHeight, destVisibleSubset);
@@ -84,18 +78,16 @@ SkBitmap NativeImageSkia::resizedBitmap(const SkIRect& srcSubset,
         SkBitmap subset;
         m_image.extractSubset(&subset, srcSubset);
         if (!shouldCache) {
-#if PLATFORM(CHROMIUM)
-            TRACE_EVENT0("skia", "nonCachedResize");
-#endif
             // Just resize the visible subset and return it.
+            PlatformInstrumentation::willResizeImage(shouldCache);
             SkBitmap resizedImage = skia::ImageOperations::Resize(subset, skia::ImageOperations::RESIZE_LANCZOS3, destWidth, destHeight, destVisibleSubset);
+            PlatformInstrumentation::didResizeImage();
             resizedImage.setImmutable();
             return resizedImage;
         } else {
-#if PLATFORM(CHROMIUM)
-            TRACE_EVENT0("skia", "cachedResize");
-#endif
+            PlatformInstrumentation::willResizeImage(shouldCache);
             m_resizedImage = skia::ImageOperations::Resize(subset, skia::ImageOperations::RESIZE_LANCZOS3, destWidth, destHeight);
+            PlatformInstrumentation::didResizeImage();
         }
         m_resizedImage.setImmutable();
     }
index 43ef518..72bc7d0 100644 (file)
 #include "BMPImageDecoder.h"
 
 #include "BMPImageReader.h"
+#include "PlatformInstrumentation.h"
 #include <wtf/PassOwnPtr.h>
 
-#if PLATFORM(CHROMIUM)
-#include "TraceEvent.h"
-#endif
-
 namespace WebCore {
 
 // Number of bits in .BMP used to store the file header (doesn't match
@@ -81,8 +78,11 @@ ImageFrame* BMPImageDecoder::frameBufferAtIndex(size_t index)
     }
 
     ImageFrame* buffer = &m_frameBufferCache.first();
-    if (buffer->status() != ImageFrame::FrameComplete)
+    if (buffer->status() != ImageFrame::FrameComplete) {
+        PlatformInstrumentation::willDecodeImage("BMP");
         decode(false);
+        PlatformInstrumentation::didDecodeImage();
+    }
     return buffer;
 }
 
@@ -94,9 +94,6 @@ bool BMPImageDecoder::setFailed()
 
 void BMPImageDecoder::decode(bool onlySize)
 {
-#if PLATFORM(CHROMIUM)
-    TRACE_EVENT0("webkit", "BMPImageDecoder::decode");
-#endif
     if (failed())
         return;
 
index 724ea0d..40e131e 100644 (file)
 #include "GIFImageDecoder.h"
 
 #include "GIFImageReader.h"
+#include "PlatformInstrumentation.h"
 #include <wtf/PassOwnPtr.h>
 
-#if PLATFORM(CHROMIUM)
-#include "TraceEvent.h"
-#endif
-
 namespace WebCore {
 
 GIFImageDecoder::GIFImageDecoder(ImageSource::AlphaOption alphaOption,
@@ -130,8 +127,11 @@ ImageFrame* GIFImageDecoder::frameBufferAtIndex(size_t index)
         return 0;
 
     ImageFrame& frame = m_frameBufferCache[index];
-    if (frame.status() != ImageFrame::FrameComplete)
+    if (frame.status() != ImageFrame::FrameComplete) {
+        PlatformInstrumentation::willDecodeImage("GIF");
         decode(index + 1, GIFFullQuery);
+        PlatformInstrumentation::didDecodeImage();
+    }
     return &frame;
 }
 
@@ -314,9 +314,6 @@ void GIFImageDecoder::gifComplete()
 
 void GIFImageDecoder::decode(unsigned haltAtFrame, GIFQuery query)
 {
-#if PLATFORM(CHROMIUM)
-    TRACE_EVENT0("webkit", "GIFImageDecoder::decode");
-#endif
     if (failed())
         return;
 
index 36dde1c..2db3ecf 100644 (file)
 
 #include "BMPImageReader.h"
 #include "PNGImageDecoder.h"
+#include "PlatformInstrumentation.h"
 #include <wtf/PassOwnPtr.h>
 
-#if PLATFORM(CHROMIUM)
-#include "TraceEvent.h"
-#endif
-
 namespace WebCore {
 
 // Number of bits in .ICO/.CUR used to store the directory and its entries,
@@ -121,8 +118,11 @@ ImageFrame* ICOImageDecoder::frameBufferAtIndex(size_t index)
         return 0;
 
     ImageFrame* buffer = &m_frameBufferCache[index];
-    if (buffer->status() != ImageFrame::FrameComplete)
+    if (buffer->status() != ImageFrame::FrameComplete) {
+        PlatformInstrumentation::willDecodeImage("ICO");
         decode(index, false);
+        PlatformInstrumentation::didDecodeImage();
+    }
     return buffer;
 }
 
@@ -157,9 +157,6 @@ void ICOImageDecoder::setDataForPNGDecoderAtIndex(size_t index)
 
 void ICOImageDecoder::decode(size_t index, bool onlySize)
 {
-#if PLATFORM(CHROMIUM)
-    TRACE_EVENT0("webkit", "ICOImageDecoder::decode");
-#endif
     if (failed())
         return;
 
index bef4203..275ffc0 100644 (file)
 
 #include "config.h"
 #include "JPEGImageDecoder.h"
+#include "PlatformInstrumentation.h"
 #include <stdio.h>  // Needed by jpeglib.h for FILE.
 #include <wtf/PassOwnPtr.h>
 
-#if PLATFORM(CHROMIUM)
-#include "TraceEvent.h"
-#endif
-
 #if OS(WINCE)
 // Remove warning: 'FAR' macro redefinition
 #undef FAR
@@ -540,8 +537,11 @@ ImageFrame* JPEGImageDecoder::frameBufferAtIndex(size_t index)
     }
 
     ImageFrame& frame = m_frameBufferCache[0];
-    if (frame.status() != ImageFrame::FrameComplete)
+    if (frame.status() != ImageFrame::FrameComplete) {
+        PlatformInstrumentation::willDecodeImage("JPEG");
         decode(false);
+        PlatformInstrumentation::didDecodeImage();
+    }
     return &frame;
 }
 
@@ -647,9 +647,6 @@ void JPEGImageDecoder::jpegComplete()
 
 void JPEGImageDecoder::decode(bool onlySize)
 {
-#if PLATFORM(CHROMIUM)
-    TRACE_EVENT0("webkit", "JPEGImageDecoder::decode");
-#endif
     if (failed())
         return;
 
index 158debb..851b6f9 100644 (file)
 #include "config.h"
 #include "PNGImageDecoder.h"
 
+#include "PlatformInstrumentation.h"
 #include "png.h"
 #include <wtf/OwnArrayPtr.h>
 #include <wtf/PassOwnPtr.h>
 
-#if PLATFORM(CHROMIUM)
-#include "TraceEvent.h"
-#endif
-
 #if USE(QCMSLIB)
 #include "qcms.h"
 #endif
@@ -261,8 +258,11 @@ ImageFrame* PNGImageDecoder::frameBufferAtIndex(size_t index)
     }
 
     ImageFrame& frame = m_frameBufferCache[0];
-    if (frame.status() != ImageFrame::FrameComplete)
+    if (frame.status() != ImageFrame::FrameComplete) {
+        PlatformInstrumentation::willDecodeImage("PNG");
         decode(false);
+        PlatformInstrumentation::didDecodeImage();
+    }
     return &frame;
 }
 
@@ -530,9 +530,6 @@ void PNGImageDecoder::pngComplete()
 
 void PNGImageDecoder::decode(bool onlySize)
 {
-#if PLATFORM(CHROMIUM)
-    TRACE_EVENT0("webkit", "PNGImageDecoder::decode");
-#endif
     if (failed())
         return;
 
index 612890f..af40106 100644 (file)
 
 #if USE(WEBP)
 
+#include "PlatformInstrumentation.h"
 #include "webp/decode.h"
 
-#if PLATFORM(CHROMIUM)
-#include "TraceEvent.h"
-#endif
-
 #if CPU(BIG_ENDIAN) || CPU(MIDDLE_ENDIAN)
 inline WEBP_CSP_MODE outputMode() { return MODE_RGBA; }
 #elif USE(SKIA) && SK_B32_SHIFT
@@ -80,16 +77,16 @@ ImageFrame* WEBPImageDecoder::frameBufferAtIndex(size_t index)
     }
 
     ImageFrame& frame = m_frameBufferCache[0];
-    if (frame.status() != ImageFrame::FrameComplete)
+    if (frame.status() != ImageFrame::FrameComplete) {
+        PlatformInstrumentation::willDecodeImage("WEBP");
         decode(false);
+        PlatformInstrumentation::didDecodeImage();
+    }
     return &frame;
 }
 
 bool WEBPImageDecoder::decode(bool onlySize)
 {
-#if PLATFORM(CHROMIUM)
-    TRACE_EVENT0("webkit", "WEBPImageDecoder::decode");
-#endif
     if (failed())
         return false;