[PATCH] D24819: Statistic: Only print statistics on exit for -stats

Matthias Braun via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 21 19:22:02 PDT 2016


MatzeB created this revision.
MatzeB added a reviewer: bruno.
MatzeB added a subscriber: llvm-commits.
MatzeB set the repository for this revision to rL LLVM.
Herald added a subscriber: mcrosier.

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.

Also remove the -stats-json option; I am about to propose a better
system for clang which supersedes it.

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,14 +37,10 @@
 /// -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
@@ -77,7 +73,7 @@
   // printed.
   sys::SmartScopedLock<true> Writer(*StatLock);
   if (!Initialized) {
-    if (Enabled)
+    if (Stats || Enabled)
       StatInfo->addStatistic(this);
 
     TsanHappensBefore(this);
@@ -91,15 +87,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() {
@@ -186,16 +183,12 @@
 
   // Get the stream to write to.
   std::unique_ptr<raw_ostream> OutStream = CreateInfoOutputFile();
-  if (StatsAsJSON)
-    PrintStatisticsJSON(*OutStream);
-  else
-    PrintStatistics(*OutStream);
-
+  PrintStatistics(*OutStream);
 #else
   // 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.72134.patch
Type: text/x-patch
Size: 1969 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160922/492e5c2e/attachment.bin>


More information about the llvm-commits mailing list