factor/library/tools/heap-stats.factor

36 lines
954 B
Factor
Raw Normal View History

2005-02-14 21:58:07 -05:00
! Copyright (C) 2004, 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: memory
USING: kernel lists math namespaces prettyprint stdio words
vectors unparser generic ;
2004-11-25 21:53:27 -05:00
2005-02-14 21:58:07 -05:00
: kb. 1024 /i unparse write " KB" write ;
2004-11-25 21:53:27 -05:00
2005-02-14 21:58:07 -05:00
: (room.) ( free total -- )
2dup swap - swap ( free used total )
kb. " total " write
kb. " used " write
kb. " free" print ;
: room. ( -- )
room
"Data space: " write (room.)
"Code space: " write (room.) ;
2004-11-25 21:53:27 -05:00
: heap-stat. ( type instances bytes -- )
dup 0 = [
3drop
] [
2004-12-27 22:58:43 -05:00
rot builtin-type word-name write ": " write
2004-11-25 21:53:27 -05:00
unparse write " bytes, " write
unparse write " instances" print
] ifte ;
: heap-stats. ( -- )
#! Print heap allocation breakdown.
0 heap-stats [ dupd uncons heap-stat. 1 + ] each drop ;
2005-02-14 21:58:07 -05:00
: instances ( class -- list )
#! Return a list of all instances of a built-in class.
"builtin-type" word-property (instances) ;