This page has been translated automatically.
Video Tutorials
Interface
Essentials
Advanced
How To
Professional (SIM)
UnigineEditor
Interface Overview
Assets Workflow
Settings and Preferences
Working With Projects
Adjusting Node Parameters
Setting Up Materials
Setting Up Properties
Lighting
Sandworm
Using Editor Tools for Specific Tasks
Extending Editor Functionality
Built-in Node Types
Nodes
Objects
Effects
Decals
Light Sources
Geodetics
World Nodes
Sound Objects
Pathfinding Objects
Players
Programming
Fundamentals
Setting Up Development Environment
Usage Examples
C++
C#
UnigineScript
UUSL (Unified UNIGINE Shader Language)
Plugins
File Formats
Materials and Shaders
Rebuilding the Engine Tools
GUI
Double Precision Coordinates
API
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
Content Creation
Content Optimization
Materials
Material Nodes Library
Miscellaneous
Input
Math
Matrix
Textures
Art Samples
Tutorials
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.

Unigine.Profiler Class

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.

A dynamic mesh is created in Init and then modified on the engine update. All counters are created in Update(), too.

Source code (C#)
using System;
using System.Collections;
using System.Collections.Generic;
using Unigine;

#region Math Variables
#if UNIGINE_DOUBLE
using Scalar = System.Double;
using Vec3 = Unigine.dvec3;
#else
using Scalar = System.Single;
using Vec3 = Unigine.vec3;
#endif
#endregion

[Component(PropertyGuid = "AUTOGENERATED_GUID")] // <-- this line is generated automatically for a new component
public class ProfilerClass : Component
{
	// declare variables
	
	int size = 128;
	
	
    ObjectMeshDynamic mesh;

	
	private void Init()
	{
		// create a dynamic mesh
		mesh = new ObjectMeshDynamic(ObjectMeshDynamic.DYNAMIC_VERTEX | ObjectMeshDynamic.IMMUTABLE_INDICES);
		// set the mesh settings
		mesh.WorldTransform = MathLib.Translate(new 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(new vec3(0));
				mesh.AddTexCoord(new 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++;
			}
		}
	}
	
	private void Update()
	{

		// initialize the graph color
		float[] color = new float [4] {1.0f,1.0f,1.0f,1.0f};

		// add a counter that shows time spent between the previous frame update and the current one
		Profiler.SetValue("Frame update time", "s", Game.Time, 1.0f, color);

		float time = Game.Time;
		float isize = 30.0f / size;
		// start the counter that shows the time spent for dymanic mesh grid modifying
		Profiler.Begin("Grid", new 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 = MathLib.Cos(Y + time);
				for (int x = 0; x < size; x++)
				{
					float X = x * isize - 15.0f;
					mesh.SetVertex(i++, new vec3(X, Y, Z * MathLib.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.NumVertex, 20000, null);	

	}
}

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

See Also#

Profiler Class

Properties

Gui Gui#

The pointer to the GUI of the engine Performance Profiler.

bool Enabled#

Console: show_profiler
The value indicating if the profiler is enabled.

string MicroprofileUrl#

The microprofile web server url.

Members


void SetValue ( string name, string units, int value, int max_value, float[] arg5 ) #

Updates settings of the integer counter.
Source code (C#)
// initialize the graph color
float[] color = new float [4] {1.0f,1.0f,1.0f,1.0f};

// add a counter without a graph
Profiler.SetValue("Random value 1", "", new System.Random().Next(0,5), 4, null);
// add a counter with a colored graph
Profiler.SetValue("Random value 2", "", new System.Random().Next(0,10), 9, color);

Arguments

  • string name - Name of the counter.
  • string units - Counter units.
  • int value - Value of the counter.
  • int max_value - Counter maximum value.
  • float[] arg5 - Color of the graph. Pass NULL if no graph is required.

void SetValue ( string name, string units, float value, float max_value, float[] arg5 ) #

Updates settings of the float counter.
Source code (C#)
// initialize the graph color
float[] color = new float [4] {1.0f,1.0f,1.0f,1.0f};

float rvalue = (float)new System.Random().NextDouble() * 1;
// add a counter without a graph
Profiler.SetValue("Random value 1", "", rvalue, 1.0f, null);
// add a counter with a colored graph
Profiler.SetValue("Random value 2", "", 1 + rvalue, 10.0f, color);

Arguments

  • string name - Name of the counter.
  • string units - Counter units.
  • float value - Value of the counter.
  • float max_value - Counter maximum value.
  • float[] arg5 - Color of the graph. Pass NULL if no graph is required.

float 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 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 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;

    ObjectMeshDynamic mesh;


	float time = Game.Time;
	float isize = 30.0f / size;
	// start the counter that shows the time spent for dymanic mesh grid modifying
	Profiler.Begin("Grid", new 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 = MathLib.Cos(Y + time);
			for (int x = 0; x < size; x++)
			{
				float X = x * isize - 15.0f;
				mesh.SetVertex(i++, new vec3(X, Y, Z * MathLib.Sin(X + time)));
			}
		}
	}
	// stop the counter
	Profiler.End();

Arguments

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

void Begin ( string name ) #

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#)
ObjectMeshDynamic 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

  • string name - Name of the counter.

float End ( ) #

Stops the last activated counter and returns its value.

Return value

Value of the counter in milliseconds.

int BeginMicro ( string name, bool gpu = 0 ) #

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#)
ObjectMeshDynamic 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

  • string 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 ) #

Stops a previously activated Microprofile counter with the specified ID.

Arguments

  • int id - Microprofile counter ID.
Last update: 2022-12-14
Build: ()