[PATCH] D24819: Statistic: Only print statistics on exit for -stats
Matthias Braun via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 23 15:22:19 PDT 2016
MatzeB updated this revision to Diff 72370.
MatzeB added a comment.
Leave the -stats-json option in, simplifying the patch.
Repository:
rL LLVM
https://reviews.llvm.org/D24819
Files:
lib/Support/Statistic.cpp
Index: lib/Support/Statistic.cpp
===================================================================
--- lib/Support/Statistic.cpp
+++ lib/Support/Statistic.cpp
@@ -37,15 +37,15 @@
/// -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 @@
// printed.
sys::SmartScopedLock<true> Writer(*StatLock);
if (!Initialized) {
- if (Enabled)
+ if (Stats || Enabled)
StatInfo->addStatistic(this);
TsanHappensBefore(this);
@@ -91,15 +91,16 @@
// 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 @@
// 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. "
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24819.72370.patch
Type: text/x-patch
Size: 1800 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160923/e62fd72c/attachment.bin>
More information about the llvm-commits
mailing list