1 ! Copyright (C) 2005, 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel sequences vectors arrays generic assocs io math
4 namespaces parser prettyprint strings io.styles vectors words
5 system sorting splitting grouping math.parser classes memory
13 dup length 4 > [ 3 cut* "," glue ] when
14 " KB" append write-cell ;
16 : write-total/used/free ( free total str -- )
24 : write-total ( n str -- )
32 : write-headings ( seq -- )
33 [ [ write-cell ] each ] with-row ;
36 data-room 2 <groups> [
37 [ first2 ] [ number>string "Generation " prepend ] bi*
43 : write-labelled-size ( n string -- )
44 [ write-cell write-size ] with-row ;
48 [ "Size:" write-labelled-size ]
49 [ "Used:" write-labelled-size ]
50 [ "Total free space:" write-labelled-size ]
51 [ "Largest free block:" write-labelled-size ]
54 : heap-stat-step ( obj counts sizes -- )
56 [ [ class ] dip inc-at ]
57 [ [ [ size ] [ class ] bi ] dip at+ ] 2bi* ;
62 "==== DATA HEAP" print
63 standard-table-style [
64 { "" "Total" "Used" "Free" } write-headings
68 "==== CODE HEAP" print
69 standard-table-style [
73 : heap-stats ( -- counts sizes )
75 2dup '[ _ _ heap-stat-step ] each-object ;
78 heap-stats dup keys natural-sort standard-table-style [
79 { "Class" "Bytes" "Instances" } write-headings
83 dup pick at pprint-cell