! Copyright (C) 2005, 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: kernel sequences arrays generic assocs io math namespaces parser prettyprint strings io.styles words system sorting splitting grouping math.parser classes memory combinators fry vm specialized-arrays accessors continuations classes.struct ; SPECIALIZED-ARRAY: gc-event IN: tools.memory string dup length 4 > [ 3 cut* "," glue ] when " KB" append ; : fancy-table. ( obj alist -- ) [ [ nip first ] [ second call( obj -- str ) ] 2bi 2array ] with map simple-table. ; : copying-room. ( copying-sizes -- ) { { "Size:" [ size>> kilobytes ] } { "Occupied:" [ occupied>> kilobytes ] } { "Free:" [ free>> kilobytes ] } } fancy-table. ; : nursery-room. ( data-room -- ) "- Nursery space" print nursery>> copying-room. ; : aging-room. ( data-room -- ) "- Aging space" print aging>> copying-room. ; : mark-sweep-table. ( mark-sweep-sizes -- ) { { "Size:" [ size>> kilobytes ] } { "Occupied:" [ occupied>> kilobytes ] } { "Total free:" [ total-free>> kilobytes ] } { "Contiguous free:" [ contiguous-free>> kilobytes ] } { "Free block count:" [ free-block-count>> number>string ] } } fancy-table. ; : tenured-room. ( data-room -- ) "- Tenured space" print tenured>> mark-sweep-table. ; : misc-room. ( data-room -- ) "- Miscellaneous buffers" print { { "Card array:" [ cards>> kilobytes ] } { "Deck array:" [ decks>> kilobytes ] } { "Mark stack:" [ mark-stack>> kilobytes ] } } fancy-table. ; : data-room. ( -- ) "==== DATA HEAP" print nl data-room data-heap-room memory>struct { [ nursery-room. nl ] [ aging-room. nl ] [ tenured-room. nl ] [ misc-room. ] } cleave ; : code-room. ( -- ) "==== CODE HEAP" print nl code-room mark-sweep-sizes memory>struct mark-sweep-table. ; PRIVATE> : room. ( -- ) data-room. nl code-room. ; : heap-stats ( -- counts sizes ) [ ] instances H{ } clone H{ } clone [ '[ _ _ heap-stat-step ] each ] 2keep ; : heap-stats. ( -- ) heap-stats dup keys natural-sort standard-table-style [ [ { "Class" "Bytes" "Instances" } [ write-cell ] each ] with-row [ [ dup pprint-cell dup pick at pprint-cell pick at pprint-cell ] with-row ] each 2drop ] tabular-output nl ; : collect-gc-events ( quot -- events ) enable-gc-events [ ] [ disable-gc-events drop ] cleanup disable-gc-events byte-array>gc-event-array ;