Skip to content

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

Merged
merged 11 commits into from
Feb 22, 2018
Merged

Profile stats #14703

merged 11 commits into from
Feb 22, 2018

Conversation

graydon
Copy link
Contributor

@graydon graydon commented Feb 18, 2018

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.

@graydon
Copy link
Contributor Author

graydon commented Feb 18, 2018

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 59a83270923a85e4fa36811a85995ff8c59362ee

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 59a83270923a85e4fa36811a85995ff8c59362ee

@davidungar
Copy link
Contributor

davidungar commented Feb 18, 2018 via email

@graydon
Copy link
Contributor Author

graydon commented Feb 19, 2018

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 59a83270923a85e4fa36811a85995ff8c59362ee

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 59a83270923a85e4fa36811a85995ff8c59362ee

@graydon graydon requested a review from jrose-apple February 20, 2018 18:13
Copy link
Contributor

@jrose-apple jrose-apple left a 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.

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the extra indirection?

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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.

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); \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stray \ here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whoops! fixing

@graydon
Copy link
Contributor Author

graydon commented Feb 20, 2018

@jrose-apple Pushed requested changes (removed a bunch of macros too) and added test.

@graydon
Copy link
Contributor Author

graydon commented Feb 20, 2018

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - c054edea2b62be6058ec3c15a9ff7cc04e7cc239

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - c054edea2b62be6058ec3c15a9ff7cc04e7cc239

@jrose-apple
Copy link
Contributor

Note that I left other comments on the other PR.

@graydon
Copy link
Contributor Author

graydon commented Feb 20, 2018

Oops, missed them, sorry; fixing now.

@graydon
Copy link
Contributor Author

graydon commented Feb 21, 2018

@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).

@graydon
Copy link
Contributor Author

graydon commented Feb 21, 2018

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 9d7b887d521b8452175c49162951e99593f7319f

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 9d7b887d521b8452175c49162951e99593f7319f

llvm::Optional<AlwaysOnDriverCounters> DriverCounters;
llvm::Optional<AlwaysOnFrontendCounters> FrontendCounters;
llvm::Optional<AlwaysOnFrontendCounters> LastTracedFrontendCounters;
llvm::Optional<std::vector<FrontendStatsEvent>> FrontendStatsEvents;
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I never knew! Nice.

NowUS, LiveUS, IsEntry, T.EventName, name, \
delta, total, T.Entity, T.Formatter}); \
} \
#define FRONTEND_STATISTIC(TY, NAME) \
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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!

@graydon
Copy link
Contributor Author

graydon commented Feb 22, 2018

@swift-ci please test and merge

1 similar comment
@graydon
Copy link
Contributor Author

graydon commented Feb 22, 2018

@swift-ci please test and merge

@swift-ci swift-ci merged commit 786cfc5 into swiftlang:master Feb 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants