This page has been translated automatically.
视频教程
界面
要领
高级
实用建议
基础
专业(SIM)
UnigineEditor
界面概述
资源工作流程
Version Control
设置和首选项
项目开发
调整节点参数
Setting Up Materials
设置属性
照明
Sandworm
使用编辑器工具执行特定任务
如何擴展編輯器功能
嵌入式节点类型
Nodes
Objects
Effects
Decals
光源
Geodetics
World Nodes
Sound Objects
Pathfinding Objects
Players
编程
基本原理
搭建开发环境
使用范例
C++
C#
UnigineScript
统一的Unigine着色器语言 UUSL (Unified UNIGINE Shader Language)
Plugins
File Formats
材质和着色器
Rebuilding the Engine Tools
GUI
双精度坐标
应用程序接口
Animations-Related Classes
Containers
Common Functionality
Controls-Related Classes
Engine-Related Classes
Filesystem Functionality
GUI-Related Classes
Math Functionality
Node-Related Classes
Objects-Related Classes
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
IG Plugin
CIGIConnector Plugin
Rendering-Related Classes
VR-Related Classes
创建内容
内容优化
材质
Material Nodes Library
Miscellaneous
Input
Math
Matrix
Textures
Art Samples
Tutorials

Microprofile

UNIGINE has support for Microprofile, an advanced external embeddable CPU/GPU profiler with support for per-frame inspection. UNIGINE支持Microprofile,这是一种先进的外部可嵌入CPU / GPU分析器,支持逐帧检查。

Microprofile Tool Microprofile工具

The profiler features the following:探查器具有以下特点:

  • Profiling operations performed by the engine on CPU and GPU引擎在CPU和GPU上执行的分析操作
  • Profiling the engine threads分析引擎线程
  • Profiling up to 1000 frames最多分析1000帧
  • The performance data output to a local web server or to an HTML file性能数据输出到本地Web服务器或HTML文件

Running Microprofile
运行Microprofile#

The Microprofile tool is available only for the Development builds of UNIGINE Engine: it won't be compiled for the Debug and Release ones. You can use the microprofile_info console command to check if the Microprofile is compiled. Microprofile工具仅适用于UNIGINE引擎的Development版本:不会针对DebugRelease版本进行编译。您可以使用 microprofile_info 控制台命令来检查Microprofile是否已编译。

The performance data obtained by the Microprofile can be output to a local web server or to an HTML file.Microprofile可以输出到本地Web服务器或HTML文件。

注意
Microprofile shows valid information only after the first 1000 frames are rendered (e.g. at the framerate of 60 FPS, such "warmup" time comprises about 16 seconds).Microprofile仅在渲染前 1000 帧后显示有效信息(例如,在60帧/秒的帧率下,这种“预热”时间约为16秒)。

Enabling and Disabling Microprofile
启用和禁用Microprofile#

Microprofile is performance-consuming, that's why we recommend you to enable it only when you work with it and keep disabled otherwise.Microprofile消耗性能,这就是为什么我们建议您仅在使用时启用它,否则保持禁用

One way to disable Microprofile is to untick the corresponding option before running UnigineEditor or the application:禁用Microprofile的一种方法是在运行UnigineEditor应用程序之前取消选中相应的选项:

Disabling Microprofile via SDK Browser

Another way is to use the microprofile_enabled console command.另一种方法是使用microprofile_enabled控制台命令。

注意
If you change the Microprofile status via the console, this setting is saved in the <Project_Name>/data/configs/default.user file. The state set in the user configuration file will override the state defined via SDK Browser.如果通过控制台更改Microprofile状态,则此设置将保存在<Project_Name>/data/configs/default.user文件中。 用户配置文件中设置的状态将复盖通过SDK浏览器定义的状态。

Saving Performance Data to File
将性能数据保存到文件#

Microprofile allows saving the performance data to an HTML file and then analyzing it offline.Microprofile允许将性能数据保存到HTML文件,然后离线分析。

To output the performance data to the HTML file, perform the following:要将性能数据输出到HTML文件,请执行以下操作:

  1. In the console, set the the number of frames to be profiled via the microprofile_dump_frames console command. You can skip this step: by default, 500 frames will be profiled.在控制台中,通过microprofile_dump_frames控制台命令设置要分析的帧数。 您可以跳过此步骤:默认情况下,将对500帧进行分析。
  2. Run the microprofile_dump_html console command.运行microprofile_dump_html控制台命令。

The performance data will be saved to the specified HTML file.性能数据将保存到指定的HTML文件中。

注意
If the path isn't specified, the dump is saved to data/microprofile_dump_html folder.如果未指定路径,则转储将保存到data/microprofile_dump_html文件夹。

Using profiling dumps simplifies capturing performance "spikes": the engine continues rendering the application in the background even when it is out of focus, so the frame where the spike has occurred can be overwritten in case of using the Web server for performance data visualization. Also it can be used to estimate the optimization results: you can dump frames before and after optimization and compare them.使用分析转储简化了捕获性能“峰值”:引擎在后台继续呈现应用程序,即使它不在焦点上,因此在使用Web服务器进行性能数据可视化的情况下,可以覆盖发生峰值的帧。它还可以用来估计优化结果:您可以转储优化前后的帧并对它们进行比较。

Visualization Using Built-In Server
使用内置服务器进行可视化#

To visualize the performance data using the local web server, perform the following:要使用本地Web服务器可视化性能数据,请执行以下操作:

  1. In the console, set the the number of frames to be profiled via the microprofile_webserver_frames console command. You can skip this step: by default, 200 frames will be profiled.在控制台中,通过 microprofile_webserver_frames 控制台命令设置要分析的帧数。您可以跳过此步骤:默认情况下,将分析 200 个帧。
  2. On the Menu Bar of UnigineEditor, choose Tools -> Microprofile.在UnigineEditor的菜单栏上,选择Tools -> Microprofile

The performance data will be displayed in your Web browser.性能数据将显示在您的Web浏览器中。

注意
  • You can display only a part of the profiled frames: in the Web browser address bar, add /<number_of_frames> to the current URL.您只能显示部分分析帧:在Web浏览器地址栏中,将/<number_of_frames>添加到当前URL。
  • Don't forget to refresh (F5) the page in the Web browser while the profiling data is collected as it is not performed automatically.在收集分析数据时,不要忘记在Web浏览器中刷新页面(F5),因为它不是自动执行的。

For example, if you specify localhost:1337/100, only the first 100 frames will be displayed.例如,如果指定localhost:1337/100,则仅显示前100帧。

注意
All available console commands can be found in the Performance Profiling section of the article on Console.所有可用的控制台命令都可以在关于 Console 的文章的 Performance Profiling 一节中找到。

Performance Data
性能数据#

The Microprofile visualizes the detailed per frame performance data on the operations performed by the engine on CPU and GPU and on the engine threads. In the Microprofile main menu, you can change the visualization mode: click Mode and choose the required one. By default, the Detailed mode is set. Microprofile可视化引擎在CPU和GPU 以及引擎线程上执行的操作的每帧详细性能数据。在Microprofile主菜单中,您可以更改可视化模式:单击Mode并选择所需的模式。默认情况下,设置为Detailed模式。

Profiling Groups Displayed in Detailed ModeDetailed模式显示的性能分析组

In the Detailed mode, each operation (function) and thread is displayed as a separate colored region. The regions are hierarchical: the function called by the other function is displayed under the last one. The size of the region is determined by the time the corresponding operation takes.Detailed模式下,每个操作(功能)和线程均显示为单独的彩色区域。区域是分层的:另一个功能调用的功能显示在最后一个功能下方。区域的大小取决于相应操作所花费的时间。

In the picture below, the Engine::do_render() function calls the RenderRenderer::renderWorld() functions and so on:在下图中,Engine::do_render()函数调用RenderRenderer::renderWorld()函数,依此类推:

To view the data on a certain operation or a thread, point to the corresponding region. To zoom in/out the displayed regions, scroll the mouse wheel.要在某个操作或线程上查看数据,请指向相应的区域。要放大/缩小显示的区域,请滚动鼠标滚轮。

CPU Data
CPU数据#

In the Main group of the performance data, the call stack of the operations (e.g., update, rendering, etc.) performed by the engine on CPU is displayed.在性能数据的Main组中,显示引擎在CPU上执行的操作的调用堆栈(例如update, rendering等)。

Performance Data on World Update Function World Update函数的性能数据

GPU Data
GPU数据#

In the GPU group of the performance data, the call stack of the operations performed by the engine on GPU is displayed. In addition to the main performance data, for each function (e.g. environment rendering, post materials rendering and so on), the number of DIP calls and rendered triangles is shown. Also there can be the number of surfaces, lights, shadows rendered by this function, the number of materials and shaders used; the information on the node or material for which the function is called (identifier, name, etc.).性能数据的 GPU 组中,显示了引擎在GPU上执行的操作的调用堆栈。除了主要性能数据以外,对于每个功能(例如环境渲染,后期材质渲染等),还会显示DIP调用和渲染的三角形的数量。还可以有此功能渲染的表面,灯光,阴影的数量,所使用的材质和着色器的数量。有关调用该函数的节点或材质的信息(标识符,名称等)。

Performance Data on Deferred Lighting Rendering延迟照明渲染上的性能数据

When the region that corresponds to the certain function is pointed, the Microprofile displays when this function is called on CPU and how much time is spent on its performing. 指向与某个功能对应的区域时,将在CPU上调用此功能以及执行该功能所花费的时间时显示Microprofile

Vulkan or DirectX commands can be combined into GPU Debug groups that are created automatically when defining a profiling scope. All graphic resources loaded from external files, such as textures, shaders, static or skinned meshes, as well as the Engine's internal resources, have their own debug names to simplify identification. This information can be useful when using Graphics API debuggers, such as NVIDIA Nsight or RenderDoc. Vulkan或DirectX命令可以组合到在定义概要分析范围时自动创建的GPU调试组。从外部文件加载的所有图形资源(例如纹理,着色器,静态或蒙皮的网格物体)以及引擎的内部资源均具有自己的调试名称,以简化识别。使用Graphics API调试器(例如NVIDIA NsightRenderDoc)时,此信息可能很有用。

Example of debug data viewed in RenderDocRenderDoc中查看的调试数据示例

Engine Threads Data
引擎线程数据#

The performance data on the engine threads is visualized in the CPUThread, SoundThread, AsyncQueueThread, WorldSpawnMeshClutterThread, WorldSpawnGrassThread groups. 引擎线程上的性能数据在CPUThread, SoundThread, AsyncQueueThread, WorldSpawnMeshClutterThread, WorldSpawnGrassThread组中可视化。

Performance Data on Physics Thread物理线程上的性能数据

Using Microprofile For Application Logic
将Microprofile用于应用逻辑#

You can use the Microprofile to inspect performance of your application logic. 您可以使用Microprofile来检查应用程序逻辑的性能。

  1. Open the source code of your application.打开应用程序的源代码。
  2. Include the UnigineProfiler.h file to get access to methods of the Profiler class.包含UnigineProfiler.h文件以访问Profiler类的方法。

    AppWorldLogic.h
    #include <UnigineProfiler.h>
    
    using namespace Unigine;
  3. Find a function or a scope in the code you want to inspect.在要检查的代码中查找函数或作用域。
  4. In the beginning of the function (or the scope), call Profiler::begin(). Specify a name for the capture to be displayed in the Microprofile.在函数(或作用域)的开头,调用Profiler::begin()。 指定要在Microprofile中显示的捕获的名称。

    注意
    You can specify the __FUNCTION__ macro to automatically use the class and the function name as the capture.您可以指定__FUNCTION__宏以自动使用类和函数名作为捕获。
  5. In the end of the function (scope), call Profiler::end().在函数(作用域)的末尾,调用Profiler::end()

    AppWorldLogic.cpp
    int AppWorldLogic::update()
    {
    
    	// start profiling
    	Profiler::begin("AppWorldLogic::update");
    
    	float time = Game::getTime();
    	float angle_0 = time * 1.0f;
    	float angle_1 = time * 1.5f;
    	float angle_2 = time * 2.0f;
    
    	light_0->setWorldTransform(translate(Unigine::Math::Vec3(sinf(angle_0), cosf(angle_0), 1.0f) * 20.0f));
    
    	light_1->setWorldTransform(translate(Unigine::Math::Vec3(sinf(angle_1), cosf(angle_1), 1.0f) * 20.0f));
    
    	light_2->setWorldTransform(translate(Unigine::Math::Vec3(sinf(angle_2), cosf(angle_2), 1.0f) * 20.0f));
    
    	// stop profiling
    	Profiler::end();
    
    	return 1;
    }
  6. Run the project.运行项目。
  7. Open the console and run the microprofile_enabled 1 command.打开控制台并运行microprofile_enabled 1命令。
  8. Go to the Microprofile and find the region with the specified name.转到Microprofile并找到具有指定名称的区域。

The begin() and end() functions make the profiling scope available for both the Profiler and Microprofile. begin()end()函数使分析作用域可用于分析器Microprofile

If you want to use Microprofile only, create the counter via the beginMicro() and endMicro() functions.如果您只想使用Microprofile,请通过beginMicro()endMicro()函数创建计数器。

注意
beginMicro() returns an identifier that should be passed to endMicro(). Thus, several nested counters can be created.beginMicro()返回应传递给endMicro()的标识符。 因此,可以创建多个嵌套计数器
AppWorldLogic.cpp
int AppWorldLogic::update()
{

	// start profiling
	int id = Profiler::beginMicro("AppWorldLogic::update");

	float time = Game::getTime();
	float angle_0 = time * 1.0f;
	float angle_1 = time * 1.5f;
	float angle_2 = time * 2.0f;

	light_0->setWorldTransform(translate(Unigine::Math::Vec3(sinf(angle_0), cosf(angle_0), 1.0f) * 20.0f));

	light_1->setWorldTransform(translate(Unigine::Math::Vec3(sinf(angle_1), cosf(angle_1), 1.0f) * 20.0f));

	light_2->setWorldTransform(translate(Unigine::Math::Vec3(sinf(angle_2), cosf(angle_2), 1.0f) * 20.0f));

	// stop profiling
	Profiler::endMicro(id);

	return 1;
}

Creating Nested Counters for Profiling
创建用于分析的嵌套计数器#

To create several nested counters, you should use the beginMicro() and endMicro() functions. beginMicro() returns an identifier that should be passed to endMicro(). This enables to create nested and intersecting profiler counters.要创建多个嵌套计数器,应使用beginMicro()endMicro()函数。 beginMicro()返回应传递给endMicro()的标识符。 这样就可以创建嵌套和相交的分析器计数器。

In the following example, combination of begin()/end() and beginMicro()/endMicro() is used. So, profiling of the AppWorldLogic::update() function will be available in both the Profiler and the Microprofile.在以下示例中,使用begin()/end()beginMicro()/endMicro()的组合。 因此,AppWorldLogic::update()函数的分析将在分析器和Microprofile中都可用。

AppWorldLogic.cpp
int AppWorldLogic::update()
{

	// start profiling
	Profiler::begin("AppWorldLogic::update");

	float time = Game::getTime();
	float angle_0 = time * 1.0f;
	float angle_1 = time * 1.5f;
	float angle_2 = time * 2.0f;

	// start profiling of the first light source (available in the Microprofile only)
	int id_0 = Profiler::beginMicro("1st Light Update");

	light_0->setWorldTransform(translate(Unigine::Math::Vec3(sinf(angle_0), cosf(angle_0), 1.0f) * 20.0f));

	// stop profiling of the first light source
	Profiler::endMicro(id_0);

	// start profiling of the second light source (available in the Microprofile only)
	int id_1 = Profiler::beginMicro("2nd Light Update");

	light_1->setWorldTransform(translate(Unigine::Math::Vec3(sinf(angle_1), cosf(angle_1), 1.0f) * 20.0f));

	// stop profiling of the second light source
	Profiler::endMicro(id_1);

	light_2->setWorldTransform(translate(Unigine::Math::Vec3(sinf(angle_2), cosf(angle_2), 1.0f) * 20.0f));

	// stop profiling
	Profiler::end();

	return 1;
}

注意
Use only beginMicro()/endMicro(), if you don't need the Profiler tool.如果您不需要分析器工具,请仅使用beginMicro()/endMicro()

Profiling Logic Using Macros
使用宏分析逻辑#

There are special macros to mark fragments of your code that should be inspected. They can be used instead of the beginMicro() and endMicro() functions:有特殊的来标记应该检查的代码片段。 它们可以用来代替beginMicro()endMicro()函数:

  • UNIGINE_PROFILER_FUNCTION to inspect performance of the function.UNIGINE_PROFILER_FUNCTION检查功能的性能。

    Using Macro Using Functions
    源代码 (C++)
    void myFunction()
    {
    	UNIGINE_PROFILER_FUNCTION;
    	// your function code
    }
    源代码 (C++)
    void myFunction()
    {
    	int id = Profiler::beginMicro(__FUNCTION__);
    	// your function code
    	Profiler::endMicro(id);
    }
  • UNIGINE_PROFILER_SCOPED to inspect only a certain part of the code.UNIGINE_PROFILER_SCOPED只检查代码的某一部分。

    Using Macro Using Functions
    源代码 (C++)
    void myFunction()
    {
    	// your function code
    	{
    		UNIGINE_PROFILER_SCOPED("Scope name");
    		// your function code
    	}
    }
    源代码 (C++)
    void myFunction()
    {
    	// your function code
    	{
    		int id = Profiler::beginMicro("Scope name");
    		// your function code
    		Profiler::endMicro(id);
    	}
    }

Video Tutorial: Performance Inspection with Microprofile
视频教程:使用Microprofile进行性能检查#

最新更新: 2024-08-16
Build: ()