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
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)) {
109 StatisticInfo &SI = *StatInfo;
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
137}
138
140
141void StatisticInfo::sort() {
144 if (int Cmp = std::strcmp(LHS->getDebugType(), RHS->getDebugType()))
145 return Cmp < 0;
146
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(),
197 MaxDebugTypeLen, Stat->getDebugType(), Stat->getDesc());
198
199 OS << '\n';
201}
202
206
208
209
210 OS << "{\n";
211 const char *delim = "";
213 OS << delim;
214 assert(yaml::needsQuotes(Stat->getDebugType()) == yaml::QuotingType::None &&
215 "Statistic group/type name is simple.");
216 assert(yaml::needsQuotes(Stat->getName()) == yaml::QuotingType::None &&
217 "Statistic name is simple");
218 OS << "\t\"" << Stat->getDebugType() << '.' << Stat->getName() << "\": "
219 << Stat->getValue();
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
268}
block placement Basic Block Placement Stats
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static bool EnableStats
-stats - Command line option to cause transformations to emit stats about what they did.
static ManagedStatic< StatisticInfo > StatInfo
static ManagedStatic< sys::SmartMutex< true > > StatLock
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 const char * printAllJSONValues(raw_ostream &OS, const char *delim)
Prints all timers as JSON key/value pairs.
static void constructForStatistics()
Ensure global objects required for statistics printing are initialized.
std::atomic< bool > Initialized
void RegisterStatistic()
RegisterStatistic - The first time a statistic is bumped, this method is called.
StringRef getName() const
Return a constant reference to the value's name.
A range adaptor for a pair of iterators.
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)
const_iterator begin(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get begin iterator over path.
const_iterator end(StringRef path LLVM_LIFETIME_BOUND)
Get end iterator over path.
std::lock_guard< SmartMutex< mt_only > > SmartScopedLock
This is an optimization pass for GlobalISel generic memory operations.
void stable_sort(R &&Range)
std::unique_ptr< raw_ostream > CreateInfoOutputFile()
Return a stream to print our output on.
void ResetStatistics()
Reset the statistics.
void EnableStatistics(bool DoPrintOnExit=true)
Enable the collection and printing of statistics.
void sort(IteratorTy Start, IteratorTy End)
bool AreStatisticsEnabled()
Check if statistics are enabled.
void initStatisticOptions()
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
void PrintStatistics()
Print statistics to the file returned by CreateInfoOutputFile().
std::vector< std::pair< StringRef, uint64_t > > GetStatistics()
Get the statistics.
void PrintStatisticsJSON(raw_ostream &OS)
Print statistics in JSON format.