diff options
author | Matthias Braun <matze@braunis.de> | 2016-09-26 18:38:07 +0000 |
---|---|---|
committer | Matthias Braun <matze@braunis.de> | 2016-09-26 18:38:07 +0000 |
commit | c603551b4e61ad58589e4d34cd7de69420fd7081 (patch) | |
tree | f1e7bcc2ade852a1ef4ea4eda43c1ab46ce2a0be /llvm/lib/Support/Statistic.cpp | |
parent | 3de0791144be11b7121478f78dda9e35dedb6d0b (diff) | |
download | bcm5719-llvm-c603551b4e61ad58589e4d34cd7de69420fd7081.tar.gz bcm5719-llvm-c603551b4e61ad58589e4d34cd7de69420fd7081.zip |
Statistic: Only print statistics on exit for -stats
Previously enabling the statistics with EnableStatistics() would lead to
them getting printed to stderr/-info-output-file on exit. However
frontends may want a way to enable statistics and do the printing on
their own instead of the forced printing on exit.
This changes the code so that only the -stats option enables printing on
exit, EnableStatistics() only enables the tracking but requires invoking
one of the PrintStatistics() variants.
Differential Revision: https://reviews.llvm.org/D24819
llvm-svn: 282425
Diffstat (limited to 'llvm/lib/Support/Statistic.cpp')
-rw-r--r-- | llvm/lib/Support/Statistic.cpp | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/llvm/lib/Support/Statistic.cpp b/llvm/lib/Support/Statistic.cpp index cdd36794507..774778143c2 100644 --- a/llvm/lib/Support/Statistic.cpp +++ b/llvm/lib/Support/Statistic.cpp @@ -37,15 +37,15 @@ using namespace llvm; /// -stats - Command line option to cause transformations to emit stats about /// what they did. /// -static cl::opt<bool> -Enabled( - "stats", +static cl::opt<bool> Stats("stats", cl::desc("Enable statistics output from program (available with Asserts)")); static cl::opt<bool> StatsAsJSON("stats-json", cl::desc("Display statistics as json data")); +static bool Enabled; + namespace { /// StatisticInfo - This class is used in a ManagedStatic so that it is created /// on demand (when the first statistic is bumped) and destroyed only when @@ -77,7 +77,7 @@ void Statistic::RegisterStatistic() { // printed. sys::SmartScopedLock<true> Writer(*StatLock); if (!Initialized) { - if (Enabled) + if (Stats || Enabled) StatInfo->addStatistic(this); TsanHappensBefore(this); @@ -91,15 +91,16 @@ void Statistic::RegisterStatistic() { // Print information when destroyed, iff command line option is specified. StatisticInfo::~StatisticInfo() { - llvm::PrintStatistics(); + if (::Stats) + llvm::PrintStatistics(); } void llvm::EnableStatistics() { - Enabled.setValue(true); + Enabled = true; } bool llvm::AreStatisticsEnabled() { - return Enabled; + return Enabled || Stats; } void StatisticInfo::sort() { @@ -195,7 +196,7 @@ void llvm::PrintStatistics() { // Check if the -stats option is set instead of checking // !Stats.Stats.empty(). In release builds, Statistics operators // do nothing, so stats are never Registered. - if (Enabled) { + if (Stats) { // Get the stream to write to. std::unique_ptr<raw_ostream> OutStream = CreateInfoOutputFile(); (*OutStream) << "Statistics are disabled. " |