ServersYour serverFor creatorsForumFAQDocumentationSecurity
Download the launcher
  1. Documentation
  2. Shared functions
  3. getResourceUsage

Function

getResourceUsage

Server and clientResourcesTrilogy Hub only

Shows how much CPU time and memory the scripts of each resource use: event handlers, timers, commands and exports. It measures since the previous read (the shortest window is 1 s, a more frequent read gets the previous result). On the server it covers server resources; on the client it covers the resources running for the player and also gives the time per rendered frame. The /stats panel of the default stats resource works this way.

Syntax

table, table getResourceUsage()

Returns

Rows from the most expensive: { resource, ms, cpu, msPerFrame, calls, maxMs, allocKB, timers, handlers, system, textureKB, modelKB, top } (ms = ms per second, cpu = % of one core, allocKB = KB allocated per second; textureKB and modelKB on the client only: KB of script texture memory and of file models held by the resource) and a summary { seconds, ms, cpu, msPerFrame, fps, luaKB, textureKB, modelKB }. The system row is the platform's own code. top lists up to 5 most expensive handlers of the resource { name, ms, calls, maxMs } (an event, timer, command or wczytanie pliku … = loading a file at start).

Example

setTimer(function()
    local rows = getResourceUsage()
    local top = rows[1]
    if top and top.msPerFrame > 2 then
        outputChatBox(("%s: %.2f ms na klatke"):format(top.resource, top.msPerFrame))
    end
end, 5000, 0)

See also