https://www.jianshu.com/p/82eb8fae3b9d

There are several profiling tools useful for analyzing Unity UI’s performance. The key tools are:

The external tools provide method-level CPU profiling with millisecond (or better) resolution, as well as detailed draw-call and shader profiling. Instructions for setting up and using the above tools lie beyond the scope of this guide. Note that the XCode Frame Debugger and Instruments are only usable on IL2CPP builds for Apple platforms, and therefore can currently only be used to profile iOS builds.

外部工具提供具有毫秒(或更高)分辨率的方法级CPU评测,以及详细的draw调用和着色器评测。设置和使用上述工具的说明不在本指南的范围内。请注意,XCode Frame调试器和工具只能用于苹果平台的IL2CPP版本,因此当前只能用于分析iOS版本。

Unity Profiler

The primary use for the Unity Profiler is to perform comparative profiling: enabling and disabling elements of a UI while the Unity Profiler is running can quickly narrow down the portions of a UI hierarchy that are most responsible for performance issues.

Unity Profiler的主要用途是执行比较分析:在Unity Profiler运行时启用和禁用UI元素可以快速缩小UI层次结构中对性能问题最负责的部分。

To analyze this, watch the Canvas.BuildBatch and Canvas.SendWillRenderCanvases lines in the profiler’s output.

Canvas.BuildBatch is the native-code calculations that perform the Canvas Batch Building process, as described previously.

如前所述,Canvas.BuildBatch是执行rebatch过程的本地代码计算。

Canvas.SendWillRenderCanvases contains the invocation of the C# scripts that are subscribed to the Canvas component’s willRenderCanvases Event. Unity UI’s CanvasUpdateRegistry class receives this event and uses it to run the Rebuild process, described previously. It is expected that any dirty UI components will update their Canvas Renderers at this time.

Canvas.SendWillRenderCanvases 包含对订阅到Canvas组件的willRenderCanvases事件的C脚本的调用。Unity UI的CanvasUpdateRegistry类接收此事件,并使用它运行前面描述的重建过程。预计任何脏UI组件都会在此时更新其画布呈现器。

Note: To more easily see differences in UI performance, it is generally advisable to disable all of the trace categories aside from “Rendering”, “Scripts” and “UI”. This can be done by clicking on the colored boxes beside the name of the trace category on the left-hand side of the CPU Usage profiler. The categories can also be re-ordered in the CPU profiler by clicking and dragging the names of the categories upwards or downwards.

注意:为了更容易地看到UI性能的差异,通常建议禁用除“Rendering”、“Scripts”和“UI”之外的所有跟踪类别。这可以通过单击CPU使用情况探查器左侧跟踪类别名称旁边的彩色框来完成。类别也可以在CPU事件探查器中重新排序,方法是单击类别名称并向上或向下拖动。

The UI category is new in Unity 2017.1 and up. Unfortunately, parts of the UI update process are not categorized correctly, so be careful when looking at the UI curve because it may not contain all UI related calls. For example, Canvas.SendWillRenderCanvases is categorized as "UI", but Canvas.BuildBatch is categorized as “Others” and “Rendering”.

UI类别在Unity 2017.1及更高版本中是新的。不幸的是,UI更新过程的某些部分没有正确分类,所以在查看UI曲线时要小心,因为它可能不包含所有与UI相关的调用。例如,Canvas.SendWillRenderCanvases文件被归类为“UI”,但是Canvas.BuildBatch分为“Others”和“Rendering”。

In 2017.1 and up, there’s also a new UI Profiler. By default, this profiler is the last one in the Profiler window. It consists of two timelines and a batch viewer:

The first timeline shows the CPU time spent in two categories, respectively computing layout and rendering. Note that it suffers from the same problem described previously and some UI functions may not be accounted for.

第一个时间线显示了两类CPU时间,分别是计算布局和渲染。请注意,它与前面描述的问题相同,并且可能没有考虑某些UI函数。