@@ -307,18 +307,20 @@ class MatchASTVisitor : public RecursiveASTVisitor<MatchASTVisitor>,
307
307
308
308
void onStartOfTranslationUnit () {
309
309
const bool EnableCheckProfiling = Options.CheckProfiling .hasValue ();
310
+ TimeBucketRegion Timer;
310
311
for (MatchCallback *MC : Matchers->AllCallbacks ) {
311
- TimeRegion Timer (EnableCheckProfiling ? &TimeByBucket[MC-> getID ()]
312
- : nullptr );
312
+ if (EnableCheckProfiling)
313
+ Timer. setBucket (&TimeByBucket[MC-> getID ()] );
313
314
MC->onStartOfTranslationUnit ();
314
315
}
315
316
}
316
317
317
318
void onEndOfTranslationUnit () {
318
319
const bool EnableCheckProfiling = Options.CheckProfiling .hasValue ();
320
+ TimeBucketRegion Timer;
319
321
for (MatchCallback *MC : Matchers->AllCallbacks ) {
320
- TimeRegion Timer (EnableCheckProfiling ? &TimeByBucket[MC-> getID ()]
321
- : nullptr );
322
+ if (EnableCheckProfiling)
323
+ Timer. setBucket (&TimeByBucket[MC-> getID ()] );
322
324
MC->onEndOfTranslationUnit ();
323
325
}
324
326
}
@@ -489,19 +491,32 @@ class MatchASTVisitor : public RecursiveASTVisitor<MatchASTVisitor>,
489
491
bool shouldUseDataRecursionFor (clang::Stmt *S) const { return false ; }
490
492
491
493
private:
492
- class TimeRegion {
494
+ class TimeBucketRegion {
493
495
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
+ }
501
516
}
502
517
503
518
private:
504
- llvm::TimeRecord *Record ;
519
+ llvm::TimeRecord *Bucket ;
505
520
};
506
521
507
522
// / \brief Runs all the \p Matchers on \p Node.
@@ -510,9 +525,10 @@ class MatchASTVisitor : public RecursiveASTVisitor<MatchASTVisitor>,
510
525
template <typename T, typename MC>
511
526
void matchImpl (const T &Node, const MC &Matchers) {
512
527
const bool EnableCheckProfiling = Options.CheckProfiling .hasValue ();
528
+ TimeBucketRegion Timer;
513
529
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 ()] );
516
532
BoundNodesTreeBuilder Builder;
517
533
if (MP.first .matches (Node, this , &Builder)) {
518
534
MatchVisitor Visitor (ActiveASTContext, MP.second );
0 commit comments