This page has been translated automatically.
UnigineEditor
Interface Overview
Assets Workflow
Settings and Preferences
Adjusting Node Parameters
Setting Up Materials
Setting Up Properties
Landscape Tool
Using Editor Tools for Specific Tasks
FAQ
Programming
Fundamentals
Setting Up Development Environment
Usage Examples
UnigineScript
C++
C#
UUSL (Unified UNIGINE Shader Language)
File Formats
Rebuilding the Engine and Tools
GUI
Double Precision Coordinates
API
Containers
Common Functionality
Controls-Related Classes
Filesystem Functionality
GUI-Related Classes
Math Functionality
Node-Related Classes
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
CIGI Client Plugin
Rendering-Related Classes
Warning! This version of documentation is OUTDATED, as it describes an older SDK version! Please switch to the documentation for the latest SDK version.
Warning! This version of documentation describes an old SDK version which is no longer supported! Please upgrade to the latest SDK version.

engine.profiler Functions

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 (UnigineScript)
engine.profiler.begin("my_counter");
// ...code to profile...
engine.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 shows 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.

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

Source code (UnigineScript)
#include <core/unigine.h>

// declare variables
int size = 128;
ObjectMeshDynamic mesh;

int init() {
	
	// create a dynamic mesh and remove script ownership
	mesh = class_remove(new ObjectMeshDynamic(OBJECT_DYNAMIC_VERTEX | OBJECT_IMMUTABLE_INDICES));
	// pass ownership to UnigineEditor
	engine.editor.addNode(mesh);
	// set the mesh settings
	mesh.setWorldTransform(translate(Vec3(0.0f,0.0f,2.0f)));
	mesh.setMaterial("mesh_base","*");
	mesh.setProperty("surface_base","*");
	
	// create dynamic mesh vertices
	for(int y = 0; y < size; y++) {
		for(int x = 0; x < size; x++) {
			mesh.addVertex(vec3_zero);
			mesh.addTexCoord(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 update() {
	
	// add a counter that shows the number of dynamic mesh vertices
	engine.profiler.setValue("Num Vertices", "", mesh.getNumVertex());
	// add a counter that shows engine update phase duration
	engine.profiler.setValue("Update time", "ms", engine.getUpdateTime(),1.0f,vec4(1.0f));

	float time = engine.game.getTime();
	float isize = 30.0f / size;
	// start the counter that shows the time spent for dymanic mesh grid modifying
	engine.profiler.begin("grid",vec4(1.0f));
	forloop(int y = 0, i = 0; size) {
		float Y = y * isize - 15.0f;
		float Z = cos(Y + time);
		forloop(int x = 0; size) {
			float X = x * isize - 15.0f;
			mesh.setVertex(i++,vec3(X,Y,Z * sin(X + time)));
		}
	}
	// stop the counter
	engine.profiler.end();
	
	// start the counter that shows the time spent for
	// dynamic mesh normal vectors, tangent vectors and a mesh bounding box calculation
	engine.profiler.begin("mesh");
	mesh.updateBounds();
	mesh.updateTangents();
	mesh.flushVertex();
	// stop the counter
	engine.profiler.end();
	
	return 1;
}

Profiler Class

Members


void engine.profiler.setEnabled(int enabled)

Enables or disables the profiler.

Arguments

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

int engine.profiler.isEnabled()

Returns a value indicating if the profiler is enabled.

Return value

1 if the profiler is enabled; otherwise, 0.

float engine.profiler.getValue(string name)

Returns a value of the specified counter.

Arguments

  • string name - The name of the counter.

Return value

Value of the counter in milliseconds.

void engine.profiler.begin(string name, vec4 color)

Starts a counter with a given name and shows a colored graph (if the show_profiler 2 console variable is set). The counter shows the user how many millisecods have been spent for the operation that is peformed between the engine.profiler.begin() and the engine.profiler.end() functions.
Source code (UnigineScript)
int size = 128;
ObjectMeshDynamic mesh;
// ... 
float time = engine.game.getTime();
// start the counter that shows the time spent for dymanic mesh grid calculation
engine.profiler.begin("grid",vec4(1.0f));
// modify a mesh grid
forloop(int y = 0, i = 0; size) {
	float Y = y * isize - 15.0f;
	float Z = cos(Y + time);
	forloop(int x = 0; size) {
		float X = x * isize - 15.0f;
		mesh.setVertex(i++,vec3(X,Y,Z * sin(X + time)));
	}
}
// stop the counter
engine.profiler.end();

Arguments

  • string name - Name of the counter.
  • vec4 color - Color of the graph.

void engine.profiler.begin(string name)

Starts a counter with a given name. The counter shows the user how many millisecods have been spent for the operation that is peformed between the engine.profiler.begin() and the engine.profiler.end() functions.
Source code (UnigineScript)
ObjectMeshDynamic mesh;
// ...
// start the counter that shows the time spent for 
// dynamic mesh normal vectors, tangent vectors and a mesh bounding box calculation
engine.profiler.begin("mesh");
mesh.updateBounds();
mesh.updateTangents();
mesh.flushVertex();
// stop the counter
engine.profiler.end();

Arguments

  • string name - Name of the counter.

float engine.profiler.end()

Stops the last activated counter and returns its value.

Return value

Value of the counter in milliseconds.

string engine.profiler.getMicroprofileUrl()

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.

Gui engine.profiler.getGui()

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

Return value

Pointer to the GUI.

void engine.profiler.setGui(Gui gui)

Sets the GUI for the engine Performance Profiler

Arguments

  • Gui gui - A pointer to the GUI class instance.
Last update: 2018-08-10
Build: ()