Skip to content

Commit 7af8800

Browse files
committedOct 27, 2014
Speed up clang-tidy when profiling in on.
Summary: 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. Reviewers: alexfh Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D5972 llvm-svn: 220682
1 parent 49e4068 commit 7af8800

File tree

1 file changed

+31
-15
lines changed

1 file changed

+31
-15
lines changed
 

‎clang/lib/ASTMatchers/ASTMatchFinder.cpp

+31-15
Original file line numberDiff line numberDiff line change
@@ -307,18 +307,20 @@ class MatchASTVisitor : public RecursiveASTVisitor<MatchASTVisitor>,
307307

308308
void onStartOfTranslationUnit() {
309309
const bool EnableCheckProfiling = Options.CheckProfiling.hasValue();
310+
TimeBucketRegion Timer;
310311
for (MatchCallback *MC : Matchers->AllCallbacks) {
311-
TimeRegion Timer(EnableCheckProfiling ? &TimeByBucket[MC->getID()]
312-
: nullptr);
312+
if (EnableCheckProfiling)
313+
Timer.setBucket(&TimeByBucket[MC->getID()]);
313314
MC->onStartOfTranslationUnit();
314315
}
315316
}
316317

317318
void onEndOfTranslationUnit() {
318319
const bool EnableCheckProfiling = Options.CheckProfiling.hasValue();
320+
TimeBucketRegion Timer;
319321
for (MatchCallback *MC : Matchers->AllCallbacks) {
320-
TimeRegion Timer(EnableCheckProfiling ? &TimeByBucket[MC->getID()]
321-
: nullptr);
322+
if (EnableCheckProfiling)
323+
Timer.setBucket(&TimeByBucket[MC->getID()]);
322324
MC->onEndOfTranslationUnit();
323325
}
324326
}
@@ -489,19 +491,32 @@ class MatchASTVisitor : public RecursiveASTVisitor<MatchASTVisitor>,
489491
bool shouldUseDataRecursionFor(clang::Stmt *S) const { return false; }
490492

491493
private:
492-
class TimeRegion {
494+
class TimeBucketRegion {
493495
public:
494-
TimeRegion(llvm::TimeRecord *Record) : Record(Record) {
495-
if (Record)
496-
*Record -= llvm::TimeRecord::getCurrentTime(true);
497-
}
498-
~TimeRegion() {
499-
if (Record)
500-
*Record += llvm::TimeRecord::getCurrentTime(false);
496+
TimeBucketRegion() : Bucket(nullptr) {}
497+
~TimeBucketRegion() { setBucket(nullptr); }
498+
499+
/// \brief Start timing for \p NewBucket.
500+
///
501+
/// If there was a bucket already set, it will finish the timing for that
502+
/// other bucket.
503+
/// \p NewBucket will be timed until the next call to \c setBucket() or
504+
/// until the \c TimeBucketRegion is destroyed.
505+
/// If \p NewBucket is the same as the currently timed bucket, this call
506+
/// does nothing.
507+
void setBucket(llvm::TimeRecord *NewBucket) {
508+
if (Bucket != NewBucket) {
509+
auto Now = llvm::TimeRecord::getCurrentTime(true);
510+
if (Bucket)
511+
*Bucket += Now;
512+
if (NewBucket)
513+
*NewBucket -= Now;
514+
Bucket = NewBucket;
515+
}
501516
}
502517

503518
private:
504-
llvm::TimeRecord *Record;
519+
llvm::TimeRecord *Bucket;
505520
};
506521

507522
/// \brief Runs all the \p Matchers on \p Node.
@@ -510,9 +525,10 @@ class MatchASTVisitor : public RecursiveASTVisitor<MatchASTVisitor>,
510525
template <typename T, typename MC>
511526
void matchImpl(const T &Node, const MC &Matchers) {
512527
const bool EnableCheckProfiling = Options.CheckProfiling.hasValue();
528+
TimeBucketRegion Timer;
513529
for (const auto &MP : Matchers) {
514-
TimeRegion Timer(EnableCheckProfiling ? &TimeByBucket[MP.second->getID()]
515-
: nullptr);
530+
if (EnableCheckProfiling)
531+
Timer.setBucket(&TimeByBucket[MP.second->getID()]);
516532
BoundNodesTreeBuilder Builder;
517533
if (MP.first.matches(Node, this, &Builder)) {
518534
MatchVisitor Visitor(ActiveASTContext, MP.second);

0 commit comments

Comments
 (0)
Please sign in to comment.