LLVM: lib/Support/Statistic.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
24
26
37#include
38#include
39using namespace llvm;
40
41
42
43
48
51 "stats",
53 "Enable statistics output from program (available with Asserts)"),
56 "stats-json", cl::desc("Display statistics as json data"),
58}
59
60namespace {
61
62
63
64
65
66class StatisticInfo {
67 std::vector<TrackingStatistic *> Stats;
68
72
73
75public:
76 using const_iterator = std::vector<TrackingStatistic *>::const_iterator;
77
78 StatisticInfo();
79 ~StatisticInfo();
80
82
83 const_iterator begin() const { return Stats.begin(); }
84 const_iterator end() const { return Stats.end(); }
85 iterator_range<const_iterator> statistics() const {
87 }
88
89 void reset();
90};
91}
92
95
96
97
99
100
101
102
103
104
105
106
107 if (.load(std::memory_order_relaxed)) {
111
112 if (Initialized.load(std::memory_order_relaxed))
113 return;
115 SI.addStatistic(this);
116
117
118 Initialized.store(true, std::memory_order_release);
119 }
120}
121
122StatisticInfo::StatisticInfo() {
123
124
126}
127
128
129StatisticInfo::~StatisticInfo() {
132}
133
138
140
141void StatisticInfo::sort() {
144 if (int Cmp = std::strcmp(LHS->getDebugType(), RHS->getDebugType()))
145 return Cmp < 0;
146
147 if (int Cmp = std::strcmp(LHS->getName(), RHS->getName()))
148 return Cmp < 0;
149
150 return std::strcmp(LHS->getDesc(), RHS->getDesc()) < 0;
151 });
152}
153
154void StatisticInfo::reset() {
156
157
158
159
160
161 for (auto *Stat : Stats) {
162
163
164 Stat->Initialized = false;
165 Stat->Value = 0;
166 }
167
168
169
170
171
172
174}
175
178
179
180 unsigned MaxDebugTypeLen = 0, MaxValLen = 0;
182 MaxValLen = std::max(MaxValLen, (unsigned)utostr(Stat->getValue()).size());
183 MaxDebugTypeLen =
184 std::max(MaxDebugTypeLen, (unsigned)std::strlen(Stat->getDebugType()));
185 }
186
188
189
190 OS << "===" << std::string(73, '-') << "===\n"
191 << " ... Statistics Collected ...\n"
192 << "===" << std::string(73, '-') << "===\n\n";
193
194
196 OS << format("%*" PRIu64 " %-*s - %s\n", MaxValLen, Stat->getValue(),
198
199 OS << '\n';
201}
202
206
208
209
210 OS << "{\n";
211 const char *delim = "";
213 OS << delim;
215 "Statistic group/type name is simple.");
217 "Statistic name is simple");
220 delim = ",\n";
221 }
222
224
225 OS << "\n}\n";
227}
228
230#if LLVM_ENABLE_STATS
233
234
235 if (Stats.Stats.empty()) return;
236
237
241 else
243
244#else
245
246
247
249
251 (*OutStream) << "Statistics are disabled. "
252 << "Build with asserts or with -DLLVM_FORCE_ENABLE_STATS\n";
253 }
254#endif
255}
256
259 std::vector<std::pair<StringRef, uint64_t>> ReturnStats;
260
261 for (const auto &Stat : StatInfo->statistics())
262 ReturnStats.emplace_back(Stat->getName(), Stat->getValue());
263 return ReturnStats;
264}
265
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
block placement Basic Block Placement Stats
static bool EnableStats
-stats - Command line option to cause transformations to emit stats about what they did.
Definition Statistic.cpp:44
static bool PrintOnExit
Definition Statistic.cpp:47
static ManagedStatic< StatisticInfo > StatInfo
Definition Statistic.cpp:93
static bool StatsAsJSON
Definition Statistic.cpp:45
static ManagedStatic< sys::SmartMutex< true > > StatLock
Definition Statistic.cpp:94
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
ManagedStatic - This transparently changes the behavior of global statics to be lazily constructed on...
static LLVM_ABI const char * printAllJSONValues(raw_ostream &OS, const char *delim)
Prints all timers as JSON key/value pairs.
static LLVM_ABI void constructForStatistics()
Ensure global objects required for statistics printing are initialized.
const char * getDesc() const
uint64_t getValue() const
const char * getDebugType() const
const char * getName() const
std::atomic< bool > Initialized
LLVM_ABI void RegisterStatistic()
RegisterStatistic - The first time a statistic is bumped, this method is called.
Definition Statistic.cpp:98
This class implements an extremely fast bulk output stream that can only output to a stream.
SmartMutex - A mutex with a compile time constant parameter that indicates whether this mutex should ...
LocationClass< Ty > location(Ty &L)
LLVM_ABI iterator begin() const
std::lock_guard< SmartMutex< mt_only > > SmartScopedLock
QuotingType needsQuotes(StringRef S, bool ForcePreserveAsString=true)
This is an optimization pass for GlobalISel generic memory operations.
void stable_sort(R &&Range)
LLVM_ABI std::unique_ptr< raw_ostream > CreateInfoOutputFile()
Return a stream to print our output on.
LLVM_ABI void ResetStatistics()
Reset the statistics.
Definition Statistic.cpp:266
std::string utostr(uint64_t X, bool isNeg=false)
LLVM_ABI void EnableStatistics(bool DoPrintOnExit=true)
Enable the collection and printing of statistics.
Definition Statistic.cpp:134
void sort(IteratorTy Start, IteratorTy End)
LLVM_ABI bool AreStatisticsEnabled()
Check if statistics are enabled.
Definition Statistic.cpp:139
void initStatisticOptions()
Definition Statistic.cpp:49
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
LLVM_ABI void PrintStatistics()
Print statistics to the file returned by CreateInfoOutputFile().
Definition Statistic.cpp:229
LLVM_ABI std::vector< std::pair< StringRef, uint64_t > > GetStatistics()
Get the statistics.
Definition Statistic.cpp:257
@ Enabled
Convert any .debug_str_offsets tables to DWARF64 if needed.
LLVM_ABI void PrintStatisticsJSON(raw_ostream &OS)
Print statistics in JSON format.
Definition Statistic.cpp:203