提交 f3a96e21 编写于 作者: O oceanxiao

add memoryprofiler

上级 9422ea5d
......@@ -114,7 +114,7 @@ Unity引擎视角:
### 3.3 MemoryProfiler
MemoryProfiler可以分析UnityHeap底层分配器的分配细节,任何分配都会产生记录,因此我们可以通过该能力分析更详细具体的分配行为。
关于该能力的使用请查阅[使用MemoryProfiler分析内存](MemoryProfiler.md)
关于该能力的使用请查阅[使用MemoryProfiler分析内存](UsingMemoryProfiler.md)
### 3.4 Unity Profiler
当发现UnityHeap(尤其是Native)占用比较高时,可通过UnityProfiler进一步分析问题所在。关于该工具在微信小游戏的使用请查阅[使用 Unity Profiler 性能调优](UnityProfiler.md),推荐使用Unity InstantGame版本增强的Profiler功能,下载地址请查阅[推荐引擎版本](UnityVersion.md)
......
# 使用MemoryProfiler内存分析
## 概述
利用MemoryProfiler,我们可以分析UnityHeap(CPU主内存)的详细分配堆栈与统计数值
## 步骤
1. 导出选项时勾选"Profiling Funcs"与"Profiling Memory"
<img src='../image/memoryprofiler1.png' width="800"/>
2. 在微信开发者工具运行游戏,过程中会自动记录所有内存分配数据
3. 在微信开发者工具中选择gameContext, 并在Console输入命令: GameGlobal.memprofiler.onDump()
<img src='../image/memoryprofiler2.png' width="600"/>
Unity将自启动监听端口34999等待调试链接,对于WebGL版本会启动websockify.js(用于websocket转发)。
此时,导出的WebGL游戏在浏览器时能自动连接到Unity Profiler。
4. 将位于游戏缓存目录下的csv内存数据拖拽并导入到sqlite数据库, 推荐使用[DB Browser for SQLite](https://sqlitebrowser.org/)
<img src='../image/memoryprofiler3.png' width="600"/>
<img src='../image/memoryprofiler4.png' width="400"/>
5. 对表格执行格式化换行
update alloc_used set callback=replace(callback, 'at ', x'0a'
6. 使用常规SQL进行数据分析
<img src='../image/memoryprofiler5.png' width="800"/>
其中:
- callback: 堆栈
- count: 当前存活的分配次数
- size: 当前使用内存
- malloc: 总分配次数
- free: 总释放次数
典型地, 我们可以通过size进行排序分析内存最大占用的堆栈情况
常见的数据分配堆栈特征:
Unity 2021:
```
所有内存: select sum(size) from alloc_used
AssetBundle Storage Memory: select *sum(size)* from alloc_used where callback like "%AssetBundle_LoadFromMemory%" or callback like "%OnFinishReceiveData%" or callback like "%AssetBundleLoadFromStream%"
AssetBundle Info: select * from alloc_used where callback like "%get_assetBundle%"
Lua: select * from alloc_used where callback like "%luaY_parser%" or callback like "%luaH_resize%" or callback like "%luaM_realloc%"
Shader: select * from alloc_used where callback like "%ShaderLab%"
IL2CPP runtime: select sum(size) from alloc_used where callback like "%MetadataCache%"
MipMap: select * from alloc_used where callback like "%Mipmap%"
Other: select * from alloc_used where callback not like "%xxx%" or callback not like "%xxx%"
```
......@@ -62,6 +62,7 @@
- [使用 Android CPU Profiler 性能调优](Design/AndroidProfile.md)
- [使用 Unity Profiler 性能调优](Design/UnityProfiler.md)
- [优化Unity WebGL的内存](Design/OptimizationMemory.md)
- [使用MemoryProfiler分析内存](Design/UsingMemoryProfiler.md)
- [音频适配优化](Design/AudioOptimization.md)
- [压缩纹理优化](Design/CompressedTexture.md)
- [资源优化工具与建议](Design/AssetOptimization.md)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册