本文为原创,如需转载请标注原址:http://blog.csdn.net/cube454517408/article/details/51700492
使用Unity Profiler查看Android手机上运行性能数据,以下是官方文档:
Android
Remoteprofiling can be enabled on Android devices through two different paths : WiFiorADB.
For WiFiprofiling, follow these steps:
- Make sure to disable Mobile Data on your Android device.
- Connect your Android device to your WiFi network.
- Attach your device to your Mac/PC via cable, check the “Development Build” and “Autoconnect Profiler” checkboxes in Unity’s build settings dialog, and hit “Build & Run” in Unity Editor.
- When the app launches on the device, open the profiler window in Unity Editor (Window->Profiler)
- If the Unity Editor fails to autoconnect to the device, select the appropriate device from the Profiler Window Active Profiler drop down menu.Note: The Android device and host computer (running the Unity Editor) must both be on the samesubnet for the device detection to work.
For ADB profiling,follow these steps:
- Attach your device to your Mac/PC via cable and make sure ADB recognizes the device (i.e. it shows inadb devices list).
- Check the “Development Build” checkbox in Unity’s build settings dialog, and hit “Build & Run”.
- When the app launches on the device, open the profiler window in Unity Editor (Window->Profiler)
- Select the AndroidProfiler(ADB@127.0.0.1:54999) from the Profiler Window Active Profiler drop down menu.Note: The Unity editor will automatically create an adb tunnel for your application when you press “Build & Run”. If you want to profile another application or you restart the adb server you have to setup this tunnel manually. To do this, open a Terminal window / CMD prompt and enter:
adb forward tcp:54999 localabstract:Unity-{insert bundle identifier here}
Note: Theentry in the drop down menu is only visible when the selected target isAndroid.
If you areusing a firewall, you need to make sure that ports 54998 to 55511 are open inthe firewall’s outbound rules - these are the ports used by Unity for remoteprofiling.
官方这里介绍了两种联调方式:wifi和用数据线连接的adb模式,这里推荐用adb模式,数据反馈更为及时。这里我们采用adb来联调。
简单罗列一下官方步骤:
1. 将你的手机设备采用adb的方式与PC/Mac相连
2. 发布Unity Android Apk时,勾选“Development Build”和“AutoConnect Profiler”选项
3. 开始运行手机程序后,点开Window->Profiler,选择AndroidProfiler(ADB@127.0.0.1:54999)
4. 手动打开adb的连接,打开CMD,输入:adb forward tcp:54999localabstrack:Unity-com.WJ.SwDemo2;(注意:这里的com.WJ.SwDemo2请填写运行应用程序的Bundle Identifier)
注意:这里要注意防火墙不能屏蔽端口:54998-55511
下面记录一下联调过程中发现的问题和解决方案,以供参考~
1. 开启防火墙端口54998-55511:
2. 输入adb联调命令:
打开CMD(快捷键WIN+R),
输入:adb forwardtcp:54999 localabstract:Unity-com.WJ.SwDemo2,回车;
如上图:
1) 回车后,还无法连接,输入:adb nodaemon server,发现端口5037已被占用
2) 输入:netstat –ano | findstr “5037”,查看5037被哪些进程占用
3) 输入:taskkill /f /pid 5900(这里是上面查出的进程pid),终止占用5037的进程
4) 输入:adb forward tcp:54999 localabstract:Unity-com.WJ.SwDemo2,发现5037还不能连
5) 输入:adb start-server,重新启动adb,然后再输入4)所示adb连接代码
6) 打开手机应用程序,并确保Profiler选择AndroidProfiler(ADB@127.0.0.1:54999)模式,即可在电脑上查看应用的性能数据