-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Profile stats #14703
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Profile stats #14703
Conversation
7fb7384
to
59a8327
Compare
@swift-ci please test |
Build failed |
Build failed |
59a8327
to
c054ede
Compare
@swift-ci please test |
Build failed |
Build failed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see anything that looks unreasonable here, although I'm not super happy with all the macros.
include/swift/Basic/Statistic.h
Outdated
llvm::TimeRecord StartedTime; | ||
std::unique_ptr<llvm::NamedRegionTimer> Timer; | ||
SourceManager *SourceMgr; | ||
clang::SourceManager *ClangSourceMgr; | ||
std::unique_ptr<AlwaysOnDriverCounters> DriverCounters; | ||
std::unique_ptr<AlwaysOnFrontendCounters> FrontendCounters; | ||
std::unique_ptr<AlwaysOnFrontendCounters> LastTracedFrontendCounters; | ||
std::vector<FrontendStatsEvent> FrontendStatsEvents; | ||
std::unique_ptr<std::vector<FrontendStatsEvent>> FrontendStatsEvents; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the extra indirection?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Congruent with the other machinery where we test if it's active based on the presence/absence of the supporting data structure (i.e. nullptr == disabled); this PR changes the test for tracing (vs. profiling which also uses the LastTracedFrontendCounters) from testing LastTracedFrontendCounters to testing FrontendStatsEvents, so the latter moves to a thing-that-can-be-nullptr. I suppose I could also split enabled/disabled signalling into a set of boolean flags if you prefer. That would make it a bit more obvious.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with an explicit test rather than relying on an empty state, but is there a reason to use unique_ptr
over Optional
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, just muscle memory from the days before a reliable C++ Optional in my codebase.
Optional is good! I'll switch 'em over.
lib/Basic/Statistic.cpp
Outdated
SmallString<256> Path(Dirname); | ||
llvm::sys::path::append(Path, Filename); | ||
std::error_code EC; | ||
raw_fd_ostream Stream(Path, EC, fs::F_Append | fs::F_Text); \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stray \
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whoops! fixing
c054ede
to
9d7b887
Compare
@jrose-apple Pushed requested changes (removed a bunch of macros too) and added test. |
@swift-ci please test |
Build failed |
Build failed |
Note that I left other comments on the other PR. |
Oops, missed them, sorry; fixing now. |
9d7b887
to
35c4942
Compare
@jrose-apple pushed update with fixes to both this branch and the prefix (and closing out that PR since you seem roughly ok with this extension). |
@swift-ci please test |
Build failed |
Build failed |
include/swift/Basic/Statistic.h
Outdated
llvm::Optional<AlwaysOnDriverCounters> DriverCounters; | ||
llvm::Optional<AlwaysOnFrontendCounters> FrontendCounters; | ||
llvm::Optional<AlwaysOnFrontendCounters> LastTracedFrontendCounters; | ||
llvm::Optional<std::vector<FrontendStatsEvent>> FrontendStatsEvents; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: No need for the llvm::
prefix if you import swift/Basic/LLVM.h
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I never knew! Nice.
lib/Basic/Statistic.cpp
Outdated
NowUS, LiveUS, IsEntry, T.EventName, name, \ | ||
delta, total, T.Entity, T.Formatter}); \ | ||
} \ | ||
#define FRONTEND_STATISTIC(TY, NAME) \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was actually the macro that scared me most, but I guess it's hard to factor out.
#define FRONTEND_STATISTIC(TY, NAME) \
handleStatistic(#TY "." #NAME, C.NAME, LastTracedFrontendCounters->NAME, EventProfilers->NAME, EntityProfilers->NAME);
…well, maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mm, fair. Lemme see what I can do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, this cleaned up nicely. Thanks!
35c4942
to
757aba6
Compare
757aba6
to
9d34041
Compare
@swift-ci please test and merge |
1 similar comment
@swift-ci please test and merge |
Followup to #14695 with a single additional feature, commit ea2e87f, that adds a couple banks of hierarchical profilers to the -stats-output-dir / -trace-stats-events machinery. The user need only pass -profile-stats-events or -profile-stats-entities (along with -stats-output-dir) to get the full feature, so it's still quite easy to explain, capture, transport, etc.
The additional output is a subdirectory full of plain-text hierarchical profiles in the input format to flamegraph.pl, each of which shows time or event-counts arranged into pseudo-stacks formed by the entry/exit events of the FrontendStatsTracer objects, optionally subdivided by source entity (though that makes the profile quite a bit more fine-grained -- it also removes the mystery of which call to "typecheck-decl" is which!).
Here's a (github-sanitized, script-disabled so only half-useful, but you can still get tooltips) version showing the Sema.NumGenericSignatureBuilders counter broken down by source entity in a single file from the Plank project, as an example:

I'll push a few more tests next week, just wanted to get this posted for any early feedback.