15
15
16
16
#include " llvm/ADT/SmallString.h"
17
17
#include " llvm/ADT/Statistic.h"
18
- #include " swift/AST/Identifier.h"
19
- #include " swift/Basic/SourceLoc.h"
18
+ #include " swift/Basic/LLVM.h"
20
19
#include " swift/Basic/Timer.h"
21
20
22
21
#define SWIFT_FUNC_STAT \
@@ -60,6 +59,7 @@ class ProtocolConformance;
60
59
class Expr ;
61
60
class SILFunction ;
62
61
class FrontendStatsTracer ;
62
+ class SourceManager ;
63
63
64
64
class UnifiedStatsReporter {
65
65
@@ -110,30 +110,48 @@ class UnifiedStatsReporter {
110
110
// active at all. Reduces redundant machinery.
111
111
class RecursionSafeTimers ;
112
112
113
+ // We also keep a few banks of optional hierarchical profilers for times and
114
+ // statistics, activated with -profile-stats-events and
115
+ // -profile-stats-entities, which are part way between the detail level of the
116
+ // aggregate statistic JSON files and the fine-grained CSV traces. Naturally
117
+ // these are written in yet a different file format: the input format for
118
+ // flamegraphs.
119
+ struct StatsProfilers ;
120
+
113
121
private:
114
122
bool currentProcessExitStatusSet;
115
123
int currentProcessExitStatus;
116
124
SmallString<128 > StatsFilename;
117
125
SmallString<128 > TraceFilename;
126
+ SmallString<128 > ProfileDirname;
118
127
llvm::TimeRecord StartedTime;
128
+
129
+ // This is unique_ptr because NamedRegionTimer is non-copy-constructable.
119
130
std::unique_ptr<llvm::NamedRegionTimer> Timer;
131
+
120
132
SourceManager *SourceMgr;
121
133
clang::SourceManager *ClangSourceMgr;
122
- std::unique_ptr<AlwaysOnDriverCounters> DriverCounters;
123
- std::unique_ptr<AlwaysOnFrontendCounters> FrontendCounters;
124
- std::unique_ptr<AlwaysOnFrontendCounters> LastTracedFrontendCounters;
125
- std::vector<FrontendStatsEvent> FrontendStatsEvents;
134
+ Optional<AlwaysOnDriverCounters> DriverCounters;
135
+ Optional<AlwaysOnFrontendCounters> FrontendCounters;
136
+ Optional<AlwaysOnFrontendCounters> LastTracedFrontendCounters;
137
+ Optional<std::vector<FrontendStatsEvent>> FrontendStatsEvents;
138
+
139
+ // These are unique_ptr so we can use incomplete types here.
126
140
std::unique_ptr<RecursionSafeTimers> RecursiveTimers;
141
+ std::unique_ptr<StatsProfilers> EventProfilers;
142
+ std::unique_ptr<StatsProfilers> EntityProfilers;
127
143
128
144
void publishAlwaysOnStatsToLLVM ();
129
- void printAlwaysOnStatsAndTimers (llvm:: raw_ostream &OS);
145
+ void printAlwaysOnStatsAndTimers (raw_ostream &OS);
130
146
131
147
UnifiedStatsReporter (StringRef ProgramName,
132
148
StringRef AuxName,
133
149
StringRef Directory,
134
150
SourceManager *SM,
135
151
clang::SourceManager *CSM,
136
- bool TraceEvents);
152
+ bool TraceEvents,
153
+ bool ProfileEvents,
154
+ bool ProfileEntities);
137
155
public:
138
156
UnifiedStatsReporter (StringRef ProgramName,
139
157
StringRef ModuleName,
@@ -144,7 +162,9 @@ class UnifiedStatsReporter {
144
162
StringRef Directory,
145
163
SourceManager *SM=nullptr ,
146
164
clang::SourceManager *CSM=nullptr ,
147
- bool TraceEvents=false );
165
+ bool TraceEvents=false ,
166
+ bool ProfileEvents=false ,
167
+ bool ProfileEntities=false );
148
168
~UnifiedStatsReporter ();
149
169
150
170
AlwaysOnDriverCounters &getDriverCounters ();
0 commit comments