Class PerformanceInstance
- Namespace
- Godot
- Assembly
- GodotSharp.dll
This class provides access to a number of different monitors related to performance, such as memory usage, draw calls, and FPS. These are the same as the values displayed in the Monitor tab in the editor's Debugger panel. By using the GetMonitor(Monitor) method of this class, you can access this data from your code.
You can add custom monitors using the AddCustomMonitor(StringName, Callable, Array) method. Custom monitors are available in Monitor tab in the editor's Debugger panel together with built-in monitors.
Note: Some of the built-in monitors are only available in debug mode and will always return 0 when used in a project exported in release mode.
Note: Some of the built-in monitors are not updated in real-time for performance reasons, so there may be a delay of up to 1 second between changes.
Note: Custom monitors do not support negative values. Negative values are clamped to 0.
[GodotClassName("Performance")]
public class PerformanceInstance : GodotObject, IDisposable
- Inheritance
-
PerformanceInstance
- Implements
- Inherited Members
Methods
AddCustomMonitor(StringName, Callable, Array)
Adds a custom monitor with the name id. You can specify the category of the monitor using slash delimiters in id (for example: "Game/NumberOfNPCs"). If there is more than one slash delimiter, then the default category is used. The default category is "Custom". Prints an error if given id is already present.
public override void _Ready()
{
var monitorValue = new Callable(this, MethodName.GetMonitorValue);
// Adds monitor with name "MyName" to category "MyCategory".
Performance.AddCustomMonitor("MyCategory/MyMonitor", monitorValue);
// Adds monitor with name "MyName" to category "Custom".
// Note: "MyCategory/MyMonitor" and "MyMonitor" have same name but different ids so the code is valid.
Performance.AddCustomMonitor("MyMonitor", monitorValue);
// Adds monitor with name "MyName" to category "Custom".
// Note: "MyMonitor" and "Custom/MyMonitor" have same name and same category but different ids so the code is valid.
Performance.AddCustomMonitor("Custom/MyMonitor", monitorValue);
// Adds monitor with name "MyCategoryOne/MyCategoryTwo/MyMonitor" to category "Custom".
Performance.AddCustomMonitor("MyCategoryOne/MyCategoryTwo/MyMonitor", monitorValue);
}
public int GetMonitorValue()
{
return GD.Randi() % 25;
}
The debugger calls the callable to get the value of custom monitor. The callable must return a zero or positive integer or floating-point number.
Callables are called with arguments supplied in argument array.
public void AddCustomMonitor(StringName id, Callable callable, Array arguments = null)
Parameters
idStringNamecallableCallableargumentsArray
GetCustomMonitor(StringName)
Returns the value of custom monitor with given id. The callable is called to get the value of custom monitor. See also HasCustomMonitor(StringName). Prints an error if the given id is absent.
public Variant GetCustomMonitor(StringName id)
Parameters
idStringName
Returns
GetCustomMonitorNames()
Returns the names of active custom monitors in an Array.
public Array<StringName> GetCustomMonitorNames()
Returns
GetMonitor(Monitor)
Returns the value of one of the available built-in monitors. You should provide one of the Performance.Monitor constants as the argument, like this:
GD.Print(Performance.GetMonitor(Performance.Monitor.TimeFps)); // Prints the FPS to the console.
See GetCustomMonitor(StringName) to query custom performance monitors' values.
public double GetMonitor(Performance.Monitor monitor)
Parameters
monitorPerformance.Monitor
Returns
GetMonitorModificationTime()
Returns the last tick in which custom monitor was added/removed (in microseconds since the engine started). This is set to GetTicksUsec() when the monitor is updated.
public ulong GetMonitorModificationTime()
Returns
HasCustomMonitor(StringName)
Returns true if custom monitor with the given id is present, false otherwise.
public bool HasCustomMonitor(StringName id)
Parameters
idStringName
Returns
HasGodotClassMethod(in godot_string_name)
Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.
protected override bool HasGodotClassMethod(in godot_string_name method)
Parameters
methodgodot_string_nameName of the method to check for.
Returns
HasGodotClassSignal(in godot_string_name)
Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.
protected override bool HasGodotClassSignal(in godot_string_name signal)
Parameters
signalgodot_string_nameName of the signal to check for.
Returns
InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)
Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.
protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)
Parameters
methodgodot_string_nameName of the method to invoke.
argsNativeVariantPtrArgsArguments to use with the invoked method.
retgodot_variantValue returned by the invoked method.
Returns
RemoveCustomMonitor(StringName)
Removes the custom monitor with given id. Prints an error if the given id is already absent.
public void RemoveCustomMonitor(StringName id)
Parameters
idStringName