如何通过构建时间获取时间戳_构建时间:获取详细信息

如何通过构建时间获取时间戳_构建时间:获取详细信息

如何通过构建时间获取时间戳

Updated BuildReport API in Unity 2020.1 beta gives more details about the build times of your project, breaking them down to the asset level. This information will help you optimize your iteration times.

Unity 2020.1 beta中更新的BuildReport API提供了有关项目构建时间的更多详细信息,并将其细分为资产级别。 此信息将帮助您优化迭代时间。

Jump to BuildOptions.DetailedBuildReport manual page to check out directly how to use the new API, and drop the Build Report Inspector into your project to inspect your new build reports easily.

跳转至 BuildOptions.DetailedBuildReport手册页 以直接了解如何使用新API,并将 Build Report Inspector 放到项目中以轻松检查新的构建报告。

Build times for projects with lots of content can become quite long. This makes iteration slower, especially when testing on several platforms.

具有大量内容的项目的构建时间可能会变得很长。 这会使迭代变慢,尤其是在多个平台上进行测试时。

Unity 2018.1 introduced the BuildReport API that gives information about the Unity build process. Since then, the BuildReport object returned from BuildPipeline.BuildPlayer has information about the steps happening during the build process, which assets contribute to the build size, and which engine modules are included in the build.

Unity 2018.1引入了 BuildReport API , 该 API 提供有关Unity构建过程的信息。 此后,从 BuildPipeline.BuildPlayer 返回的BuildReport对象 具有关于在生成过程中发生的步骤,其资产向构建尺寸,并且该发动机模块被包含在构建的信息。

In Unity 2020.1, if you pass the new BuildOptions.DetailedBuildReport option to the API function BuildPipeline.BuildPlayer, you will have more information available in the BuildReport object, such as more detailed build steps, and a summary of which scenes are using the assets in the build.

在Unity 2020.1中,如果将新的 BuildOptions.DetailedBuildReport 选项传递给API函数 BuildPipeline.BuildPlayer ,您将在BuildReport对象中获得更多可用信息,例如更详细的构建步骤,以及哪些场景正在使用资产的摘要。构建。

构建报告检查器包 (Build Report Inspector package)

The BuildReport API makes it possible to write custom tools to analyze your project’s build times.

BuildReport API使编写自定义工具来分析项目的构建时间成为可能。

One approach to learning how to use it is by looking at the Build Report Inspector provided by Unity to illustrate its usage.

学习如何使用它的一种方法是查看Unity提供的Build Report Inspector来说明其用法。

Build Report Inspector can be added to a project from the Unity Package Manager window. Check Show Preview Packages in the Advanced menu and look for Build Report Inspector on the list. Finally, click the “Install” button. 

可以从Unity Package Manager窗口中将构建报告检查器添加到项目中。 选中 “ 高级” 菜单 中的“ 显示预览软件包” , 然后 在列表中 查找“ 构建报告检查器 ”。 最后,单击“安装”按钮。

如何通过构建时间获取时间戳_构建时间:获取详细信息

Build Report Inspector in the Package Manager

程序包管理器中的构建报告检查器

You can also get the Build Report Inspector script (including future experimental versions), as well as contribute to improving it, from this GitHub repository.

您还可以从此 GitHub存储库中 获得Build Report Inspector脚本(包括将来的实验版本),并为改进它做出贡献 。

Build Report Inspector adds a command menu Open Last Build Report to the Window menu. Clicking command menu Open Last Build Report copies the build report file generated during the last build under a location visible by the project, and selects it to make its contents visible in the inspector:

Build Report Inspector将命令菜单 Open Last Build Report添加Window 菜单。 单击命令菜单“ 打开上一个构建报告” ,将上次构建期间生成的构建报告文件复制到项目可见的位置,并选择它以使其内容在检查器中可见:

如何通过构建时间获取时间戳_构建时间:获取详细信息

Simple Build Report for an incremental build of project BoatAttack

用于项目BoatAttack增量构建的简单构建报告

BuildReport.steps中的其他详细信息 (Additional details in BuildReport.steps)

When building with the BuildOptions.DetailedBuildReport option, new build steps are listed in BuildReport.steps

使用 BuildOptions.DetailedBuildReport 选项进行构建时,新的构建步骤会在 BuildReport.steps 中列出 。

Build steps shorter than 1ms will not be listed, as this would create a lot of noise. 

小于1ms的构建步骤将不会列出,因为这会产生很多噪音。

Those newly reported steps include:

这些新报告的步骤包括:

  • Assets load and write times for the build

    资产的加载和写入时间

  • GarbageCollection times during the build

    构建期间的垃圾回收时间

  • Time to process asset dependencies

    处理资产依赖关系的时间

  • Custom Asset Bundle build details and times

    自定义资产捆绑包构建详细信息和时间

BuildOptions.DetailedBuildReport manual page has an example of Editor script showing how to use the option. 

BuildOptions.DetailedBuildReport手册页上 有一个编辑器脚本示例,显示了如何使用该选项。

Here is how we can modify that example to build the BoatAttack project with the BuildOptions.DetailedBuildReport flag:

这是我们如何修改该示例以 使用BuildOptions.DetailedBuildReport标志 构建 BoatAttack 项目的方法:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
using UnityEditor;
using UnityEngine;
public class DetailedBuildReportExample : MonoBehaviour
{
    [MenuItem("Build/DetailedBuildReport example")]
    public static void MyBuild()
    {
        BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions();
        buildPlayerOptions.scenes = new[] { "Assets/scenes/MainMenu.unity", "Assets/scenes/_levels/level_Island.unity" };
        buildPlayerOptions.locationPathName = "DetailedReportBuild/MyGame.exe";
        buildPlayerOptions.target = BuildTarget.StandaloneWindows64;
        buildPlayerOptions.options = BuildOptions.DetailedBuildReport;
        var buildReport = BuildPipeline.BuildPlayer(buildPlayerOptions);
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
using UnityEditor ;
using UnityEngine ;
public class DetailedBuildReportExample : MonoBehaviour
{
     [ MenuItem ( "Build/DetailedBuildReport example" ) ]
     public static void MyBuild ( )
     {
         BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions ( ) ;
         buildPlayerOptions . scenes = new [ ] { "Assets/scenes/MainMenu.unity" , "Assets/scenes/_levels/level_Island.unity" } ;
         buildPlayerOptions . locationPathName = "DetailedReportBuild/MyGame.exe" ;
         buildPlayerOptions . target = BuildTarget . StandaloneWindows64 ;
         buildPlayerOptions . options = BuildOptions . DetailedBuildReport ;
         var buildReport = BuildPipeline . BuildPlayer ( buildPlayerOptions ) ;
     }
}

If we add the above script to the Boat Attack project’s Assets/Editor folder and click Editor menu Build/DetailedBuildReport example, a project build will begin. At the end of the build, additional data will be included in the Build Report.

如果将上述脚本添加到Boat Attack项目的 Assets / Editor 文件夹中,然后单击“编辑器”菜单 Build / DetailedBuildReport 示例 ,则将开始进行项目构建。 在构建结束时,其他数据将包含在构建报告中。

Now if we use the Window/Open Last Build Report command like described in the previous section, we can see that additional steps have been included in the report:

现在,如果我们使用 上一节中所述的“ 打开窗口/打开上一个生成报告” 命令,我们可以看到报告中包含了其他步骤:

如何通过构建时间获取时间戳_构建时间:获取详细信息

Detailed Build Report for an incremental build of project BoatAttack

项目BoatAttack增量构建的详细构建报告

The additional information makes it possible to pinpoint which steps and which assets take more time when building the project.

附加信息可以在构建项目时查明哪些步骤和哪些资产需要更多时间。

After identifying those assets, you can swap them with lighter “development” versions, for better iteration times.

确定这些资产后,可以将其替换为较轻的“开发”版本,以缩短迭代时间。

使用特定资产查找所有场景 (Find all scenes using a specific asset)

In the process of replacing heavy assets, it might be useful to know exactly which scenes in the build include a given asset.

在替换重资产的过程中,准确了解构建中的哪些场景包含给定资产可能会很有用。

If the BuildOptions.DetailedBuildReport option was used during the build, this information is exposed in the BuildReport as member BuildReport.scenesUsingAssets.

如果 在构建过程中使用 了 BuildOptions.DetailedBuildReport 选项,则此信息作为 BuildReport.scenesUsingAssets 成员在BuildReport中 公开

If you added the Build Report Inspector to your project, you can review this information from the ScenesUsingAssets tab:

如果您将Build Report Inspector添加到项目中,则可以从 ScenesUsingAssets 选项卡中 查看以下信息 :

如何通过构建时间获取时间戳_构建时间:获取详细信息

List of scenes using specific assets in the BoatAttack project

BoatAttack项目中使用特定资产的场景列表

During development, replacing those assets by smaller ones, or creating build profiles without the scenes referencing them, will help in reducing iteration times.

在开发过程中,用较小的资产替换这些资产,或者在没有场景引用它们的情况下创建构建配置文件,将有助于减少迭代时间。

Unity 2020.1 Beta和网络研讨会 (Unity 2020.1 beta and webinar)

Use Detailed Build Reports to discover what is making up your project build times, and use this information to optimize your iteration loops. Try this feature in Unity 2020.1 beta and let us know what you think. On April 20 at 9:00 am PST (6:00 pm CET), we will be hosting a 2020.1 beta webinar for people interested in a guided tour of the features and updates. You can register here for the webinar. If you have any additional questions about this or other features in 2020.1, we will be hosting a Q&A following our 2020.1 beta overview webinar. You can drop your questions in this forum thread.

使用“详细的构建报告”来发现构成项目构建时间的原因,并使用此信息来优化迭代循环。 尝试在 Unity 2020.1 beta中使用 此功能, 并告诉我们您的想法。 美国太平洋标准时间 4月20 日上午9:00( 美国中部 标准时间下午6:00) ,我们将举办2020.1 beta网络研讨会,面向有兴趣的功能和更新导览的人们。 您可以 在此处 注册 网络研讨会。 如果您对2020.1中的此功能或其他功能有任何其他疑问,我们将在2020.1 Beta概述网络研讨会之后主持问答。 您可以在此论坛主题中提问。

翻译自: https://blogs.unity3d.com/2020/04/09/build-times-get-the-details/

如何通过构建时间获取时间戳