Android手机用Unity Profiler查看性能

本文为原创,如需转载请标注原址:http://blog.youkuaiyun.com/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:

  1. Make sure to disable Mobile Data     on your Android device.
  2. Connect your Android device to     your WiFi network.
  3. 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.
  4. When the app launches on the     device, open the profiler window in Unity Editor (Window->Profiler)
  5. 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)模式,即可在电脑上查看应用的性能数据

 

 

 

### 如何使用 Unity Profiler 进行性能分析 #### 了解 Unity Profiler 工具 Unity 提供了名为 Profiler 的强大工具,用于帮助开发者识别并解决应用程序中的性能瓶颈。该工具有助于深入理解程序各部分的执行情况,从而做出针对性优化[^2]。 #### 启动与配置 Profiler 为了启动 Profiler,在编辑器窗口顶部菜单栏找到 `Window` -> `Analysis` -> `Profiler` 即可打开此面板。初次开启时,默认显示的是最近一次播放模式下的数据记录;如果希望获取当前正在运行项目的实时信息,则需确保项目处于 Play 模式下,并勾选左上方的 "Deep Profile" 选项来收集更加详尽的数据[^1]。 #### 主要功能模块解析 - **CPU Usage**:展示 CPU 上各个系统的占用率,包括脚本、动画、物理计算等方面; - **Rendering**:涉及图形渲染过程的各项指标统计,如绘制调用次数(Draw Calls),三角形数量(Triangles)等; - **Memory**:监控堆内存分配状况,对于排查潜在泄漏问题至关重要; - **Audio/Video/GPU Jobs/etc.**:其他子系统的表现概况也会被纳入监测范围之内。 #### 实际操作指南 当面对特定场景想要捕捉其完整的性能特征时,可以点击下方红色按钮开始录制一段时间内的活动日志。结束后通过拖拽滑块来回放整个流程,观察不同阶段各项参数的变化趋势。另外值得注意的一点是在移动平台上做性能测试的话,还可以借助 ADB 命令让 Android 设备上的应用连接到本地计算机来进行远程调试[^4]。 ```bash adb connect <device_ip>:<port> ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值