To profile your application on its target release platform, connect the target device to your network or directly to your computer via cable. You can also profile your application directly in the Unity Editor for approximate profiling results during the development of your application.
You can only profile your application as a Development Build. To set this up, go to Build Settings (File > Build Settings) and select your application’s target platform. Enable the Development Build setting.
You can also check the Autoconnect Profiler checkbox to make the Unity Editor bake its IP address into the built Player during the build process. When you start the player, it attempts to connect to the Profiler to the Editor located at the baked IP address.
When you build and run your application, the player appears in the Attach to Player drop-down of the Profiler window. The Attach to Player drop-down shows all Unity Players running on your local network. You can identify these Players by player type and the hostname that is running the player (for example, iPhonePlayer (Toms iPhone)).
Select it and then click Record to start collecting profiling information on your application. If you enabled Autoconnect to Profiler in Build Settings, Unity automatically starts collecting data when the application starts.
To continuously collect data while your application runs, enable the Run In Background setting in Player Settings (menu: Edit > Project Settings > Player > Resolution and Presentation). When you enable this setting, the Profiler collects data even when you leave your application running in the background. If you disable it, the Profiler only collects data when the application is running in an active window.
If you use the Profiler window to run and profile your application in the Editor, the results are only an approximation of your application’s behavior when the target platform runs it. Because Play Mode runs in the same process as the Editor, you cannot fully isolate your application’s CPU, GPU, and memory usage from Unity’s. This skews the resulting profiling data further.
To get better profiling results, you should always profile your application on a target device. Only profile in the Editor to quickly iterate over issues you have already identified on a device.
You can use the Unity Profiler in WebGL, but you cannot attach to running players via WebGL. This is because WebGL uses WebSockets for communication, which does not allow incoming connections on the browser side. To attach to a running player, you need to enable the Autoconnect Profiler checkbox in Build Settings (menu: File > Build Settings). Unity cannot profile draw calls for WebGL.
Both iOS and Android devices support remote profiling over a network. If you are using a firewall, open ports 54998 to 55511 in your firewall’s outbound rules. These are the ports Unity uses for remote profiling.
Note: Sometimes, when you set up remote profiling, the Unity Editor might not auto-connect to the device. If this happens, you can initiate the Profiler connection manually. To do this, select the Attach to Player drop-down menu in the Profiler window and choose the appropriate device.
You can also plug the target device directly into your computer, to avoid network or connection issues.
To enable remote profiling on iOS devices, follow these steps:
Android devices support two methods of remote profiling: via WiFi or through Android Debug Bridge (adb).
Para un profiling con WiFi, siga los siguientes pasos:
Note: The Android device and host computer that is running the Unity Editor must both be on the same subnet for device detection to work.
For Android Debug Bridge (adb) profiling, follow these steps:
The Unity Editor automatically creates an adb tunnel for your application when you select Build & Run. If you want to profile another application, or you restart the adb server, you have to configure this tunnel manually. To do this, open a Terminal window or CMD prompt and enter:
adb forward tcp:34999 localabstract:Unity-{insert bundle identifier here}
To use Deep Profiling with an Android build, you need to enable the Mono Scripting Backend setting in the Android Player Settings (menu: Edit > Project Settings > Player > Android > Other Settings) and enter the following to start the game through an adb command:
~$ adb shell am start -n {insert bundle identifier here}/com.unity3d.player.UnityPlayerActivity -e 'unity' '-deepprofiling'