Added css jit profiler, disabled by default.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 8 Jul 2014 21:47:51 +0000 (21:47 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 8 Jul 2014 21:47:51 +0000 (21:47 +0000)
https://bugs.webkit.org/show_bug.cgi?id=134695

Patch by Alex Christensen <achristensen@webkit.org> on 2014-07-08
Reviewed by Benjamin Poulain.

* css/ElementRuleCollector.cpp:
(WebCore::ElementRuleCollector::ruleMatches):
Tell the RuleData when its compiled selector is used.
* css/RuleSet.cpp:
(WebCore::RuleData::RuleData):
Initialize the compiled selector use count to 0.
* css/RuleSet.h:
(WebCore::RuleData::~RuleData):
(WebCore::RuleData::compiledSelectorUsed):
Count and log the number of times a compiled selector is used.
* cssjit/SelectorCompiler.h:
Added option for CSS_SELECTOR_JIT_PROFILING set to 0 by default.
* dom/SelectorQuery.cpp:
(WebCore::SelectorDataList::executeCompiledSimpleSelectorChecker):
(WebCore::SelectorDataList::execute):
Tell the SelectorData when its compiled selector is used.
* dom/SelectorQuery.h:
(WebCore::SelectorDataList::SelectorData::SelectorData):
(WebCore::SelectorDataList::SelectorData::~SelectorData):
(WebCore::SelectorDataList::SelectorData::compiledSelectorUsed):
Count and log the number of times a compiled selector is used.

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

Source/WebCore/ChangeLog
Source/WebCore/css/ElementRuleCollector.cpp
Source/WebCore/css/RuleSet.cpp
Source/WebCore/css/RuleSet.h
Source/WebCore/cssjit/SelectorCompiler.h
Source/WebCore/dom/SelectorQuery.cpp
Source/WebCore/dom/SelectorQuery.h

index 2da5122..d9f7846 100644 (file)
@@ -1,3 +1,32 @@
+2014-07-08  Alex Christensen  <achristensen@webkit.org>
+
+        Added css jit profiler, disabled by default.
+        https://bugs.webkit.org/show_bug.cgi?id=134695
+
+        Reviewed by Benjamin Poulain.
+
+        * css/ElementRuleCollector.cpp:
+        (WebCore::ElementRuleCollector::ruleMatches):
+        Tell the RuleData when its compiled selector is used.
+        * css/RuleSet.cpp:
+        (WebCore::RuleData::RuleData):
+        Initialize the compiled selector use count to 0.
+        * css/RuleSet.h:
+        (WebCore::RuleData::~RuleData):
+        (WebCore::RuleData::compiledSelectorUsed):
+        Count and log the number of times a compiled selector is used.
+        * cssjit/SelectorCompiler.h:
+        Added option for CSS_SELECTOR_JIT_PROFILING set to 0 by default.
+        * dom/SelectorQuery.cpp:
+        (WebCore::SelectorDataList::executeCompiledSimpleSelectorChecker):
+        (WebCore::SelectorDataList::execute):
+        Tell the SelectorData when its compiled selector is used.
+        * dom/SelectorQuery.h:
+        (WebCore::SelectorDataList::SelectorData::SelectorData):
+        (WebCore::SelectorDataList::SelectorData::~SelectorData):
+        (WebCore::SelectorDataList::SelectorData::compiledSelectorUsed):
+        Count and log the number of times a compiled selector is used.
+
 2014-07-08  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         Unreviewed. Fix GObject DOM bindings API breaks test after r170700.
index 5db522f..e3aa615 100644 (file)
@@ -303,6 +303,9 @@ inline bool ElementRuleCollector::ruleMatches(const RuleData& ruleData)
 
         if (ruleData.compilationStatus() == SelectorCompilationStatus::SimpleSelectorChecker) {
             SelectorCompiler::SimpleSelectorChecker selectorChecker = SelectorCompiler::simpleSelectorCheckerFunction(compiledSelectorChecker, ruleData.compilationStatus());
+#if CSS_SELECTOR_JIT_PROFILING
+            ruleData.compiledSelectorUsed();
+#endif
             return selectorChecker(&m_element);
         }
         ASSERT(ruleData.compilationStatus() == SelectorCompilationStatus::SelectorCheckerWithCheckingContext);
@@ -311,6 +314,9 @@ inline bool ElementRuleCollector::ruleMatches(const RuleData& ruleData)
         SelectorCompiler::CheckingContext context;
         context.elementStyle = m_style;
         context.resolvingMode = m_mode;
+#if CSS_SELECTOR_JIT_PROFILING
+        ruleData.compiledSelectorUsed();
+#endif
         return selectorChecker(&m_element, &context);
     }
 #endif // ENABLE(CSS_SELECTOR_JIT)
index 777e72e..6620556 100644 (file)
@@ -140,6 +140,9 @@ RuleData::RuleData(StyleRule* rule, unsigned selectorIndex, unsigned position, A
     , m_linkMatchType(SelectorChecker::determineLinkMatchType(selector()))
     , m_hasDocumentSecurityOrigin(addRuleFlags & RuleHasDocumentSecurityOrigin)
     , m_propertyWhitelistType(determinePropertyWhitelistType(addRuleFlags, selector()))
+#if CSS_SELECTOR_JIT_PROFILING
+    , m_compiledSelectorUseCount(0)
+#endif
 {
     ASSERT(m_position == position);
     ASSERT(m_selectorIndex == selectorIndex);
index 72017bb..5c81b63 100644 (file)
@@ -29,6 +29,7 @@
 #include <wtf/HashMap.h>
 #include <wtf/HashSet.h>
 #include <wtf/text/AtomicString.h>
+#include <wtf/text/CString.h>
 
 namespace WebCore {
 
@@ -85,6 +86,14 @@ public:
         m_compilationStatus = status;
         m_compiledSelectorCodeRef = codeRef;
     }
+#if CSS_SELECTOR_JIT_PROFILING
+    ~RuleData()
+    {
+        if (m_compiledSelectorCodeRef.code().executableAddress())
+            dataLogF("RuleData compiled selector %d \"%s\"\n", m_compiledSelectorUseCount, selector()->selectorText().utf8().data());
+    }
+    void compiledSelectorUsed() const { m_compiledSelectorUseCount++; }
+#endif
 #endif // ENABLE(CSS_SELECTOR_JIT)
 
 private:
@@ -106,6 +115,9 @@ private:
 #if ENABLE(CSS_SELECTOR_JIT)
     mutable SelectorCompilationStatus m_compilationStatus;
     mutable JSC::MacroAssemblerCodeRef m_compiledSelectorCodeRef;
+#if CSS_SELECTOR_JIT_PROFILING
+    mutable unsigned m_compiledSelectorUseCount;
+#endif
 #endif // ENABLE(CSS_SELECTOR_JIT)
 };
     
@@ -114,6 +126,9 @@ struct SameSizeAsRuleData {
     unsigned compilationStatus;
     void* compiledSelectorPointer;
     void* codeRefPtr;
+#if CSS_SELECTOR_JIT_PROFILING
+    unsigned compiledSelectorUseCount;
+#endif
 #endif // ENABLE(CSS_SELECTOR_JIT)
 
     void* a;
index 8be9396..1a6223d 100644 (file)
@@ -31,6 +31,8 @@
 #include "SelectorChecker.h"
 #include <JavaScriptCore/MacroAssemblerCodeRef.h>
 
+#define CSS_SELECTOR_JIT_PROFILING 1
+
 namespace JSC {
 class MacroAssemblerCodeRef;
 class VM;
index 5eaad51..726c46e 100644 (file)
@@ -361,9 +361,14 @@ ALWAYS_INLINE void SelectorDataList::executeSingleMultiSelectorData(const Contai
 
 #if ENABLE(CSS_SELECTOR_JIT)
 template <typename SelectorQueryTrait>
-ALWAYS_INLINE void SelectorDataList::executeCompiledSimpleSelectorChecker(const ContainerNode& rootNode, SelectorCompiler::SimpleSelectorChecker selectorChecker, typename SelectorQueryTrait::OutputType& output) const
+ALWAYS_INLINE void SelectorDataList::executeCompiledSimpleSelectorChecker(const ContainerNode& rootNode, SelectorCompiler::SimpleSelectorChecker selectorChecker, typename SelectorQueryTrait::OutputType& output, const SelectorData& selectorData) const
 {
     for (auto& element : elementDescendants(const_cast<ContainerNode&>(rootNode))) {
+#if CSS_SELECTOR_JIT_PROFILING
+        selectorData.compiledSelectorUsed();
+#else
+        UNUSED_PARAM(selectorData);
+#endif
         if (selectorChecker(&element)) {
             SelectorQueryTrait::appendOutputForElement(output, &element);
             if (SelectorQueryTrait::shouldOnlyMatchFirstElement)
@@ -435,7 +440,7 @@ ALWAYS_INLINE void SelectorDataList::execute(ContainerNode& rootNode, typename S
         const SelectorData& selectorData = m_selectors.first();
         void* compiledSelectorChecker = selectorData.compiledSelectorCodeRef.code().executableAddress();
         SelectorCompiler::SimpleSelectorChecker selectorChecker = SelectorCompiler::simpleSelectorCheckerFunction(compiledSelectorChecker, selectorData.compilationStatus);
-        executeCompiledSimpleSelectorChecker<SelectorQueryTrait>(*searchRootNode, selectorChecker, output);
+        executeCompiledSimpleSelectorChecker<SelectorQueryTrait>(*searchRootNode, selectorChecker, output, selectorData);
         break;
         }
 #else
index 8fc2dd7..ca70b78 100644 (file)
@@ -32,6 +32,7 @@
 #include <wtf/HashMap.h>
 #include <wtf/Vector.h>
 #include <wtf/text/AtomicStringHash.h>
+#include <wtf/text/CString.h>
 
 namespace WebCore {
 
@@ -55,6 +56,9 @@ private:
     struct SelectorData {
         SelectorData(const CSSSelector* selector, bool isFastCheckable)
             : selector(selector)
+#if CSS_SELECTOR_JIT_PROFILING
+            , m_compiledSelectorUseCount(0)
+#endif
             , isFastCheckable(isFastCheckable)
         {
         }
@@ -63,6 +67,15 @@ private:
 #if ENABLE(CSS_SELECTOR_JIT)
         mutable JSC::MacroAssemblerCodeRef compiledSelectorCodeRef;
         mutable SelectorCompilationStatus compilationStatus;
+#if CSS_SELECTOR_JIT_PROFILING
+        ~SelectorData()
+        {
+            if (compiledSelectorCodeRef.code().executableAddress())
+                dataLogF("SelectorData compiled selector %d \"%s\"\n", m_compiledSelectorUseCount, selector->selectorText().utf8().data());
+        }
+        mutable unsigned m_compiledSelectorUseCount;
+        void compiledSelectorUsed() const { m_compiledSelectorUseCount++; }
+#endif
 #endif // ENABLE(CSS_SELECTOR_JIT)
         bool isFastCheckable;
     };
@@ -76,7 +89,7 @@ private:
     template <typename SelectorQueryTrait> void executeSingleSelectorData(const ContainerNode& rootNode, const SelectorData&, typename SelectorQueryTrait::OutputType&) const;
     template <typename SelectorQueryTrait> void executeSingleMultiSelectorData(const ContainerNode& rootNode, typename SelectorQueryTrait::OutputType&) const;
 #if ENABLE(CSS_SELECTOR_JIT)
-    template <typename SelectorQueryTrait> void executeCompiledSimpleSelectorChecker(const ContainerNode& rootNode, SelectorCompiler::SimpleSelectorChecker, typename SelectorQueryTrait::OutputType&) const;
+    template <typename SelectorQueryTrait> void executeCompiledSimpleSelectorChecker(const ContainerNode& rootNode, SelectorCompiler::SimpleSelectorChecker, typename SelectorQueryTrait::OutputType&, const SelectorData&) const;
 #endif // ENABLE(CSS_SELECTOR_JIT)
 
     Vector<SelectorData> m_selectors;