xcode swift 文件的输出编译持续时间

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31520133/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 07:31:20  来源:igfitidea点击:

Output compile durations for swift files

swiftxcodecompiler-optimizationcompilation-time

提问by system

Is there a way to turn output the time taken to compile a swift file during an xcode build?

有没有办法在 xcode 构建期间将输出转换为编译 swift 文件所需的时间?

I would like to compile from the command line to trigger the same build xcode does but to include the time taken to compile each file.

我想从命令行编译以触发与 xcode 相同的构建,但要包括编译每个文件所需的时间。

The Report Navigatorshow full build reports per file but there is no timeframe associated with them.

Report Navigator节目全力打造每个文件的报告,但没有与它们相关的时间表。

Its not clear on compile times by looking and the loading state etc. as its more guestimate style.

通过查看和加载状态等,它在编译时间上并不清楚,因为它更具有推测性。

I would like to cut down the compile time of a Swift 1.2 project, as it takes around 5 - 10 minutes after a clean or 3 -5 minutes after changing source in a heavily dependent file.

我想缩短 Swift 1.2 项目的编译时间,因为它在清理后大约需要 5 - 10 分钟,或者在一个高度依赖的文件中更改源代码后需要 3 -5 分钟。

回答by zrzka

You can add…

你可以加…

-Xfrontend -debug-time-function-bodies

…to Other Swift Flags in Swift Compiler - Custom Flagssection (build settings).

...到Swift Compiler 中的其他 Swift 标志 - 自定义标志部分(构建设置)。

Build settings

构建设置

Note: You have to keep same order of these flags. -Xfrontendsays that the next flag should be passed to the frontend. It will not work if you reverse the order.

注意:您必须保持这些标志的相同顺序。-Xfrontend说下一个标志应该传递给前端。如果您颠倒顺序,它将不起作用。

Then you can get compile times in your build log:

然后你可以在你的构建日志中获得编译时间:

Build log

构建日志

Which is useful when you do want to optimize compile time and also it's good to attach this kind of build log when reporting an issue to Apple Swift guysabout slow compile time.

这在您确实想要优化编译时间时很有用,并且在向Apple Swift 人员报告有关编译时间缓慢的问题时附加这种构建日志也很有用。

Credit goes to Joe PamerErrant compiler hacker. Currently an engineering manager at Apple (Swift, Clang), formerly at Microsoft (TypeScript, F#, JavaScript, .NET).He tweeted it as a response to Rob Rix question about profiling Swift compilation. It made me curious, so, I disassembled compiler, checked text section for more flags and found other hidden options. Don't use them in production code, just play with them.

幸得乔Pamer对不按编译器的黑客。目前在 Apple(Swift、Clang)担任工程经理,之前在 Microsoft(TypeScript、F#、JavaScript、.NET)工作。他在推特上回应了 Rob Rix 关于分析 Swift 编译的问题。这让我很好奇,所以,我反汇编了编译器,检查了文本部分以获取更多标志并找到其他隐藏选项。不要在生产代码中使用它们,只需使用它们即可。



Build time of the whole project. Run following command in terminal…

整个项目的构建时间。在终端中运行以下命令...

defaults write com.apple.dt.Xcode ShowBuildOperationDuration YES

…restart Xcode, clean & build and…

...重新启动 Xcode,清理并构建并...

Build time

构建时间



What if I have pods?

如果我有豆荚怎么办?

Do same as above for your podsproject

对您的pods项目执行与上述相同的操作