Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 3911695

Browse files
committed
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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@282425 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 4d5121c commit 3911695

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

lib/Support/Statistic.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ using namespace llvm;
3737
/// -stats - Command line option to cause transformations to emit stats about
3838
/// what they did.
3939
///
40-
static cl::opt<bool>
41-
Enabled(
42-
"stats",
40+
static cl::opt<bool> Stats("stats",
4341
cl::desc("Enable statistics output from program (available with Asserts)"));
4442

4543

4644
static cl::opt<bool> StatsAsJSON("stats-json",
4745
cl::desc("Display statistics as json data"));
4846

47+
static bool Enabled;
48+
4949
namespace {
5050
/// StatisticInfo - This class is used in a ManagedStatic so that it is created
5151
/// on demand (when the first statistic is bumped) and destroyed only when
@@ -77,7 +77,7 @@ void Statistic::RegisterStatistic() {
7777
// printed.
7878
sys::SmartScopedLock<true> Writer(*StatLock);
7979
if (!Initialized) {
80-
if (Enabled)
80+
if (Stats || Enabled)
8181
StatInfo->addStatistic(this);
8282

8383
TsanHappensBefore(this);
@@ -91,15 +91,16 @@ void Statistic::RegisterStatistic() {
9191

9292
// Print information when destroyed, iff command line option is specified.
9393
StatisticInfo::~StatisticInfo() {
94-
llvm::PrintStatistics();
94+
if (::Stats)
95+
llvm::PrintStatistics();
9596
}
9697

9798
void llvm::EnableStatistics() {
98-
Enabled.setValue(true);
99+
Enabled = true;
99100
}
100101

101102
bool llvm::AreStatisticsEnabled() {
102-
return Enabled;
103+
return Enabled || Stats;
103104
}
104105

105106
void StatisticInfo::sort() {
@@ -195,7 +196,7 @@ void llvm::PrintStatistics() {
195196
// Check if the -stats option is set instead of checking
196197
// !Stats.Stats.empty(). In release builds, Statistics operators
197198
// do nothing, so stats are never Registered.
198-
if (Enabled) {
199+
if (Stats) {
199200
// Get the stream to write to.
200201
std::unique_ptr<raw_ostream> OutStream = CreateInfoOutputFile();
201202
(*OutStream) << "Statistics are disabled. "

0 commit comments

Comments
 (0)