-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[SR-1788] Add -driver-time-compilation option #4367
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
[SR-1788] Add -driver-time-compilation option #4367
Conversation
@swift-ci please test |
The Linux failures are occurring when compiling swift-corelibs-foundation, and appear to be unrelated. |
@jrose-apple is really the person to review this, but taking a quick look I have some comments. |
@@ -421,14 +424,26 @@ int Compilation::performJobsImpl() { | |||
} | |||
|
|||
int Result = EXIT_SUCCESS; | |||
llvm::TimerGroup DriverTimerGroup("Driver Time Compilation"); | |||
std::map<std::string, std::unique_ptr<llvm::Timer>> DriverTimers; |
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.
Given how the code is written, couldn't use an RAII type to hide all of this? I am imagining an API like:
// We want to make sure map is not allocating memory here unless we have ShowDriverTimeCompilation actually enabled. So I imagine you want something like SharedTimer has.
SimpleTimerGroup Group;
llvm::SmallString<128> CmdLine;
auto taskBegin = ... {
if (ShowDriverTimeCompilation) {
BeginCmd->printCommandLine(CmdLine);
Group.startTimer(CmdLine)
}
}
...
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 think this is a perfectly good approach, except the map should be from Job *
to timer instead of command-line-string to timer. (At which point I suggest using an llvm::DenseMap
, which is a hash map. See the LLVM Programmer's Manual for more nifty data structures.)
This is looking great. I wonder how it interacts with (That's not something that necessarily makes sense to put in a regression test, but it's worth seeing what the behavior is before we commit. I think it'll be fine because I think I've used |
fbf7638
to
4375b9b
Compare
When using both |
4375b9b
to
642a32f
Compare
Thanks for all the great feedback! I think I addressed everything I can. @swift-ci please test |
DriverTimers.insert({ | ||
BeganCmd, | ||
std::unique_ptr<llvm::Timer>( | ||
new llvm::Timer(CmdLine.str(), DriverTimerGroup)) |
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.
Bonus tip: if you call str()
on the raw_svector_ostream instead of the SmallString, you don't have to force its destructor to be called.
@swift-ci Please test |
@modocache I don't think you actually triggered swift-ci. I pushed the button again. |
642a32f
to
6639184
Compare
Thanks for the follow-ups @jrose-apple. I think I've responded to them all. Now let's see if Swift CI still listens to me... @swift-ci Please test |
Sort of. OS X tests here |
// CHECK: ---Wall Time--- | ||
// CHECK: --- Name --- | ||
// CHECK: driver-time-compilation.swift | ||
// CHECK: {{[0-9]+}}.{{[0-9]+}} (100.0%) Total |
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.
Looks good! I think it's worth having a multi-file test too. You could just add an extra RUN line that uses %S/../Inputs/empty.swift
, a standard empty .swift file, as well as %s
. (Both tests are useful.)
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.
Done! 👍
6639184
to
6afc934
Compare
@swift-ci please test |
Mostly looks good to me! I still feel weird about printing the whole command line, though—those can get pretty long with every input file appearing in the list. |
6afc934
to
1529d6e
Compare
(Rebased onto #4437.) Ah, yeah, I guess for most actual inputs these timer names would be much, much longer. I liked the idea of seeing the exactly which jobs took up what amount of time, but that information is also available by using I'll look into printing a summary of the job instead. Maybe I can reuse some of the logic from |
The following change: diff --git a/lib/Driver/Compilation.cpp b/lib/Driver/Compilation.cpp
index beabfd5..b86706c 100644
--- a/lib/Driver/Compilation.cpp
+++ b/lib/Driver/Compilation.cpp
@@ -436,13 +436,11 @@ int Compilation::performJobsImpl() {
const Job *BeganCmd = (const Job *)Context;
if (ShowDriverTimeCompilation) {
- llvm::SmallString<128> CmdLine;
- llvm::raw_svector_ostream OS(CmdLine);
- BeganCmd->printCommandLine(OS);
+ auto JobName = BeganCmd->getSource().getClassName();
DriverTimers.insert({
BeganCmd,
std::unique_ptr<llvm::Timer>(
- new llvm::Timer(OS.str(), DriverTimerGroup))
+ new llvm::Timer(JobName, DriverTimerGroup))
});
DriverTimers[BeganCmd]->startTimer();
} Results in the following output:
You mention above displaying something like "Compile x.swift". I think I can do that by printing a Job's InputActions when available -- although, if there are a lot of input files, the name may get pretty long. |
Yeah, now that I think about it printing like |
OK, I have something like this at the moment:
Does this look good? I'll update the pull request with this soon. |
Seems reasonable, and we can always tweak it later. Thanks, Brian! |
Add an option to print the time it takes each driver task to complete. Here's an example of the output: ``` $ swiftc -driver-time-compilation \ -emit-library -module-name Crispix \ Crispix/A.swift Crispix/B.swift Crispix/C.swift ===-------------------------------------------------------------------------=== Driver Time Compilation ===-------------------------------------------------------------------------=== Total Execution Time: 0.0000 seconds (0.0875 wall clock) ---Wall Time--- --- Name --- 0.0245 ( 28.0%) link /path/to/Crispix/A.swift /path/to/Crispix/B.swift /path/to/Crispix/C.swift 0.0211 ( 24.1%) compile /path/to/Crispix/A.swift 0.0209 ( 23.9%) compile /path/to/Crispix/B.swift 0.0176 ( 20.1%) compile /path/to/Crispix/C.swift 0.0035 ( 4.0%) swift-autolink-extract /path/to/Crispix/A.swift /path/to/Crispix/B.swift /path/to/Crispix/C.swift 0.0875 (100.0%) Total ```
1529d6e
to
6c92c78
Compare
I'm betting some of the C++ could be nicer, but this now produces the output I described above. @swift-ci please test |
Build failed |
Build failed |
Both failures appear to be in the CI infrastructure, not the contents of the pull request. |
Something weird happened there. Let's just try again. @swift-ci Please test |
Looks like it's all green this time! :) |
Thanks for the new feature, Brian! |
You're quite welcome! I'd love to work on more of lib/Driver. Did you happen to see my email? https://lists.swift.org/pipermail/swift-dev/Week-of-Mon-20160815/002739.html |
What's in this pull request?
Add an option to print the time it takes each driver task to complete.
Here's an example of the output:
I don't write C++ very often, and this is probably one of the larger changes I've made to
lib/Driver
, so I wouldn't be surprised if there's some wacky code in here. 😅 Any and all feedback welcome!/cc @jrose-apple @gottesmm
Resolved bug number: (SR-1788)
Before merging this pull request to apple/swift repository:
Triggering Swift CI
The swift-ci is triggered by writing a comment on this PR addressed to the GitHub user @swift-ci. Different tests will run depending on the specific comment that you use. The currently available comments are:
Smoke Testing
A smoke test on macOS does the following:
device standard libraries are not built.
version of these tests are not run.
A smoke test on Linux does the following:
tests are not run.
Validation Testing
Lint Testing
Note: Only members of the Apple organization can trigger swift-ci.