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
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
注意! 这个版本的文档是过时的,因为它描述了一个较老的SDK版本!请切换到最新SDK版本的文档。
注意! 这个版本的文档描述了一个不再受支持的旧SDK版本!请升级到最新的SDK版本。

Unigine::Profiler Class

Header: #include <UnigineProfiler.h>

The Profiler class is used to create counters for the engine Performance Profiler. Allows using counters in your code in the following manner:

Source code (C++)
Profiler::begin("my_counter");
// ...code to profile...
Profiler::end();
Notice
Counters can be nested.

Usage Example#

The following example contains different approaches to creating counters:

  • Two counters are added via the setValue() function: one shows the number of dynamic mesh vertices, the other shows the update time. This approach should be used when you need to show, for example, a value of a setting, the number of objects, and so on.
  • Another two counters are added by using the begin()/end() construction. They show the time spent for mesh grid modifying and the time spent for mesh normal vectors, tangent vectors and a mesh bounding box calculation. This approach should be used when you need to show time spent for executing a part of the code.

AppWorldLogic.h contains declaration of the required variables.

Source code (C++)
#include <UnigineLogic.h>
#include <UnigineStreams.h>
#include <UnigineObjects.h>

class AppWorldLogic: public Unigine::WorldLogic
{

public:
	AppWorldLogic();
	virtual ~AppWorldLogic();

	int init() override;

	int update() override;
	int postUpdate() override;
	int updatePhysics() override;

	int shutdown() override;

	int save(const Unigine::StreamPtr &stream) override;
	int restore(const Unigine::StreamPtr &stream) override;

private:
	// declare variables
	int size = 128;
	Unigine::ObjectMeshDynamicPtr mesh;
};

In AppWorldLogic.cpp, a dynamic mesh is created and then modified on the engine update. All counters are created in update() too.

Source code (C++)
#include "AppWorldLogic.h"
#include <UnigineProfiler.h>
#include <UnigineEditor.h>
#include <UnigineGame.h>

using namespace Unigine;

int AppWorldLogic::init()
{
	// create a dynamic mesh
	mesh = ObjectMeshDynamic::create(ObjectMeshDynamic::USAGE_DYNAMIC_VERTEX | ObjectMeshDynamic::USAGE_IMMUTABLE_INDICES);
	// set the mesh settings
	mesh->setWorldTransform(Math::translate(Math::Vec3(0.0f, 0.0f, 2.0f)));

	// create dynamic mesh vertices
	for (int y = 0; y < size; y++) {
		for (int x = 0; x < size; x++)
		{
			mesh->addVertex(Math::vec3(0.0f));
			mesh->addTexCoord(Math::vec4((float)x / size, (float)y / size, 0.0f, 0.0f));
		}
	}

	// create dynamic mesh indices
	for (int y = 0; y < size - 1; y++) {
		int offset = size * y;
		for (int x = 0; x < size - 1; x++) {
			mesh->addIndex(offset);
			mesh->addIndex(offset + 1);
			mesh->addIndex(offset + size);
			mesh->addIndex(offset + size);
			mesh->addIndex(offset + 1);
			mesh->addIndex(offset + size + 1);
			offset++;
		}
	}

	return 1;
}

int AppWorldLogic::update()
{
	// add a counter that shows engine update phase duration
	Profiler::setValue("Update time", "ms", Engine::get()->getUpdateTime(), 50.0f, Math::vec4(0.0f, 0.0f, 0.0f, 1.0f));
	float time = Game::getTime();
	float isize = 30.0f / size;
	// start the counter that shows the time spent for dymanic mesh grid modifying
	Profiler::begin("Grid", Math::vec4(1.0f));
	for (int y = 0; y < size; y++)
	{
		for (int i = 0; i < size; i++)
		{
			float Y = y * isize - 15.0f;
			float Z = Math::cos(Y + time);
			for (int x = 0; x < size; x++)
			{
				float X = x * isize - 15.0f;
				mesh->setVertex(i++, Math::vec3(X, Y, Z * Math::sin(X + time)));
			}
		}
	}
	// stop the counter
	Profiler::end();
	// start the counter that shows the time spent for 
	// dynamic mesh normal vectors, tangent vectors and a mesh bounding box calculation
	Profiler::begin("mesh");
	mesh->updateBounds();
	mesh->updateTangents();
	mesh->flushVertex();
	// stop the counter
	Profiler::end();

	// add the counter that shows the number of dynamic mesh vertices
	Profiler::setValue("Num vertices", "", mesh->getNumVertex(), 32768, NULL);

	return 1;
}

Notice
To create nested counters, you need to use the beginMicro() and endMicro() functions.

See Also#

Profiler Class

Members


void setEnabled ( bool enabled ) #

Console: show_profiler
Enables or disables the profiler.

Arguments

  • bool enabled - 1 to enable the profiler, 0 to disable it.

bool isEnabled ( ) const#

Console: show_profiler
Returns a value indicating if the profiler is enabled.

Return value

1 if the profiler is enabled; otherwise, 0.

void setValue ( const char * name, const char * units, int value, int max_value, float * OUT_arg5 ) #

Updates settings of the integer counter.
Source code (C++)
// add a counter without a graph
Profiler::setValue("Random value 1", "", rand() % 5, 4, NULL);
// add a counter with a colored graph
Profiler::setValue("Random value 2", "", rand() % 10, 9, Math::vec4(1.0f));

Arguments

  • const char * name - Name of the counter.
  • const char * units - Counter units.
  • int value - Value of the counter.
  • int max_value - Counter maximum value.
  • float * OUT_arg5 - Color of the graph. Pass NULL if no graph is required.
    Notice
    This output buffer is to be filled by the Engine as a result of executing the method.

void setValue ( const char * name, const char * units, float value, float max_value, float * OUT_arg5 ) #

Updates settings of the float counter.
Source code (C++)
float rvalue1 = static_cast<float>(rand()) / static_cast<float>(RAND_MAX);
float rvalue2 = static_cast<float>(rand()) / static_cast<float>(RAND_MAX);
// add a counter without a graph
Profiler::setValue("Random value 1", "", rvalue1, 1.0f, NULL);
// add a counter with a colored graph
Profiler::setValue("Random value 2", "", 1 + rvalue2, 10.0f, Math::vec4(1.0f));

Arguments

  • const char * name - Name of the counter.
  • const char * units - Counter units.
  • float value - Value of the counter.
  • float max_value - Counter maximum value.
  • float * OUT_arg5 - Color of the graph. Pass NULL if no graph is required.
    Notice
    This output buffer is to be filled by the Engine as a result of executing the method.

float getValue ( const char * name ) const#

Returns a value of the specified counter.

Arguments

  • const char * name - The name of the counter.

Return value

Value of the counter in milliseconds.

void begin ( const char * name, const Math::vec4 & color ) const#

Starts a counter with a given name and shows a colored graph (if the show_profiler 1 console variable is set). The counter shows user how many millisecods have been spent for the operation that is performed between the begin() and the end() functions.
Source code (C++)
int size = 128;

Unigine::ObjectMeshDynamicPtr mesh;

	float time = Game::getTime();
	float isize = 30.0f / size;
	// start the counter that shows the time spent for dymanic mesh grid modifying
	Profiler::begin("Grid", Math::vec4(1.0f));
	for (int y = 0; y < size; y++)
	{
		for (int i = 0; i < size; i++)
		{
			float Y = y * isize - 15.0f;
			float Z = Math::cos(Y + time);
			for (int x = 0; x < size; x++)
			{
				float X = x * isize - 15.0f;
				mesh->setVertex(i++, Math::vec3(X, Y, Z * Math::sin(X + time)));
			}
		}
	}
	// stop the counter
	Profiler::end();

Arguments

  • const char * name - Name of the counter.
  • const Math::vec4 & color - Color of the graph.

void begin ( const char * name ) const#

Starts a counter with a given name. The counter shows user how many millisecods have been spent for the operation that is performed between the begin() and the end() functions.
Source code (C++)
Unigine::ObjectMeshDynamicPtr mesh;

	// start the counter that shows the time spent for 
	// dynamic mesh normal vectors, tangent vectors and a mesh bounding box calculation
	Profiler::begin("mesh");
	mesh->updateBounds();
	mesh->updateTangents();
	mesh->flushVertex();
	// stop the counter
	Profiler::end();

Arguments

  • const char * name - Name of the counter.

float end ( ) const#

Stops the last activated counter and returns its value.

Return value

Value of the counter in milliseconds.

const char * getMicroprofileUrl ( ) const#

Returns the microprofile web server url.

Return value

Microprofile web server url represented in the following way:

http://localhost:p/, where p is the local port.

Ptr<Gui> getGui ( ) const#

Returns a pointer to the GUI of the engine Performance Profiler.

Return value

Pointer to the GUI.

void setGui ( const Ptr<Gui> & gui ) #

Sets the GUI for the engine Performance Profiler.

Arguments

  • const Ptr<Gui> & gui - Pointer to the GUI class instance.

int beginMicro ( const char * name, bool gpu = 0 ) const#

Starts a counter with a given name in the Microprofile only, without overloading the Performance Profiler layout. The counter shows user how many millisecods have been spent for the operation that is performed between the beginMicro() and the endMicro() functions.
Notice
Each counter has an ID. Thus, several nested beginMicro() / endMicro() blocks can be created, which can't be done in the Performance Profiler.
Source code (C++)
Unigine::ObjectMeshDynamicPtr mesh;

	// start the counter that shows the time spent for dynamic mesh normal vectors,
	// tangent vectors and a mesh bounding box calculation, with a nested counter for tangent vectors only
	int c_id = Profiler::beginMicro("mesh");
	mesh->updateBounds();
	int c_nested_id = Profiler::beginMicro("mesh_tangents");
	mesh->updateTangents();
	Profiler::endMicro(c_nested_id);
	mesh->flushVertex();
	// stop the counter
	Profiler::endMicro(c_id);

Arguments

  • const char * name - Name of the counter.
  • bool gpu - Use 1 for the GPU counter, or 0 — for the CPU counter. The default value is 0.

Return value

ID of the new added counter.

void endMicro ( int id ) const#

Stops a previously activated Microprofile counter with the specified ID.

Arguments

  • int id - Microprofile counter ID.
Last update: 2024-09-03
Build: ()