util.monitor.register

Client

Registers a custom stat with a user-supplied sampler function


Syntax

local status = util.monitor.register(
    id,
    name,
    exec,
    format
)

Scoped to the registering environment — automatically cleaned up on environment destruction.

  • Unique IDs — if id already exists, returns false; use util.monitor.unregister first to replace it.
  • Sampler functionexec is called by Godot's Performance singleton on demand and must return a single number.
  • Godot integration — registered stats appear in Godot's built-in performance profiler alongside native stats.

Parameters

TypeNameDescription
stringidUnique string identifier for this stat
stringnameHuman-readable display name shown in the Godot profiler
functionexecSampler function invoked to read the current value
Must return a single number
util.monitor.stat_formatformatDisplay format for the value in the profiler

Returns

TypeNameDescription
boolstatustrue on successful registration, false otherwise

Examples

Register a simple quantity stat
util.monitor.register("my_resource:entity_count", "Entity Count", function()
    return entity_manager.count()
end, util.monitor.stat_format.QUANTITY)
Register a memory usage stat
util.monitor.register("my_resource:cache_size", "Cache Size", function()
    return cache.byte_size()
end, util.monitor.stat_format.MEMORY)
Register a percentage stat
util.monitor.register("my_resource:cpu_load", "CPU Load", function()
    return profiler.get_load()
end, util.monitor.stat_format.PERCENTAGE)
Guard against duplicate registration
local ok = util.monitor.register("my_resource:tick_rate", "Tick Rate", function()
    return tick_system.get_rate()
end, util.monitor.stat_format.QUANTITY)

if not ok then
    core.engine.print("warn", "Stat already registered")
end

On this page