如何在 Xcode 中启用构建时间?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1027923/
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-14 18:37:43  来源:igfitidea点击:

How to enable build timing in Xcode?

xcodebuildtiming

提问by Guillaume

I'd like to know how long my project's builds take, for example by displaying it in the build pane. Is this option available somewhere in Xcode?

我想知道我的项目的构建需要多长时间,例如通过在构建窗格中显示它。这个选项在 Xcode 的某个地方可用吗?

Thanks.

谢谢。

回答by Guillaume

Type this in the terminal:

在终端中输入:

defaults write com.apple.dt.Xcode ShowBuildOperationDuration YES

Duration appears in the activity viewer after a build, alongside the "Succeeded" message.

构建后,活动查看器中会显示持续时间,旁边显示“成功”消息。

If you are running the app, the status will be replaced by the running status before you can see the duration.

如果您正在运行该应用程序,则在您看到持续时间之前,状态将被运行状态替换。

This replaces the entry that was used in older versions of Xcode:

这替换了旧版本 Xcode 中使用的条目:

defaults write com.apple.Xcode ShowBuildOperationDuration YES

默认写 com.apple.Xcode ShowBuildOperationDuration 是

Xcode may need to be closed before you enter this command. Durations should appear at the bottom left of the project window.

在输入此命令之前,可能需要关闭 Xcode。持续时间应显示在项目窗口的左下角。

Comment from an Xcode developer: "As with all undocumented user defaults, this is unsupported, assumed (but not guaranteed) accurate, and not assured to be effective in future versions."

来自 Xcode 开发人员的评论:“与所有未记录的用户默认值一样,这是不受支持的,假设(但不能保证)准确,并且不能保证在未来版本中有效。”

回答by Nikolai Ruhe

no, but you could use the command line. cd to your project directory and type

不,但您可以使用命令行。cd 到您的项目目录并键入

time xcodebuild

回答by Andrew

In Xcode 10, you are now able to see a great breakdown of the build times using their Timing Summary feature.

在 Xcode 10 中,您现在可以使用它们的时序摘要功能查看构建时间的详细细分。

Product->Perform Action->Build With Timing Summary

Product->Perform Action->Build with Timing Summary

This will show each of your target build times and the overall project build time. You can do a lot of analysis using this data and build times will depend on your hardware. Check out Building Faster in Xcodefrom WWDC 2018 if you care to learn more.

这将显示您的每个目标构建时间和整个项目构建时间。您可以使用这些数据进行大量分析,构建时间将取决于您的硬件。如果您想了解更多信息,请查看WWDC 2018 的在 Xcode 中构建更快

However, Xcode keeps track of all your builds by default and you can examine their times and logs by going to their Report Navigator.

但是,Xcode 默认会跟踪您的所有构建,您可以通过转到它们的 Report Navigator 检查它们的时间和日志。

Build Logs within Report Navigator

在报告导航器中构建日志

回答by adsurbum

I solved it with Run Scripts in Build Phases

我用Run Scripts in解决了Build Phases

I have added one Run Script at start point of the build:

我在构建的起点添加了一个运行脚本:

echo $(date +%s) > ../build_start_time

echo $(date +%s) > ../build_start_time

and one at the end:

最后一个:

START=$(cat ../build_start_time)
END=$(date +%s)
echo $(echo "$END - $START" | bc)

Now i can see the time in Build Log -> All Messages

现在我可以在 Build Log -> All Messages 中看到时间