llvm.org GIT mirror llvm / 96ef1b9
- Rework Statistics: * Renamed StatisticReporter.h/cpp to Statistic.h/cpp * Broke constructor to take two const char * arguments instead of one, so that indendation can be taken care of automatically. * Sort the list by pass name when printing * Make sure to print all statistics as a group, instead of randomly when the statistics dtors are called. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@3999 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 17 years ago
6 changed file(s) with 142 addition(s) and 158 deletion(s). Raw diff Collapse all Expand all
None //===-- Support/StatisticReporter.h - Easy way to expose stats ---*- C++ -*-==//
0 //===-- Support/Statistic.h - Easy way to expose stats ----------*- C++ -*-===//
11 //
22 // This file defines the 'Statistic' class, which is designed to be an easy way
33 // to expose various success metrics from passes. These statistics are printed
1313 //
1414 //===----------------------------------------------------------------------===//
1515
16 #ifndef SUPPORT_STATISTIC_REPORTER_H
17 #define SUPPORT_STATISTIC_REPORTER_H
16 #ifndef SUPPORT_STATISTIC_H
17 #define SUPPORT_STATISTIC_H
1818
1919 #include
2020
4242 // StatisticBase - Nontemplated base class for Statistic<> class...
4343 class StatisticBase {
4444 const char *Name;
45 const char *Desc;
46 static unsigned NumStats;
4547 protected:
46 StatisticBase(const char *name) : Name(name) {}
48 StatisticBase(const char *name, const char *desc) : Name(name), Desc(desc) {
49 ++NumStats; // Keep track of how many stats are created...
50 }
4751 virtual ~StatisticBase() {}
4852
4953 // destroy - Called by subclass dtor so that we can still invoke virtual
6872 virtual bool hasSomeData() const { return Value != DataType(); }
6973 public:
7074 // Normal constructor, default initialize data item...
71 Statistic(const char *name) : StatisticBase(name), Value(DataType()) {}
75 Statistic(const char *name, const char *desc)
76 : StatisticBase(name, desc), Value(DataType()) {}
7277
7378 // Constructor to provide an initial value...
74 Statistic(const DataType &Val, const char *name)
75 : StatisticBase(name), Value(Val) {}
79 Statistic(const DataType &Val, const char *name, const char *desc)
80 : StatisticBase(name, desc), Value(Val) {}
7681
7782 // Print information when destroyed, iff command line option is specified
7883 ~Statistic() { destroy(); }
+0
-90
include/Support/StatisticReporter.h less more
None //===-- Support/StatisticReporter.h - Easy way to expose stats ---*- C++ -*-==//
1 //
2 // This file defines the 'Statistic' class, which is designed to be an easy way
3 // to expose various success metrics from passes. These statistics are printed
4 // at the end of a run, when the -stats command line option is enabled on the
5 // command line.
6 //
7 // This is useful for reporting information like the number of instructions
8 // simplified, optimized or removed by various transformations, like this:
9 //
10 // static Statistic<> NumInstEliminated("GCSE - Number of instructions killed");
11 //
12 // Later, in the code: ++NumInstEliminated;
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef SUPPORT_STATISTIC_REPORTER_H
17 #define SUPPORT_STATISTIC_REPORTER_H
18
19 #include
20
21 // DebugFlag - This boolean is set to true if the '-debug' command line option
22 // is specified. This should probably not be referenced directly, instead, use
23 // the DEBUG macro below.
24 //
25 extern bool DebugFlag;
26
27 // DEBUG macro - This macro should be used by passes to emit debug information.
28 // In the '-debug' option is specified on the commandline, and if this is a
29 // debug build, then the code specified as the option to the macro will be
30 // executed. Otherwise it will not be. Example:
31 //
32 // DEBUG(cerr << "Bitset contains: " << Bitset << "\n");
33 //
34 #ifdef NDEBUG
35 #define DEBUG(X)
36 #else
37 #define DEBUG(X) \
38 do { if (DebugFlag) { X; } } while (0)
39 #endif
40
41
42 // StatisticBase - Nontemplated base class for Statistic<> class...
43 class StatisticBase {
44 const char *Name;
45 protected:
46 StatisticBase(const char *name) : Name(name) {}
47 virtual ~StatisticBase() {}
48
49 // destroy - Called by subclass dtor so that we can still invoke virtual
50 // functions on the subclass.
51 void destroy() const;
52
53 // printValue - Overridden by template class to print out the value type...
54 virtual void printValue(std::ostream &o) const = 0;
55
56 // hasSomeData - Return true if some data has been aquired. Avoid printing
57 // lots of zero counts.
58 //
59 virtual bool hasSomeData() const = 0;
60 };
61
62 // Statistic Class - templated on the data type we are monitoring...
63 template
64 class Statistic : private StatisticBase {
65 DataType Value;
66
67 virtual void printValue(std::ostream &o) const { o << Value; }
68 virtual bool hasSomeData() const { return Value != DataType(); }
69 public:
70 // Normal constructor, default initialize data item...
71 Statistic(const char *name) : StatisticBase(name), Value(DataType()) {}
72
73 // Constructor to provide an initial value...
74 Statistic(const DataType &Val, const char *name)
75 : StatisticBase(name), Value(Val) {}
76
77 // Print information when destroyed, iff command line option is specified
78 ~Statistic() { destroy(); }
79
80 // Allow use of this class as the value itself...
81 inline operator DataType() const { return Value; }
82 inline const DataType &operator=(DataType Val) { Value = Val; return Value; }
83 inline const DataType &operator++() { return ++Value; }
84 inline DataType operator++(int) { return Value++; }
85 inline const DataType &operator+=(const DataType &V) { return Value += V; }
86 inline const DataType &operator-=(const DataType &V) { return Value -= V; }
87 };
88
89 #endif
None //===-- Support/StatisticReporter.h - Easy way to expose stats ---*- C++ -*-==//
0 //===-- Support/Statistic.h - Easy way to expose stats ----------*- C++ -*-===//
11 //
22 // This file defines the 'Statistic' class, which is designed to be an easy way
33 // to expose various success metrics from passes. These statistics are printed
1313 //
1414 //===----------------------------------------------------------------------===//
1515
16 #ifndef SUPPORT_STATISTIC_REPORTER_H
17 #define SUPPORT_STATISTIC_REPORTER_H
16 #ifndef SUPPORT_STATISTIC_H
17 #define SUPPORT_STATISTIC_H
1818
1919 #include
2020
4242 // StatisticBase - Nontemplated base class for Statistic<> class...
4343 class StatisticBase {
4444 const char *Name;
45 const char *Desc;
46 static unsigned NumStats;
4547 protected:
46 StatisticBase(const char *name) : Name(name) {}
48 StatisticBase(const char *name, const char *desc) : Name(name), Desc(desc) {
49 ++NumStats; // Keep track of how many stats are created...
50 }
4751 virtual ~StatisticBase() {}
4852
4953 // destroy - Called by subclass dtor so that we can still invoke virtual
6872 virtual bool hasSomeData() const { return Value != DataType(); }
6973 public:
7074 // Normal constructor, default initialize data item...
71 Statistic(const char *name) : StatisticBase(name), Value(DataType()) {}
75 Statistic(const char *name, const char *desc)
76 : StatisticBase(name, desc), Value(DataType()) {}
7277
7378 // Constructor to provide an initial value...
74 Statistic(const DataType &Val, const char *name)
75 : StatisticBase(name), Value(Val) {}
79 Statistic(const DataType &Val, const char *name, const char *desc)
80 : StatisticBase(name, desc), Value(Val) {}
7681
7782 // Print information when destroyed, iff command line option is specified
7883 ~Statistic() { destroy(); }
None //===-- StatisticReporter.cpp - Easy way to expose stats information -------==//
0 //===-- Statistic.cpp - Easy way to expose stats information --------------===//
11 //
22 // This file implements the 'Statistic' class, which is designed to be an easy
33 // way to expose various success metrics from passes. These statistics are
1313 //
1414 //===----------------------------------------------------------------------===//
1515
16 #include "Support/StatisticReporter.h"
16 #include "Support/Statistic.h"
1717 #include "Support/CommandLine.h"
1818 #include
19 #include
1920
2021 bool DebugFlag; // DebugFlag - Exported boolean set by the -debug option
22
23 unsigned StatisticBase::NumStats = 0;
2124
2225 // -stats - Command line option to cause transformations to emit stats about
2326 // what they did.
3033 Debug("debug", cl::desc("Enable debug output"), cl::Hidden,
3134 cl::location(DebugFlag));
3235
36 struct StatRecord {
37 std::string Value;
38 const char *Name, *Desc;
39
40 StatRecord(const std::string V, const char *N, const char *D)
41 : Value(V), Name(N), Desc(D) {}
42
43 bool operator<(const StatRecord &SR) const {
44 return std::strcmp(Name, SR.Name) < 0;
45 }
46
47 void print(unsigned ValFieldSize, unsigned NameFieldSize) {
48 std::cerr << std::string(ValFieldSize-Value.length(), ' ')
49 << Value << " " << Name
50 << std::string(NameFieldSize-std::strlen(Name), ' ')
51 << " - " << Desc << "\n";
52 }
53 };
54
55 static std::vector *AccumStats = 0;
56
3357 // Print information when destroyed, iff command line option is specified
3458 void StatisticBase::destroy() const {
3559 if (Enabled && hasSomeData()) {
36 std::cerr.width(7);
37 printValue(std::cerr);
38 std::cerr.width(0);
39 std::cerr << "\t" << Name << "\n";
60 if (AccumStats == 0)
61 AccumStats = new std::vector();
62
63 std::ostringstream Out;
64 printValue(Out);
65 AccumStats->push_back(StatRecord(Out.str(), Name, Desc));
66 }
67
68 if (--NumStats == 0 && AccumStats) {
69 // Figure out how long the biggest Value and Name fields are...
70 unsigned MaxNameLen = 0, MaxValLen = 0;
71 for (unsigned i = 0, e = AccumStats->size(); i != e; ++i) {
72 MaxValLen = std::max(MaxValLen, (*AccumStats)[i].Value.length());
73 MaxNameLen = std::max(MaxNameLen, std::strlen((*AccumStats)[i].Name));
74 }
75
76 // Sort the fields...
77 std::stable_sort(AccumStats->begin(), AccumStats->end());
78
79 // Print out the statistics header...
80 std::cerr << "===" << std::string(73, '-') << "===\n"
81 << " ... Statistics Collected ...\n"
82 << "===" << std::string(73, '-') << "===\n\n";
83
84 // Print all of the statistics accumulated...
85 for (unsigned i = 0, e = AccumStats->size(); i != e; ++i)
86 (*AccumStats)[i].print(MaxValLen, MaxNameLen);
87
88 std::cerr << std::endl; // Flush the output stream...
89
90 // Free all accumulated statistics...
91 delete AccumStats;
92 AccumStats = 0;
4093 }
4194 }
None //===-- StatisticReporter.cpp - Easy way to expose stats information -------==//
0 //===-- Statistic.cpp - Easy way to expose stats information --------------===//
11 //
22 // This file implements the 'Statistic' class, which is designed to be an easy
33 // way to expose various success metrics from passes. These statistics are
1313 //
1414 //===----------------------------------------------------------------------===//
1515
16 #include "Support/StatisticReporter.h"
16 #include "Support/Statistic.h"
1717 #include "Support/CommandLine.h"
1818 #include
19 #include
1920
2021 bool DebugFlag; // DebugFlag - Exported boolean set by the -debug option
22
23 unsigned StatisticBase::NumStats = 0;
2124
2225 // -stats - Command line option to cause transformations to emit stats about
2326 // what they did.
3033 Debug("debug", cl::desc("Enable debug output"), cl::Hidden,
3134 cl::location(DebugFlag));
3235
36 struct StatRecord {
37 std::string Value;
38 const char *Name, *Desc;
39
40 StatRecord(const std::string V, const char *N, const char *D)
41 : Value(V), Name(N), Desc(D) {}
42
43 bool operator<(const StatRecord &SR) const {
44 return std::strcmp(Name, SR.Name) < 0;
45 }
46
47 void print(unsigned ValFieldSize, unsigned NameFieldSize) {
48 std::cerr << std::string(ValFieldSize-Value.length(), ' ')
49 << Value << " " << Name
50 << std::string(NameFieldSize-std::strlen(Name), ' ')
51 << " - " << Desc << "\n";
52 }
53 };
54
55 static std::vector *AccumStats = 0;
56
3357 // Print information when destroyed, iff command line option is specified
3458 void StatisticBase::destroy() const {
3559 if (Enabled && hasSomeData()) {
36 std::cerr.width(7);
37 printValue(std::cerr);
38 std::cerr.width(0);
39 std::cerr << "\t" << Name << "\n";
60 if (AccumStats == 0)
61 AccumStats = new std::vector();
62
63 std::ostringstream Out;
64 printValue(Out);
65 AccumStats->push_back(StatRecord(Out.str(), Name, Desc));
66 }
67
68 if (--NumStats == 0 && AccumStats) {
69 // Figure out how long the biggest Value and Name fields are...
70 unsigned MaxNameLen = 0, MaxValLen = 0;
71 for (unsigned i = 0, e = AccumStats->size(); i != e; ++i) {
72 MaxValLen = std::max(MaxValLen, (*AccumStats)[i].Value.length());
73 MaxNameLen = std::max(MaxNameLen, std::strlen((*AccumStats)[i].Name));
74 }
75
76 // Sort the fields...
77 std::stable_sort(AccumStats->begin(), AccumStats->end());
78
79 // Print out the statistics header...
80 std::cerr << "===" << std::string(73, '-') << "===\n"
81 << " ... Statistics Collected ...\n"
82 << "===" << std::string(73, '-') << "===\n\n";
83
84 // Print all of the statistics accumulated...
85 for (unsigned i = 0, e = AccumStats->size(); i != e; ++i)
86 (*AccumStats)[i].print(MaxValLen, MaxNameLen);
87
88 std::cerr << std::endl; // Flush the output stream...
89
90 // Free all accumulated statistics...
91 delete AccumStats;
92 AccumStats = 0;
4093 }
4194 }
+0
-42
support/lib/Support/StatisticReporter.cpp less more
None //===-- StatisticReporter.cpp - Easy way to expose stats information -------==//
1 //
2 // This file implements the 'Statistic' class, which is designed to be an easy
3 // way to expose various success metrics from passes. These statistics are
4 // printed at the end of a run, when the -stats command line option is enabled
5 // on the command line.
6 //
7 // This is useful for reporting information like the number of instructions
8 // simplified, optimized or removed by various transformations, like this:
9 //
10 // static Statistic<> NumInstEliminated("GCSE - Number of instructions killed");
11 //
12 // Later, in the code: ++NumInstEliminated;
13 //
14 //===----------------------------------------------------------------------===//
15
16 #include "Support/StatisticReporter.h"
17 #include "Support/CommandLine.h"
18 #include
19
20 bool DebugFlag; // DebugFlag - Exported boolean set by the -debug option
21
22 // -stats - Command line option to cause transformations to emit stats about
23 // what they did.
24 //
25 static cl::opt
26 Enabled("stats", cl::desc("Enable statistics output from program"));
27
28 // -debug - Command line option to enable the DEBUG statements in the passes.
29 static cl::opt
30 Debug("debug", cl::desc("Enable debug output"), cl::Hidden,
31 cl::location(DebugFlag));
32
33 // Print information when destroyed, iff command line option is specified
34 void StatisticBase::destroy() const {
35 if (Enabled && hasSomeData()) {
36 std::cerr.width(7);
37 printValue(std::cerr);
38 std::cerr.width(0);
39 std::cerr << "\t" << Name << "\n";
40 }
41 }