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 文件,修改bUseMallocProfilertrue,这种方式是全局性的,包括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.exeFile -> Open 打开 .mprof 文件,然后点击工具栏最后的 Go 按钮即可分析内存