Skip to content

Commit 628c446

Browse files
committed
[Stats] Add -profile-stats-{events,entities}
1 parent 7fe97c7 commit 628c446

File tree

7 files changed

+318
-36
lines changed

7 files changed

+318
-36
lines changed

include/swift/Basic/Statistic.h

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515

1616
#include "llvm/ADT/SmallString.h"
1717
#include "llvm/ADT/Statistic.h"
18-
#include "swift/AST/Identifier.h"
19-
#include "swift/Basic/SourceLoc.h"
18+
#include "swift/Basic/LLVM.h"
2019
#include "swift/Basic/Timer.h"
2120

2221
#define SWIFT_FUNC_STAT \
@@ -60,6 +59,7 @@ class ProtocolConformance;
6059
class Expr;
6160
class SILFunction;
6261
class FrontendStatsTracer;
62+
class SourceManager;
6363

6464
class UnifiedStatsReporter {
6565

@@ -110,30 +110,48 @@ class UnifiedStatsReporter {
110110
// active at all. Reduces redundant machinery.
111111
class RecursionSafeTimers;
112112

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+
113121
private:
114122
bool currentProcessExitStatusSet;
115123
int currentProcessExitStatus;
116124
SmallString<128> StatsFilename;
117125
SmallString<128> TraceFilename;
126+
SmallString<128> ProfileDirname;
118127
llvm::TimeRecord StartedTime;
128+
129+
// This is unique_ptr because NamedRegionTimer is non-copy-constructable.
119130
std::unique_ptr<llvm::NamedRegionTimer> Timer;
131+
120132
SourceManager *SourceMgr;
121133
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.
126140
std::unique_ptr<RecursionSafeTimers> RecursiveTimers;
141+
std::unique_ptr<StatsProfilers> EventProfilers;
142+
std::unique_ptr<StatsProfilers> EntityProfilers;
127143

128144
void publishAlwaysOnStatsToLLVM();
129-
void printAlwaysOnStatsAndTimers(llvm::raw_ostream &OS);
145+
void printAlwaysOnStatsAndTimers(raw_ostream &OS);
130146

131147
UnifiedStatsReporter(StringRef ProgramName,
132148
StringRef AuxName,
133149
StringRef Directory,
134150
SourceManager *SM,
135151
clang::SourceManager *CSM,
136-
bool TraceEvents);
152+
bool TraceEvents,
153+
bool ProfileEvents,
154+
bool ProfileEntities);
137155
public:
138156
UnifiedStatsReporter(StringRef ProgramName,
139157
StringRef ModuleName,
@@ -144,7 +162,9 @@ class UnifiedStatsReporter {
144162
StringRef Directory,
145163
SourceManager *SM=nullptr,
146164
clang::SourceManager *CSM=nullptr,
147-
bool TraceEvents=false);
165+
bool TraceEvents=false,
166+
bool ProfileEvents=false,
167+
bool ProfileEntities=false);
148168
~UnifiedStatsReporter();
149169

150170
AlwaysOnDriverCounters &getDriverCounters();

include/swift/Frontend/FrontendOptions.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,13 @@ class FrontendOptions {
164164
/// Trace changes to stats to files in StatsOutputDir.
165165
bool TraceStats = false;
166166

167+
/// Profile changes to stats to files in StatsOutputDir.
168+
bool ProfileEvents = false;
169+
170+
/// Profile changes to stats to files in StatsOutputDir, grouped by source
171+
/// entity.
172+
bool ProfileEntities = false;
173+
167174
/// If true, serialization encodes an extra lookup table for use in module-
168175
/// merging when emitting partial modules (the per-file modules in a non-WMO
169176
/// build).

include/swift/Option/Options.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,12 @@ def stats_output_dir: Separate<["-"], "stats-output-dir">,
202202
def trace_stats_events: Flag<["-"], "trace-stats-events">,
203203
Flags<[FrontendOption, HelpHidden]>,
204204
HelpText<"Trace changes to stats in -stats-output-dir">;
205+
def profile_stats_events: Flag<["-"], "profile-stats-events">,
206+
Flags<[FrontendOption, HelpHidden]>,
207+
HelpText<"Profile changes to stats in -stats-output-dir">;
208+
def profile_stats_entities: Flag<["-"], "profile-stats-entities">,
209+
Flags<[FrontendOption, HelpHidden]>,
210+
HelpText<"Profile changes to stats in -stats-output-dir, subdivided by source entity">;
205211

206212
def emit_dependencies : Flag<["-"], "emit-dependencies">,
207213
Flags<[FrontendOption, NoInteractiveOption, DoesNotAffectIncrementalBuild]>,

0 commit comments

Comments
 (0)