Difference between revisions of "Core.enableAllocationTracking"
From GiderosMobile
(Created page with "'''Available since:''' Gideros 2023.1<br/> '''Class:''' Core<br/> === Description === Enables profiling objects allocation. <source lang="lua"> Core.enableAllocationTrack...") |
|||
Line 1: | Line 1: | ||
+ | __NOTOC__ | ||
'''Available since:''' Gideros 2023.1<br/> | '''Available since:''' Gideros 2023.1<br/> | ||
'''Class:''' [[Core]]<br/> | '''Class:''' [[Core]]<br/> | ||
=== Description === | === Description === | ||
− | Enables | + | Enables objects allocation profiler. |
<source lang="lua"> | <source lang="lua"> | ||
− | Core.enableAllocationTracking() | + | (table) = Core.enableAllocationTracking(b) |
+ | </source> | ||
+ | |||
+ | === Parameters === | ||
+ | '''b''': (boolean) true to start the profiler, false to stop the profiler and create the table<br/> | ||
+ | |||
+ | === Return values === | ||
+ | '''Returns''' (table) table with data<br/> | ||
+ | |||
+ | === Example === | ||
+ | <source lang="lua"> | ||
+ | -- start the profiler | ||
+ | Core.enableAllocationTracking(true) | ||
+ | |||
+ | -- do stuff... | ||
+ | |||
+ | -- end the profiler and create table | ||
+ | local t=Core.enableAllocationTracking(false) | ||
+ | if t then | ||
+ | local counts={} | ||
+ | for k,v in pairs(t) do counts[v]=(counts[v] or 0)+1 end | ||
+ | local sort={} | ||
+ | for k,_ in pairs(counts) do table.insert(sort,k) end | ||
+ | table.sort(sort,function(a,b) return counts[a]>counts[b] end) | ||
+ | for _,k in ipairs(sort) do print(counts[k],k) end | ||
+ | end | ||
</source> | </source> | ||
{{Core}} | {{Core}} |
Revision as of 18:59, 19 January 2023
Available since: Gideros 2023.1
Class: Core
Description
Enables objects allocation profiler.
(table) = Core.enableAllocationTracking(b)
Parameters
b: (boolean) true to start the profiler, false to stop the profiler and create the table
Return values
Returns (table) table with data
Example
-- start the profiler
Core.enableAllocationTracking(true)
-- do stuff...
-- end the profiler and create table
local t=Core.enableAllocationTracking(false)
if t then
local counts={}
for k,v in pairs(t) do counts[v]=(counts[v] or 0)+1 end
local sort={}
for k,_ in pairs(counts) do table.insert(sort,k) end
table.sort(sort,function(a,b) return counts[a]>counts[b] end)
for _,k in ipairs(sort) do print(counts[k],k) end
end