diff options
author | Daniel Sanders <daniel_l_sanders@apple.com> | 2018-03-08 02:36:25 +0000 |
---|---|---|
committer | Daniel Sanders <daniel_l_sanders@apple.com> | 2018-03-08 02:36:25 +0000 |
commit | 1087a542554ac0ab23bbca07d026b2fb49862809 (patch) | |
tree | e930be6193658e4dfbcfb9d91aabaa66799d1fbb /llvm/lib/Support/Statistic.cpp | |
parent | e4f47b4c63dd99508410087f5b6643f3e668ed23 (diff) | |
download | bcm5719-llvm-1087a542554ac0ab23bbca07d026b2fb49862809.tar.gz bcm5719-llvm-1087a542554ac0ab23bbca07d026b2fb49862809.zip |
Support resetting STATISTIC() values using llvm::ResetStatistics()
Summary:
Most of the time, compiler statistics can be obtained using a process that
performs a single compilation and terminates such as llc. However, this isn't
always the case. JITs for example, perform multiple compilations over their
lifetime and STATISTIC() will record cumulative values across all of them.
Provide tools like this with the facilities needed to measure individual
compilations by allowing them to reset the STATISTIC() values back to zero using
llvm::ResetStatistics(). It's still the tools responsibility to ensure that they
perform compilations in such a way that the results are meaningful to their
intended use.
Reviewers: qcolombet, rtereshin, bogner, aditya_nandakumar
Reviewed By: bogner
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D44181
llvm-svn: 326981
Diffstat (limited to 'llvm/lib/Support/Statistic.cpp')
-rw-r--r-- | llvm/lib/Support/Statistic.cpp | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/llvm/lib/Support/Statistic.cpp b/llvm/lib/Support/Statistic.cpp index 1985409f35c..3f54374c670 100644 --- a/llvm/lib/Support/Statistic.cpp +++ b/llvm/lib/Support/Statistic.cpp @@ -58,7 +58,7 @@ namespace { /// This class is also used to look up statistic values from applications that /// use LLVM. class StatisticInfo { - std::vector<const Statistic*> Stats; + std::vector<Statistic*> Stats; friend void llvm::PrintStatistics(); friend void llvm::PrintStatistics(raw_ostream &OS); @@ -67,12 +67,12 @@ class StatisticInfo { /// Sort statistics by debugtype,name,description. void sort(); public: - using const_iterator = std::vector<const Statistic *>::const_iterator; + using const_iterator = std::vector<Statistic *>::const_iterator; StatisticInfo(); ~StatisticInfo(); - void addStatistic(const Statistic *S) { + void addStatistic(Statistic *S) { Stats.push_back(S); } @@ -81,6 +81,8 @@ public: iterator_range<const_iterator> statistics() const { return {begin(), end()}; } + + void reset(); }; } // end anonymous namespace @@ -135,6 +137,28 @@ void StatisticInfo::sort() { }); } +void StatisticInfo::reset() { + sys::SmartScopedLock<true> Writer(*StatLock); + + // Tell each statistic that it isn't registered so it has to register + // again. We're holding the lock so it won't be able to do so until we're + // finished. Once we've forced it to re-register (after we return), then zero + // the value. + for (auto *Stat : Stats) { + // Value updates to a statistic that complete before this statement in the + // iteration for that statistic will be lost as intended. + Stat->Initialized = false; + Stat->Value = 0; + } + + // Clear the registration list and release the lock once we're done. Any + // pending updates from other threads will safely take effect after we return. + // That might not be what the user wants if they're measuring a compilation + // but it's their responsibility to prevent concurrent compilations to make + // a single compilation measurable. + Stats.clear(); +} + void llvm::PrintStatistics(raw_ostream &OS) { StatisticInfo &Stats = *StatInfo; @@ -227,3 +251,7 @@ const std::vector<std::pair<StringRef, unsigned>> llvm::GetStatistics() { ReturnStats.emplace_back(Stat->getName(), Stat->getValue()); return ReturnStats; } + +void llvm::ResetStatistics() { + StatInfo->reset(); +} |