Print out the render tree from command line.
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 22 Oct 2015 06:10:53 +0000 (06:10 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 22 Oct 2015 06:10:53 +0000 (06:10 +0000)
https://bugs.webkit.org/show_bug.cgi?id=150416

Use system-wide notification server (https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man3/notify_register_dispatch.3.html)
to print out the render tree for the live documents.

Usage: notifyutil -p com.apple.WebKit.showRenderTree

Reviewed by Simon Fraser.

No change in functionality.

* platform/Logging.cpp:
(WebCore::registerNotifyCallback):
* platform/Logging.h:
* rendering/RenderObject.cpp:
(WebCore::RenderObject::RenderObject):
(WebCore::printRenderTreeForLiveDocuments):

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

Source/WebCore/ChangeLog
Source/WebCore/platform/Logging.cpp
Source/WebCore/platform/Logging.h
Source/WebCore/rendering/RenderObject.cpp

index 7c26d53..948f0d8 100644 (file)
@@ -1,3 +1,24 @@
+2015-10-21  Zalan Bujtas  <zalan@apple.com>
+
+        Print out the render tree from command line.
+        https://bugs.webkit.org/show_bug.cgi?id=150416
+
+        Use system-wide notification server (https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man3/notify_register_dispatch.3.html)
+        to print out the render tree for the live documents.
+
+        Usage: notifyutil -p com.apple.WebKit.showRenderTree
+
+        Reviewed by Simon Fraser.
+
+        No change in functionality.
+
+        * platform/Logging.cpp:
+        (WebCore::registerNotifyCallback):
+        * platform/Logging.h:
+        * rendering/RenderObject.cpp:
+        (WebCore::RenderObject::RenderObject):
+        (WebCore::printRenderTreeForLiveDocuments):
+
 2015-10-21  Alex Christensen  <achristensen@webkit.org>
 
         Fix CMake clean build after r191423.
index 849e5c6..5565974 100644 (file)
 #include <wtf/text/CString.h>
 #include <wtf/text/WTFString.h>
 
+#if PLATFORM(COCOA)
+#include <notify.h>
+#endif
+
 #if !LOG_DISABLED
 
 namespace WebCore {
@@ -63,6 +67,18 @@ void initializeLoggingChannelsIfNecessary()
     WTFInitializeLogChannelStatesFromString(logChannels, logChannelCount, logLevelString().utf8().data());
 }
 
+#ifndef NDEBUG
+void registerNotifyCallback(const String& notifyID, std::function<void()> callback)
+{
+#if PLATFORM(COCOA)
+    int token;
+    notify_register_dispatch(notifyID.utf8().data(), &token, dispatch_get_main_queue(), ^(int) {
+        callback();
+    });
+#endif
+}
+#endif
+
 }
 
 #endif // !LOG_DISABLED
index d59b894..e92c1e6 100644 (file)
@@ -26,6 +26,7 @@
 #ifndef Logging_h
 #define Logging_h
 
+#include <functional>
 #include <wtf/Assertions.h>
 #include <wtf/Forward.h>
 
@@ -89,6 +90,9 @@ WEBCORE_LOG_CHANNELS(DECLARE_LOG_CHANNEL)
     String logLevelString();
     bool isLogChannelEnabled(const String& name);
     WEBCORE_EXPORT void initializeLoggingChannelsIfNecessary();
+#ifndef NDEBUG
+    void registerNotifyCallback(const String& notifyID, std::function<void()> callback);
+#endif
 }
 
 #endif // !LOG_DISABLED
index 0938448..8b74a66 100644 (file)
@@ -43,6 +43,7 @@
 #include "HTMLTableCellElement.h"
 #include "HTMLTableElement.h"
 #include "HitTestResult.h"
+#include "Logging.h"
 #include "LogicalSelectionOffsetCaches.h"
 #include "Page.h"
 #include "PseudoElement.h"
@@ -81,6 +82,8 @@ namespace WebCore {
 using namespace HTMLNames;
 
 #ifndef NDEBUG
+void printRenderTreeForLiveDocuments();
+
 RenderObject::SetLayoutNeededForbiddenScope::SetLayoutNeededForbiddenScope(RenderObject* renderObject, bool isForbidden)
     : m_renderObject(renderObject)
     , m_preexistingForbidden(m_renderObject->isSetNeedsLayoutForbidden())
@@ -123,6 +126,10 @@ RenderObject::RenderObject(Node& node)
         renderView->didCreateRenderer();
 #ifndef NDEBUG
     renderObjectCounter.increment();
+    static std::once_flag onceFlag;
+    std::call_once(onceFlag, [] {
+        registerNotifyCallback("com.apple.WebKit.showRenderTree", printRenderTreeForLiveDocuments);
+    });
 #endif
 }
 
@@ -2215,6 +2222,19 @@ void RenderObject::removeRareData()
     setHasRareData(false);
 }
 
+#ifndef NDEBUG
+void printRenderTreeForLiveDocuments()
+{
+    for (const auto* document : Document::allDocuments()) {
+        if (!document->renderView() || document->inPageCache())
+            continue;
+        if (document->frame() && document->frame()->isMainFrame())
+            fprintf(stderr, "----------------------main frame--------------------------\n");
+        fprintf(stderr, "%s", document->url().string().utf8().data());
+        showRenderTree(document->renderView());
+    }
+}
+#endif
 } // namespace WebCore
 
 #if ENABLE(TREE_DEBUGGING)