43 cl::desc(
"Enable statistics output from program (available with Asserts)"),
47 cl::desc(
"Display statistics as json data"),
60 std::vector<TrackingStatistic *>
Stats;
69 using const_iterator = std::vector<TrackingStatistic *>::const_iterator;
76 const_iterator
begin()
const {
return Stats.
begin(); }
77 const_iterator
end()
const {
return Stats.
end(); }
100 if (!Initialized.load(std::memory_order_relaxed)) {
105 if (Initialized.load(std::memory_order_relaxed))
107 if (
Stats || Enabled)
108 SI.addStatistic(
this);
111 Initialized.store(
true, std::memory_order_release);
115 StatisticInfo::StatisticInfo() {
121 StatisticInfo::~StatisticInfo() {
122 if (::
Stats || PrintOnExit)
132 return Enabled ||
Stats;
148 void StatisticInfo::reset() {
155 for (
auto *Stat :
Stats) {
158 Stat->Initialized =
false;
174 unsigned MaxDebugTypeLen = 0, MaxValLen = 0;
175 for (
size_t i = 0,
e = Stats.Stats.size(); i !=
e; ++i) {
177 (
unsigned)
utostr(Stats.Stats[i]->getValue()).
size());
178 MaxDebugTypeLen =
std::max(MaxDebugTypeLen,
179 (
unsigned)std::strlen(Stats.Stats[i]->getDebugType()));
185 OS <<
"===" << std::string(73,
'-') <<
"===\n" 186 <<
" ... Statistics Collected ...\n" 187 <<
"===" << std::string(73,
'-') <<
"===\n\n";
190 for (
size_t i = 0,
e = Stats.Stats.size(); i !=
e; ++i)
191 OS <<
format(
"%*u %-*s - %s\n",
192 MaxValLen, Stats.Stats[i]->getValue(),
193 MaxDebugTypeLen, Stats.Stats[i]->getDebugType(),
194 Stats.Stats[i]->getDesc());
208 const char *delim =
"";
212 "Statistic group/type name is simple.");
214 "Statistic name is simple");
227 #if LLVM_ENABLE_STATS 232 if (Stats.Stats.empty())
return;
248 (*OutStream) <<
"Statistics are disabled. " 249 <<
"Build with asserts or with -DLLVM_ENABLE_STATS\n";
256 std::vector<std::pair<StringRef, unsigned>> ReturnStats;
258 for (
const auto &Stat : StatInfo->statistics())
259 ReturnStats.emplace_back(Stat->getName(), Stat->getValue());
const_iterator end(StringRef path)
Get end iterator over path.
void EnableStatistics(bool PrintOnExit=true)
Enable the collection and printing of statistics.
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
This class represents lattice values for constants.
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
SmartMutex - A mutex with a compile time constant parameter that indicates whether this mutex should ...
void ResetStatistics()
Reset the statistics.
friend const_iterator begin(StringRef path, Style style)
Get begin iterator over path.
const char * getName() const
const char * getDesc() const
static ManagedStatic< StatisticInfo > StatInfo
std::unique_ptr< raw_fd_ostream > CreateInfoOutputFile()
Return a file stream to print our output on.
friend const_iterator end(StringRef path)
Get end iterator over path.
const std::vector< std::pair< StringRef, unsigned > > GetStatistics()
Get the statistics.
void sort(IteratorTy Start, IteratorTy End)
void PrintStatisticsJSON(raw_ostream &OS)
Print statistics in JSON format.
auto size(R &&Range, typename std::enable_if< std::is_same< typename std::iterator_traits< decltype(Range.begin())>::iterator_category, std::random_access_iterator_tag >::value, void >::type *=nullptr) -> decltype(std::distance(Range.begin(), Range.end()))
Get the size of a range.
Align max(MaybeAlign Lhs, Align Rhs)
std::string utostr(uint64_t X, bool isNeg=false)
A range adaptor for a pair of iterators.
unsigned getValue() const
std::lock_guard< SmartMutex< mt_only > > SmartScopedLock
static const char * printAllJSONValues(raw_ostream &OS, const char *delim)
Prints all timers as JSON key/value pairs.
const char * getDebugType() const
void RegisterStatistic()
RegisterStatistic - The first time a statistic is bumped, this method is called.
void PrintStatistics()
Print statistics to the file returned by CreateInfoOutputFile().
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void stable_sort(R &&Range)
static void ConstructTimerLists()
Ensure global timer group lists are initialized.
This class implements an extremely fast bulk output stream that can only output to a stream...
static cl::opt< bool > Stats("stats", cl::desc("Enable statistics output from program (available with Asserts)"), cl::Hidden)
-stats - Command line option to cause transformations to emit stats about what they did...
ManagedStatic - This transparently changes the behavior of global statics to be lazily constructed on...
static ManagedStatic< sys::SmartMutex< true > > StatLock
bool AreStatisticsEnabled()
Check if statistics are enabled.
static cl::opt< bool > StatsAsJSON("stats-json", cl::desc("Display statistics as json data"), cl::Hidden)