forked from OSchip/llvm-project
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
This commit is contained in:
parent
49e4068781
commit
7af8800095
|
@ -307,18 +307,20 @@ public:
|
||||||
|
|
||||||
void onStartOfTranslationUnit() {
|
void onStartOfTranslationUnit() {
|
||||||
const bool EnableCheckProfiling = Options.CheckProfiling.hasValue();
|
const bool EnableCheckProfiling = Options.CheckProfiling.hasValue();
|
||||||
|
TimeBucketRegion Timer;
|
||||||
for (MatchCallback *MC : Matchers->AllCallbacks) {
|
for (MatchCallback *MC : Matchers->AllCallbacks) {
|
||||||
TimeRegion Timer(EnableCheckProfiling ? &TimeByBucket[MC->getID()]
|
if (EnableCheckProfiling)
|
||||||
: nullptr);
|
Timer.setBucket(&TimeByBucket[MC->getID()]);
|
||||||
MC->onStartOfTranslationUnit();
|
MC->onStartOfTranslationUnit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void onEndOfTranslationUnit() {
|
void onEndOfTranslationUnit() {
|
||||||
const bool EnableCheckProfiling = Options.CheckProfiling.hasValue();
|
const bool EnableCheckProfiling = Options.CheckProfiling.hasValue();
|
||||||
|
TimeBucketRegion Timer;
|
||||||
for (MatchCallback *MC : Matchers->AllCallbacks) {
|
for (MatchCallback *MC : Matchers->AllCallbacks) {
|
||||||
TimeRegion Timer(EnableCheckProfiling ? &TimeByBucket[MC->getID()]
|
if (EnableCheckProfiling)
|
||||||
: nullptr);
|
Timer.setBucket(&TimeByBucket[MC->getID()]);
|
||||||
MC->onEndOfTranslationUnit();
|
MC->onEndOfTranslationUnit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -489,19 +491,32 @@ public:
|
||||||
bool shouldUseDataRecursionFor(clang::Stmt *S) const { return false; }
|
bool shouldUseDataRecursionFor(clang::Stmt *S) const { return false; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class TimeRegion {
|
class TimeBucketRegion {
|
||||||
public:
|
public:
|
||||||
TimeRegion(llvm::TimeRecord *Record) : Record(Record) {
|
TimeBucketRegion() : Bucket(nullptr) {}
|
||||||
if (Record)
|
~TimeBucketRegion() { setBucket(nullptr); }
|
||||||
*Record -= llvm::TimeRecord::getCurrentTime(true);
|
|
||||||
}
|
/// \brief Start timing for \p NewBucket.
|
||||||
~TimeRegion() {
|
///
|
||||||
if (Record)
|
/// If there was a bucket already set, it will finish the timing for that
|
||||||
*Record += llvm::TimeRecord::getCurrentTime(false);
|
/// other bucket.
|
||||||
|
/// \p NewBucket will be timed until the next call to \c setBucket() or
|
||||||
|
/// until the \c TimeBucketRegion is destroyed.
|
||||||
|
/// If \p NewBucket is the same as the currently timed bucket, this call
|
||||||
|
/// does nothing.
|
||||||
|
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:
|
private:
|
||||||
llvm::TimeRecord *Record;
|
llvm::TimeRecord *Bucket;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \brief Runs all the \p Matchers on \p Node.
|
/// \brief Runs all the \p Matchers on \p Node.
|
||||||
|
@ -510,9 +525,10 @@ private:
|
||||||
template <typename T, typename MC>
|
template <typename T, typename MC>
|
||||||
void matchImpl(const T &Node, const MC &Matchers) {
|
void matchImpl(const T &Node, const MC &Matchers) {
|
||||||
const bool EnableCheckProfiling = Options.CheckProfiling.hasValue();
|
const bool EnableCheckProfiling = Options.CheckProfiling.hasValue();
|
||||||
|
TimeBucketRegion Timer;
|
||||||
for (const auto &MP : Matchers) {
|
for (const auto &MP : Matchers) {
|
||||||
TimeRegion Timer(EnableCheckProfiling ? &TimeByBucket[MP.second->getID()]
|
if (EnableCheckProfiling)
|
||||||
: nullptr);
|
Timer.setBucket(&TimeByBucket[MP.second->getID()]);
|
||||||
BoundNodesTreeBuilder Builder;
|
BoundNodesTreeBuilder Builder;
|
||||||
if (MP.first.matches(Node, this, &Builder)) {
|
if (MP.first.matches(Node, this, &Builder)) {
|
||||||
MatchVisitor Visitor(ActiveASTContext, MP.second);
|
MatchVisitor Visitor(ActiveASTContext, MP.second);
|
||||||
|
|
Loading…
Reference in New Issue