Unity 分析器(仅专业版) Profiler (Pro only)

龙永福
2023-12-01

The Unity Profiler helps you to optimize your game. It reports for you how much time is spent in the various areas of your game. For example, it can report the percentage of time spent rendering, animating or in your game logic.

Unity分析器可以帮助你优化你的游戏。它为您报告在你的游戏的各个领域所花费的时间。例如,它可以报告渲染、动画或在你的游戏逻辑花费时间的百分比。

You can play your game in the Editor with Profiling on, and it will record performance data. The Profiler window then displays the data in a timeline, so you can see the frames or areas that spike (take more time) than others. By clicking anywhere in the timeline, the bottom section of the Profiler window will display detailed information for the selected frame.

在编辑器中,你可以将你的游戏在分析器运行着的状态下运行,它会记录性能数据。 分析器窗口,在时间轴上显示数据,所以你可以看到帧或区域峰值(比其他需要更多的时间)。在时间轴中的任何地方按一下,分析器窗口的底部区域会显示选定的帧的详细信息。

Note that profiling has to instrument your code. This instrumentation has a small impact on the performance of your game. Typically this overhead is small enough to not affect the game framerate. When using profiling it is typical to consider only the ratio (or percentage) of time spent in certain areas. Also, to improve performance focus on those parts of the game that consume the most time. Compare profiling results before and after code changes and determine the improvements you measure. Sometimes changes you make to improve performance might have a negative effect on frame rate; unexpected consequences of code optimization should be expected.

请注意,分析时必须检测你的代码。这检测会对你的游戏性能有小小影响。通常情况下,这种开销是足够小,不会影响游戏的帧率。当使用分析时,它是典型的考虑时间花费在某些领域的比例(或百分比)。此外,为了提高性能,重点在游戏消耗的时间最多的那些部分。代码更改前后比较分析结果,并确定您测量的改进。有时,您所做的更改来提高性能,可能对帧速率有负面影响;应预计代码优化的意外的后果。

See Also 参见

iOS

Remote profiling can be enabled on iOS devices by following these steps:

iOS设备上启用远程分析可以通过以下步骤:

  1. Connect your iOS device to your WiFi network (local/adhoc WiFi network is used by profiler to send profiling data from device to the Unity Editor). 
    您的iOS设备连接到WiFi网络(分析器使用本地/adhoc WiFi网络发送分析数据,从设备到Unity的编辑器)。
  2. Check "Autoconnect Profiler" checkbox in Unity's build settings dialog. 
    在Unity的构建设置(build settings)对话框中的,勾上复选框"自动连接分析器(Autoconnect Profiler)"。
  3. Attach your device to your Mac via cable and hit "Build & Run" in Unity Editor. 
    通过数据线将您的设备连接到你的Mac,在Unity编辑器中点击"Build &Run"。
  4. When app launches on device open profiler window in Unity Editor (Window->Profiler) 
    当应用程序在设备上启动,在Unity的编辑器打开分析器窗口(Window->Profiler)

If you are using a firewall, you need to make sure that ports 54998 to 55511 are open in the firewall's outbound rules - these are the ports used by Unity for remote profiling.

如果使用了防火墙,你必须确保端口54998 到 55511在防火墙的出站规则被打开。这些端口都是Unity远程分析要使用的端口。

Note: Sometimes Unity Editor might not autoconnect to the device. In such cases profiler connection might be initiated from Profiler Window Active Profiler drop down menu by select appropriate device.

注:有时,在Unity的编辑器可能不会自动连接到该设备。在这种情况下,在分析器窗口的Active Profiler下拉菜单选择相应的设备,分析器连接可以主动发起。

Android

Remote profiling can be enabled on Android devices through two different paths : WiFi or ADB.

远程分析可以在Android设备通过两种不同的途径启用:WiFi或ADB

For WiFi profiling, follow these steps:

对于WiFi分析,用下列的这些步骤:

  1. Make sure to disable Mobile Data on your Android device. 
    确保在Andriod设备禁用手机数据。
  2. Connect your Android device to your WiFi network. 
    连接Android设备到你的Wifi网络。
  3. Check the "Autoconnect Profiler" checkbox in Unity's build settings dialog. 
    在Unity编译设置对话框,检查Autoconnect Profiler复选框是否勾选。
  4. Attach your device to your Mac/PC via cable and hit "Build & Run" in Unity Editor. 
    通过数据线连接你的设备到电脑,在Unity点击Build & Run。
  5. When the app launches on the device, open the profiler window in Unity Editor (Window->Profiler) 
    当应用程序在设备上启动,在Unity打开分析器窗口(Window->Profiler)。
  6. If the Unity Editor fails to autoconnect to the device, select the appropriate device from the Profiler Window Active Profiler drop down menu. 
    如果Unity无法自动连接到该设备,从分析器窗口Active Profiler下拉菜单,选择相应的设备。

Note: The Android device and host computer (running the Unity Editor) must both be on the same subnet for the device detection to work.

注意:Android设备和主机计算机(正运行Unity)必须两者在同一子网,才能正常运行设备检测工作。

For ADB profiling, follow these steps:

对于ADB分析,用下列的这些步骤:

  • Attach your device to your Mac/PC via cable and make sure ADB recognizes the device (i.e. it shows in adb devices list). 
    通过数据线连接设备到电脑,并确保ADB设备设备(也就是说它显示在ADB设备列表)。
  • Open a Terminal window / CMD prompt and enter 
    打开一个终端窗口/ CMD提示符并输入
adb forward tcp:54999 localabstract:Unity-<insert bundle identifier here> 
  • Check the "Development Build" checkbox in Unity's build settings dialog, and hit "Build & Run". 
    在Unity编译设置对话框,检查Development Build复选框是否勾选,并点击Build & Run。
  • When the app launches on the device, open the profiler window in Unity Editor (Window->Profiler) 
    当应用程序在设备上启动,在Unity打开分析器窗口(Window->Profiler)。
  • Select the AndroidProfiler(ADB@127.0.0.1:54999) from the Profiler Window Active Profiler drop down menu. 
    从分析器窗口Active Profiler下拉菜单选择AndroidProfiler(ADB@127.0.0.1:54999)

Note: The entry in the drop down menu is only visible when the selected target is Android.

注意:进入下拉菜单,当选择目标是Android唯一可见时选择。

If you are using a firewall, you need to make sure that ports 54998 to 55511 are open in the firewall's outbound rules - these are the ports used by Unity for remote profiling.

如果使用了防火墙,你必须确保端口54998 到 55511在防火墙的出站规则被打开。这些端口都是Unity远程分析要使用的端口。

 类似资料: