Measuring Detailed Compile Times for Research

I'm doing some research and I'd like to get a more in-depth look at the different stages of compilation to get a better picture of how compilation performance is affected and by what changes. However, I haven't been able to find a simple way to get separate information regarding the build times of the driver creating different jobs, compiling different source files (parsing, performing semantic analysis, generating SIL, etc.), and linking. I can condense my project into one file, so it'd be great if I could just see the time it takes for different stages of compilation and linking to produce the resulting executable.

I tried some flags I found in this old thread and this newer one, but the output is too detailed. For reference, I ran the following in a swift-package directory:

swift build -c=debug -Xswiftc -driver-show-incremental 
                     -Xswiftc -driver-show-job-lifecycle 
                     -Xswiftc -debug-time-function-bodies 
                     -Xswiftc -parseable-output 
                     -Xswiftc -output-file-map=./FileMap.json 
                     -Xswiftc builtin-Swift-Compilation

The result outlined the times it took to analyze or create code for (?) different declarations, which isn't exactly the stage-specific file-level overview I was looking for.

I also found article about getting build time analysis but it's for Xcode. I try to stay away from proprietary software from my research since Apple may be changing things behind the scenes (e.g. the recent build-time improvements) and we may not know that. Also, the recommended Build with Timing Summary doesn't really like that I have a custom toolchain (because the toolchain has different versions of library SDKs) which causes the build to fail.

So is there a (relatively) easy way to get more fine-grained output of compilation stages for a single file without involving Xcode?

Sorry, can’t think of anything offhand. I’m not on the project anymore and have become just another user of Swift. Since the compiler is open-source, I suggest you look at the source code, and also IIRC there’s a file in the doc directory that discusses compilation time.

It will be fascinating to see what you learn!

Good luck,

  • David

I see, thanks for the help! I’ll probably post my results somewhere on the forum.