UE4 MemoryProfiler使用
编译MemoryProfiler工具
- 打开
Engine\Source\Programs\MemoryProfiler2\MemoryProfiler2.sln工程文件,然后编译 - 编译完成后的可执行文件位于
Engine\Programs\MemoryProfiler2\Binaries目录
修改游戏工程编译选项
有两种方式可以打开 Malloc Profiler
-
在
xxx.Target.cs的构造函数中增加bUseMallocProfiler = true -
或者,打开
Engine\Saved\UnrealBuildTool\BuildConfiguration.xml文件,修改bUseMallocProfiler为true,这种方式是全局性的,包括editor都会打开 Malloc Profiler,所以不推荐使用<?xml version="1.0" encoding="utf-8" ?> <Configuration xmlns="https://www.unrealengine.com/BuildConfiguration"> dConfiguration> <bUseMallocProfiler>true</bUseMallocProfiler> ldConfiguration> </Configuration> -
保存文件,编译游戏工程
内存分析
- 运行游戏,用
MPROF MARK来生成内存快照,也可以MPROF MARK SnapshotName来给快照指定名称 - 输入
MPROF STOP命令来停止内存监控,然后会在游戏工程目录\Saved\Profiling目录下生成以日期时间为后缀的目录,目录中包含.mprof内存记录文件。这个指令是必须的,否则.mprof文件不能用 - 运行
Engine\Programs\MemoryProfiler2\Binaries\MemoryProfiler2.exe,File -> Open打开.mprof文件,然后点击工具栏最后的Go按钮即可分析内存