- Documentation
- Shared functions
- getResourceUsage
Function
getResourceUsage
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
getGamePerformanceReturns the game's performance for this player since the previous read (a window of at least 250 ms): FPS, average and longest frame time, script time per frame, the game's CPU and memory use, and ping. Which resource costs the most is shown bygetResourceUsage.getServerPerformanceReturns the server load since the previous read (a window of at least 250 ms): CPU, server loop delay, memory and player count. A large loop delay (loopMaxMs) is what players see as stuttering characters and cars.getPerformanceStatsReturns server statistics as columns and rows. Without a category: uptime, players, vehicles, objects, timers, resources and the number of API functions. The"Lua timing"category gives the script time of each resource (CPU, calls per second, longest call, allocated memory); the filter narrows it to resources whose name contains that text.