leak detector: sort type based entries by total used bytes
This commit is contained in:
parent
03b7df74a9
commit
6f6551d77d
1 changed files with 28 additions and 2 deletions
|
|
@ -18,12 +18,38 @@ proc protect*(x: pointer): ForeignCell =
|
||||||
result.owner = addr(gch)
|
result.owner = addr(gch)
|
||||||
|
|
||||||
when defined(nimTypeNames):
|
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* =
|
proc dumpNumberOfInstances* =
|
||||||
|
var a: InstancesInfo
|
||||||
|
var n = 0
|
||||||
var it = nimTypeRoot
|
var it = nimTypeRoot
|
||||||
while it != nil:
|
while it != nil:
|
||||||
if it.instances > 0:
|
if it.instances > 0 and n < a.len:
|
||||||
c_fprintf(stdout, "[Heap] %s: #%ld; bytes: %ld\n", it.name, it.instances, it.sizes)
|
a[n] = (it.name, it.instances, it.sizes)
|
||||||
|
inc n
|
||||||
it = it.nextType
|
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):
|
when defined(nimGcRefLeak):
|
||||||
proc oomhandler() =
|
proc oomhandler() =
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue