Hi alexfh,

Speed up clang-tidy when profiling in on.
It makes profiling runs twice as fast by reusing the time samples between the
different actions.
It also joins together the sampling of different matchers of the same check.

http://reviews.llvm.org/D5972

Files:
  lib/ASTMatchers/ASTMatchFinder.cpp
Index: lib/ASTMatchers/ASTMatchFinder.cpp
===================================================================
--- lib/ASTMatchers/ASTMatchFinder.cpp
+++ lib/ASTMatchers/ASTMatchFinder.cpp
@@ -307,18 +307,20 @@
 
   void onStartOfTranslationUnit() {
     const bool EnableCheckProfiling = Options.CheckProfiling.hasValue();
+    TimeBucketRegion Timer;
     for (MatchCallback *MC : Matchers->AllCallbacks) {
-      TimeRegion Timer(EnableCheckProfiling ? &TimeByBucket[MC->getID()]
-                                            : nullptr);
+      if (EnableCheckProfiling)
+        Timer.setBucket(&TimeByBucket[MC->getID()]);
       MC->onStartOfTranslationUnit();
     }
   }
 
   void onEndOfTranslationUnit() {
     const bool EnableCheckProfiling = Options.CheckProfiling.hasValue();
+    TimeBucketRegion Timer;
     for (MatchCallback *MC : Matchers->AllCallbacks) {
-      TimeRegion Timer(EnableCheckProfiling ? &TimeByBucket[MC->getID()]
-                                            : nullptr);
+      if (EnableCheckProfiling)
+        Timer.setBucket(&TimeByBucket[MC->getID()]);
       MC->onEndOfTranslationUnit();
     }
   }
@@ -489,30 +491,36 @@
   bool shouldUseDataRecursionFor(clang::Stmt *S) const { return false; }
 
 private:
-  class TimeRegion {
+  class TimeBucketRegion {
   public:
-    TimeRegion(llvm::TimeRecord *Record) : Record(Record) {
-      if (Record)
-        *Record -= llvm::TimeRecord::getCurrentTime(true);
-    }
-    ~TimeRegion() {
-      if (Record)
-        *Record += llvm::TimeRecord::getCurrentTime(false);
+    TimeBucketRegion() : Bucket(nullptr) {}
+    ~TimeBucketRegion() { setBucket(nullptr); }
+
+    void setBucket(llvm::TimeRecord *NewBucket) {
+      if (Bucket != NewBucket) {
+        auto Now = llvm::TimeRecord::getCurrentTime(true);
+        if (Bucket)
+          *Bucket += Now;
+        if (NewBucket)
+          *NewBucket -= Now;
+        Bucket = NewBucket;
+      }
     }
 
   private:
-    llvm::TimeRecord *Record;
+    llvm::TimeRecord *Bucket;
   };
 
   /// \brief Runs all the \p Matchers on \p Node.
   ///
   /// Used by \c matchDispatch() below.
   template <typename T, typename MC>
   void matchImpl(const T &Node, const MC &Matchers) {
     const bool EnableCheckProfiling = Options.CheckProfiling.hasValue();
+    TimeBucketRegion Timer;
     for (const auto &MP : Matchers) {
-      TimeRegion Timer(EnableCheckProfiling ? &TimeByBucket[MP.second->getID()]
-                                            : nullptr);
+      if (EnableCheckProfiling)
+        Timer.setBucket(&TimeByBucket[MP.second->getID()]);
       BoundNodesTreeBuilder Builder;
       if (MP.first.matches(Node, this, &Builder)) {
         MatchVisitor Visitor(ActiveASTContext, MP.second);
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to