M&S GC gets the heap dump feature
This commit is contained in:
parent
e216e0debd
commit
03916fa3b1
3 changed files with 76 additions and 69 deletions
|
|
@ -17,6 +17,30 @@ proc protect*(x: pointer): ForeignCell =
|
|||
result.data = x
|
||||
result.owner = addr(gch)
|
||||
|
||||
when defined(nimTypeNames):
|
||||
proc dumpNumberOfInstances* =
|
||||
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)
|
||||
it = it.nextType
|
||||
|
||||
template decTypeSize(cell, t) =
|
||||
when defined(nimTypeNames):
|
||||
if t.kind in {tyString, tySequence}:
|
||||
let len = cast[PGenericSeq](cellToUsr(cell)).len
|
||||
let base = if t.kind == tyString: 1 else: t.base.size
|
||||
let size = addInt(mulInt(len, base), GenericSeqSize)
|
||||
dec t.sizes, size+sizeof(Cell)
|
||||
else:
|
||||
dec t.sizes, t.size+sizeof(Cell)
|
||||
dec t.instances
|
||||
|
||||
template incTypeSize(typ, size) =
|
||||
when defined(nimTypeNames):
|
||||
inc typ.instances
|
||||
inc typ.sizes, size+sizeof(Cell)
|
||||
|
||||
proc dispose*(x: ForeignCell) =
|
||||
when hasThreadSupport:
|
||||
# if we own it we can free it directly:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue