12#include "llvm/ADT/STLExtras.h"
13#include "llvm/ADT/StringExtras.h"
14#include "llvm/ADT/StringRef.h"
15#include "llvm/Support/FileSystem.h"
16#include "llvm/Support/ManagedStatic.h"
17#include "llvm/Support/raw_ostream.h"
25 std::vector<BoolEPStat *> BoolStats;
26 std::vector<CounterEPStat *> CounterStats;
27 std::vector<UnsignedMaxEPStat *> UnsignedMaxStats;
28 std::vector<UnsignedEPStat *> UnsignedStats;
30 bool IsLocked =
false;
33 const Decl *EntryPoint;
34 std::vector<bool> BoolStatValues;
35 std::vector<unsigned> UnsignedStatValues;
37 void dumpAsCSV(llvm::raw_ostream &OS)
const;
40 std::vector<Snapshot> Snapshots;
47template <
typename Callback>
void enumerateStatVectors(
const Callback &Fn) {
59 constexpr std::array AllowedSpecialChars = {
60 '+',
'-',
'_',
'=',
':',
'(',
')',
'@',
'!',
'~',
61 '$',
'%',
'^',
'&',
'*',
'\'',
';',
'<',
'>',
'/'};
62 for (
unsigned char C : M->
name()) {
63 if (!std::isalnum(
C) && !llvm::is_contained(AllowedSpecialChars,
C)) {
64 llvm::errs() <<
"Stat name \"" << M->
name() <<
"\" contains character '"
65 <<
C <<
"' (" <<
static_cast<int>(
C)
66 <<
") that is not allowed.";
67 assert(
false &&
"The Stat name contains unallowed character");
74 return L->
name() < R->name();
77 [CmpByNames](
auto &Stats) { llvm::sort(Stats, CmpByNames); });
79 [](
const auto &Stats) { llvm::for_each(Stats,
checkStatName); });
83[[maybe_unused]]
static bool isRegistered(llvm::StringLiteral Name) {
84 auto ByName = [Name](
const EntryPointStat *M) {
return M->name() == Name; };
86 enumerateStatVectors([ByName, &
Result](
const auto &Stats) {
119 std::vector<unsigned>
Result;
124 Result.push_back(M->value());
128 Result.push_back(M->value());
132 Result.push_back(M->value());
139 std::vector<llvm::StringLiteral> Ret;
141 enumerateStatVectors([GetName, &Ret](
const auto &Stats) {
142 transform(Stats, std::back_inserter(Ret), GetName);
147void Registry::Snapshot::dumpAsCSV(llvm::raw_ostream &
OS)
const {
149 llvm::printEscapedString(
152 auto PrintAsBool = [&
OS](
bool B) {
OS << (B ?
"true" :
"false"); };
153 llvm::interleaveComma(BoolStatValues,
OS, PrintAsBool);
154 OS << ((BoolStatValues.empty() || UnsignedStatValues.empty()) ?
"" :
", ");
155 llvm::interleaveComma(UnsignedStatValues,
OS);
162 Result.push_back(M->value());
172 {EntryPoint, std::move(BoolValues), std::move(UnsignedValues)});
177 llvm::raw_fd_ostream
File(
FileName, EC, llvm::sys::fs::OF_Text);
184 OS <<
"EntryPoint, ";
188 std::vector<std::string> Rows;
192 llvm::raw_string_ostream RowOs(Row);
193 Snapshot.dumpAsCSV(RowOs);
195 Rows.push_back(RowOs.str());
198 for (
const auto &Row : Rows) {
This file defines AnalysisDeclContext, a class that manages the analysis context data for context sen...
static void checkStatName(const EntryPointStat *M)
static std::vector< unsigned > consumeUnsignedStats()
static llvm::ManagedStatic< Registry > StatsRegistry
static std::vector< llvm::StringLiteral > getStatNames()
static bool isRegistered(llvm::StringLiteral Name)
static std::vector< bool > consumeBoolStats()
static std::string getFunctionName(const Decl *D)
Decl - This represents one declaration (or definition), e.g.
BoolEPStat(llvm::StringLiteral Name)
CounterEPStat(llvm::StringLiteral Name)
static void dumpStatsAsCSV(llvm::raw_ostream &OS)
static void lockRegistry()
static void takeSnapshot(const Decl *EntryPoint)
llvm::StringLiteral name() const
UnsignedEPStat(llvm::StringLiteral Name)
UnsignedMaxEPStat(llvm::StringLiteral Name)
@ OS
Indicates that the tracking object is a descendant of a referenced-counted OSObject,...
The JSON file list parser is used to communicate input to InstallAPI.
@ Result
The result type of a method or function.