Difference between revisions of "Core.enableAllocationTracking"

From GiderosMobile
m (Text replacement - "</source>" to "</syntaxhighlight>")
 
(One intermediate revision by the same user not shown)
Line 5: Line 5:
 
=== Description ===
 
=== Description ===
 
Enables objects allocation profiler.
 
Enables objects allocation profiler.
<source lang="lua">
+
<syntaxhighlight lang="lua">
 
(table) = Core.enableAllocationTracking(b)
 
(table) = Core.enableAllocationTracking(b)
</source>
+
</syntaxhighlight>
  
 
=== Parameters ===
 
=== Parameters ===
Line 16: Line 16:
  
 
=== Example ===
 
=== Example ===
<source lang="lua">
+
<syntaxhighlight lang="lua">
 
-- start the profiler
 
-- start the profiler
 
Core.enableAllocationTracking(true)
 
Core.enableAllocationTracking(true)
Line 32: Line 32:
 
for _,k in ipairs(sort) do print(counts[k],k) end
 
for _,k in ipairs(sort) do print(counts[k],k) end
 
end
 
end
</source>
+
</syntaxhighlight>
  
 
{{Core}}
 
{{Core}}

Latest revision as of 15:27, 13 July 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