mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-17 16:38:33 +00:00
leak detector: sort type based entries by total used bytes
This commit is contained in:
@@ -18,12 +18,38 @@ proc protect*(x: pointer): ForeignCell =
|
||||
result.owner = addr(gch)
|
||||
|
||||
when defined(nimTypeNames):
|
||||
type InstancesInfo = array[400, (cstring, int, int)]
|
||||
proc sortInstances(a: var InstancesInfo; n: int) =
|
||||
# we use shellsort here; fast and simple
|
||||
var h = 1
|
||||
while true:
|
||||
h = 3 * h + 1
|
||||
if h > n: break
|
||||
while true:
|
||||
h = h div 3
|
||||
for i in countup(h, n - 1):
|
||||
var v = a[i]
|
||||
var j = i
|
||||
while a[j - h][2] < v[2]:
|
||||
a[j] = a[j - h]
|
||||
j = j - h
|
||||
if j < h: break
|
||||
a[j] = v
|
||||
if h == 1: break
|
||||
|
||||
proc dumpNumberOfInstances* =
|
||||
var a: InstancesInfo
|
||||
var n = 0
|
||||
var it = nimTypeRoot
|
||||
while it != nil:
|
||||
if it.instances > 0:
|
||||
c_fprintf(stdout, "[Heap] %s: #%ld; bytes: %ld\n", it.name, it.instances, it.sizes)
|
||||
if it.instances > 0 and n < a.len:
|
||||
a[n] = (it.name, it.instances, it.sizes)
|
||||
inc n
|
||||
it = it.nextType
|
||||
sortInstances(a, n)
|
||||
for i in 0 .. n-1:
|
||||
c_fprintf(stdout, "[Heap] %s: #%ld; bytes: %ld\n", a[i][0], a[i][1], a[i][2])
|
||||
|
||||
|
||||
when defined(nimGcRefLeak):
|
||||
proc oomhandler() =
|
||||
|
||||
Reference in New Issue
Block a user