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-labeled-size ( n string -- )
44 [ write-cell write-size ] with-row ;
48 [ "Size:" write-labeled-size ]
49 [ "Used:" write-labeled-size ]
50 [ "Total free space:" write-labeled-size ]
51 [ "Largest free block:" write-labeled-size ]
54 : heap-stat-step ( obj counts sizes -- )
55 [ [ class ] dip inc-at ]
56 [ [ [ size ] [ class ] bi ] dip at+ ] bi-curry* bi ;
61 "==== DATA HEAP" print
62 standard-table-style [
63 { "" "Total" "Used" "Free" } write-headings
67 "==== CODE HEAP" print
68 standard-table-style [
72 : heap-stats ( -- counts sizes )
73 [ ] instances H{ } clone H{ } clone
74 [ '[ _ _ heap-stat-step ] each ] 2keep ;
77 heap-stats dup keys natural-sort standard-table-style [
78 { "Class" "Bytes" "Instances" } write-headings
82 dup pick at pprint-cell