宝塔服务器面板,一键全能部署及管理,送你10850元礼包,点我领取

Profiler工具的代码详见:UnrealEngineEngineSourceDeveloperProfiler

UE4提供了2种使用Profiler工具的方式:

① UE4编辑器中的Session Frontend面板,见菜单“Window” — “Developer Tools” — “Session Frontend”

UE4 stats文件Profiler工具-风君子博客

② 独立的UnrealFrontend工具

UE4 stats文件Profiler工具-风君子博客

离线模式

控制台命令抓取性能数据并保存到文件

stat startfile // starts a stats capture, creating a new file in the Profiling directory; stop with stat StopFile to close the file

stat stopfile  // stops dumping a capture regular, raw, memory).  finishes a stats capture started by stat StartFile

stat startfileraw  // starts dumping a raw capture.  4.26版本可以生成ue4statsraw文件,但是Profiler工具不能支持该文件的读取   注:详见FProfilerManager::LoadRawStatsFile函数

stat stopfileraw   // 功能与stat stopfile一致

ue4stat文件保存在:SavedProfilingUnrealStats目录中

在代码中开启和关闭stat文件

#if STATS
    DirectStatsCommandTEXT"stat startfile"));
#endif

#if STATS
    DirectStatsCommandTEXT"stat stopfile"),true);
#endif

Profiler工具读取性能数据

在Frontend工具中的Profiler标签下,点击Load来读取ue4stat文件

也可以点击Load Folder来加载某个目录下的所有ue4stat文件

UE4 stats文件Profiler工具-风君子博客

注:红框处会列出所有的ue4stat文件, 点击即可切换

实时模式

首先需要在uproject文件中启用TcpMessagingUdpMessaging插件   注:默认会启用,但uproject中可将其关闭

本机或USB数据线的连接模式

游戏侧

UE4Editor.exe %GameDir%MyGame.uproject -skipcompile  // 编辑器

UE4Editor.exe %GameDir%MyGame.uproject ThirdPersonExampleMap -messaging -SessionName=mySession -game -skipcompile  // standalone单击  对本机或USB数据线连接的机器上的UnrealFrontend可见

Profiler工具侧

UE4Editor.exe %GameDir%MyGame.uproject -skipcompile

UnrealFrontend.exe

同一wifi网络的连接模式

游戏侧

PC:UE4Editor.exe %GameDir%MyGame.uproject ThirdPersonExampleMap -messaging -SessionName=mySession -TcpMessagingConnect=10.46.80.61:7777 -game -skipcompile  // 以standalone启动ThirdPersonExampleMap地图,并连接到10.46.80.61:7777

Android:UE4CommandLine.txt写入如下内容,并adb push到手机的UE4Game/UAGame目录中

-messaging TcpMessagingConnect=10.46.80.61:7777 -SessionOwner=kekec

IOS:ue4commandline.txt(注:要全小写)写入与Android一样的内容,并放到如下目录中

UE4 stats文件Profiler工具-风君子博客

Profiler工具侧

UE4Editor.exe %GameDir%MyGame.uproject -TcpMessagingListen=10.46.80.61:7777 -SessionOwner=kekec -skipcompile  //  启动编辑器并监听10.46.80.61:7777   注:10.46.80.61为编辑器所在机器的IP

UnrealFrontend.exe -TcpMessagingListen=10.46.80.61:7777 -SessionOwner=kekec  //  启动UnrealFrontend.exe并监听10.46.80.61:7777   注:10.46.80.61为UnrealFrontend所在机器的IP

实时Profiler

UE4 stats文件Profiler工具-风君子博客

为tips触发区域,鼠标放置上去,会显示更详细的信息说明

UE4 stats文件Profiler工具-风君子博客

Load:加载一个ue4stats文件

Load Folder:加载一个目录下的所有ue4stats文件

Data Preview:在左侧选中一个Session后, 点击该按钮可实时profiler

Live preview:让下面的GR红蓝条、Graph View条Scroll到最新帧

Data Capture:startfile / stopfile

Statistics:开启Stats Profiler

FPS Chart:统计整个文件的fps分布

UE4 stats文件Profiler工具-风君子博客

面板其他功能说明 

UE4 stats文件Profiler工具-风君子博客

GR红蓝条说明

① 红色为Game Thread的耗时(含Waiting那部分时间)  — 即FrameTime

② 蓝色为Rendering Thread的耗时(含Waiting那部分时间)

③ 通过红蓝条的高度,可快速找到耗时的区域部分

Graph View说明

① 双击左边Panel中的统计细项,会在Graph View上绘制出其各帧的数值曲线

② Threads) GameThread [0x1d3b] 24.06MS)/Calls 1 – {Value Min:22.796 Avg:45.743 Max:1857.557MS) / Calls 100%) Min:1.0 Avg:1.0 Max:1.0}

Stat统计项

所有统计大类如下:

UE4 stats文件Profiler工具-风君子博客

Group Name为Memory的统计细项如下:

UE4 stats文件Profiler工具-风君子博客

统计项类型:

为hierarchy类别,可以嵌套子节点,包含CallCount、InclusiveTime、ExclusiveTime等字段

为int或float数字类型

为Memory类型

hierarchy类别数据CallStack

UE4 stats文件Profiler工具-风君子博客

工具栏说明:

① Type有:OneFrame(选中一帧时)     Average、Maximum(拉框选中一个区域时)

② View mode:Hierarchical(层次树,按Inc Time排序)、

                          Inclusive(Flat方式,按Inc Time排序)、Inclusive(Flat方式,同名统计项合并在一起,按Inc Time排序)

                          Exclusive(Flat方式,按Exc Time排序)、Exclusive(Flat方式,同名统计项合并在一起,按Exc Time排序)

③   帧选择的Undo、Redo

④   快速展开选中节点Inc Time消耗最高的路径

其他区域说明: 

① 在Event Name层次树中的统计项均为hierarchy类别。背景色越红,说明该项的Inc TimeMS)就越高,耗时也就越高

② IncTime的两列为包含时间,Exc Time的两列为独占时间,数据为0,是显示问题;Calls为当前帧该项统计次数

③ Event Name层次树的顶层节点均为Thread。如:StatsThread [0x1d83]    其中StatsThread为线程名,0x1d83为16进制的线程ID

④ 可先通过Thread下拉框选择自己感兴趣的线程,那么其他线程就会变灰;重新选做None后,就全部恢复正常

⑤ 在Event Name层次树中,选中一个节点后,左边Calling Functions下会画出父节点的按钮,点击后,会往顶层回溯;中间Current Function为选中节点;

     右边Called Functions下会画出所有子节点的按钮,点击后,会往下回溯;名为Self的子节点比较特殊,它的Inc TimeMS)表示其父节点的独占时间。

右键快捷菜单和快捷键说明:

①  Expand All(展开所有子节点) –> Ctrl + A(全选)

② 按住Ctrl或Shift来快速多选

③ Select Stack:向顶层回溯,选中整个Stack

④ Copy To Clipboard(快捷键为Ctrl + C):可以将选中的节点拷贝到剪切板中

参考

分析工具参考

UE4 Android下实时profile获取数据