GetProcessMemoryStats

From Multi Theft Auto: Wiki
Revision as of 14:12, 3 November 2022 by Botder (talk | contribs) (Created page with "__NOTOC__ {{Shared function}} {{Added feature/item|1.6.0|1.5.9|21389|This function returns a breakdown of the process memory usage. The reported numbers are always byte units and these numbers can be '''inaccurate'''.}} ==Syntax== <syntaxhighlight lang="lua"> table|nil getProcessMemoryStats ( ) </syntaxhighlight> ==Returns== Returns a table if successful, otherwise returns '''nil''' {| class="wikitable" style="cellpadding: 10px;" |- ! Property || Description |- | <c...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This function returns a breakdown of the process memory usage. The reported numbers are always byte units and these numbers can be inaccurate.

Syntax

table|nil getProcessMemoryStats ( )

Returns

Returns a table if successful, otherwise returns nil

Property Description
virtual total program size
resident resident set size (memory in physical space/ram, also known as working set)
shared size of resident shared memory (shared with other processes)
private size of resident private memory (only for this process)

Note: Resident set size should be roughly shared + private from the table.

Example

This example will output the memory usage by the server process to the console every 5 minutes.

Click to collapse [-]
Server
setTimer(function()
    local div = 1024^2

    local pmem = getProcessMemoryStats()

    if pmem then
        outputServerLog(("[SYS] %.2f MiB  rss:%.2f MiB  shr:%.2f MiB  prv:%.2f MiB"):format(
            pmem.virtual / div,
            pmem.resident / div,
            pmem.shared / div,
            pmem.private / div
        ))
    end
end, 5 * 60000, 0)

See Also