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* "," swap 3append ] 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 ( counts sizes obj -- )
55 [ dup size swap class rot at+ ] keep
56 1 swap class rot at+ ;
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 )
74 [ >r 2dup r> heap-stat-step ] each-object ;
77 heap-stats dup keys natural-sort standard-table-style [
78 { "Class" "Bytes" "Instances" } write-headings
82 dup pick at pprint-cell