2009-10-25 14:18:06 -04:00
|
|
|
! Copyright (C) 2005, 2009 Slava Pestov.
|
2007-09-20 18:09:08 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2009-05-16 11:45:17 -04:00
|
|
|
USING: kernel sequences arrays generic assocs io math
|
|
|
|
namespaces parser prettyprint strings io.styles words
|
2008-06-09 06:22:21 -04:00
|
|
|
system sorting splitting grouping math.parser classes memory
|
2009-10-27 04:32:28 -04:00
|
|
|
combinators fry vm specialized-arrays accessors continuations
|
2009-10-27 17:31:45 -04:00
|
|
|
classes.struct generalizations ;
|
2009-10-27 04:32:28 -04:00
|
|
|
SPECIALIZED-ARRAY: gc-event
|
2007-09-20 18:09:08 -04:00
|
|
|
IN: tools.memory
|
|
|
|
|
2008-04-07 22:04:51 -04:00
|
|
|
<PRIVATE
|
|
|
|
|
2009-10-25 14:18:06 -04:00
|
|
|
: kilobytes ( n -- str )
|
2009-10-26 23:08:35 -04:00
|
|
|
1024 /i number>string
|
2008-12-03 20:10:41 -05:00
|
|
|
dup length 4 > [ 3 cut* "," glue ] when
|
2009-10-25 14:18:06 -04:00
|
|
|
" KB" append ;
|
|
|
|
|
2009-10-27 04:32:28 -04:00
|
|
|
: fancy-table. ( obj alist -- )
|
|
|
|
[ [ nip first ] [ second call( obj -- str ) ] 2bi 2array ] with map
|
2009-10-26 23:08:35 -04:00
|
|
|
simple-table. ;
|
2009-10-25 14:18:06 -04:00
|
|
|
|
2009-10-27 04:32:28 -04:00
|
|
|
: copying-room. ( copying-sizes -- )
|
2009-10-26 23:08:35 -04:00
|
|
|
{
|
2009-10-27 04:32:28 -04:00
|
|
|
{ "Size:" [ size>> kilobytes ] }
|
|
|
|
{ "Occupied:" [ occupied>> kilobytes ] }
|
|
|
|
{ "Free:" [ free>> kilobytes ] }
|
2009-10-26 23:08:35 -04:00
|
|
|
} fancy-table. ;
|
2009-10-25 14:18:06 -04:00
|
|
|
|
2009-10-27 04:32:28 -04:00
|
|
|
: nursery-room. ( data-room -- )
|
|
|
|
"- Nursery space" print nursery>> copying-room. ;
|
2009-10-25 14:18:06 -04:00
|
|
|
|
2009-10-27 04:32:28 -04:00
|
|
|
: aging-room. ( data-room -- )
|
|
|
|
"- Aging space" print aging>> copying-room. ;
|
2009-10-25 14:18:06 -04:00
|
|
|
|
2009-10-27 04:32:28 -04:00
|
|
|
: mark-sweep-table. ( mark-sweep-sizes -- )
|
2009-10-26 23:08:35 -04:00
|
|
|
{
|
2009-10-27 04:32:28 -04:00
|
|
|
{ "Size:" [ size>> kilobytes ] }
|
|
|
|
{ "Occupied:" [ occupied>> kilobytes ] }
|
|
|
|
{ "Total free:" [ total-free>> kilobytes ] }
|
|
|
|
{ "Contiguous free:" [ contiguous-free>> kilobytes ] }
|
|
|
|
{ "Free block count:" [ free-block-count>> number>string ] }
|
2009-10-26 23:08:35 -04:00
|
|
|
} fancy-table. ;
|
2009-10-25 14:18:06 -04:00
|
|
|
|
2009-10-27 04:32:28 -04:00
|
|
|
: tenured-room. ( data-room -- )
|
|
|
|
"- Tenured space" print tenured>> mark-sweep-table. ;
|
2009-10-25 14:18:06 -04:00
|
|
|
|
2009-10-27 04:32:28 -04:00
|
|
|
: misc-room. ( data-room -- )
|
2009-10-25 14:18:06 -04:00
|
|
|
"- Miscellaneous buffers" print
|
2009-10-26 23:08:35 -04:00
|
|
|
{
|
2009-10-27 04:32:28 -04:00
|
|
|
{ "Card array:" [ cards>> kilobytes ] }
|
|
|
|
{ "Deck array:" [ decks>> kilobytes ] }
|
|
|
|
{ "Mark stack:" [ mark-stack>> kilobytes ] }
|
2009-10-26 23:08:35 -04:00
|
|
|
} fancy-table. ;
|
2009-10-25 14:18:06 -04:00
|
|
|
|
|
|
|
: data-room. ( -- )
|
|
|
|
"==== DATA HEAP" print nl
|
2009-10-27 04:32:28 -04:00
|
|
|
data-room data-heap-room memory>struct {
|
|
|
|
[ nursery-room. nl ]
|
|
|
|
[ aging-room. nl ]
|
|
|
|
[ tenured-room. nl ]
|
|
|
|
[ misc-room. ]
|
|
|
|
} cleave ;
|
2009-10-25 14:18:06 -04:00
|
|
|
|
|
|
|
: code-room. ( -- )
|
|
|
|
"==== CODE HEAP" print nl
|
2009-10-27 04:32:28 -04:00
|
|
|
code-room mark-sweep-sizes memory>struct mark-sweep-table. ;
|
|
|
|
|
|
|
|
PRIVATE>
|
|
|
|
|
|
|
|
: room. ( -- ) data-room. nl code-room. ;
|
|
|
|
|
|
|
|
<PRIVATE
|
2008-04-07 22:04:51 -04:00
|
|
|
|
2008-12-03 09:46:16 -05:00
|
|
|
: heap-stat-step ( obj counts sizes -- )
|
2008-12-09 17:54:48 -05:00
|
|
|
[ [ class ] dip inc-at ]
|
2009-02-02 14:43:54 -05:00
|
|
|
[ [ [ size ] [ class ] bi ] dip at+ ] bi-curry* bi ;
|
2008-04-07 22:04:51 -04:00
|
|
|
|
|
|
|
PRIVATE>
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
: heap-stats ( -- counts sizes )
|
2009-02-16 18:04:58 -05:00
|
|
|
[ ] instances H{ } clone H{ } clone
|
|
|
|
[ '[ _ _ heap-stat-step ] each ] 2keep ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
: heap-stats. ( -- )
|
|
|
|
heap-stats dup keys natural-sort standard-table-style [
|
2009-10-25 14:18:06 -04:00
|
|
|
[ { "Class" "Bytes" "Instances" } [ write-cell ] each ] with-row
|
2007-09-20 18:09:08 -04:00
|
|
|
[
|
|
|
|
[
|
|
|
|
dup pprint-cell
|
|
|
|
dup pick at pprint-cell
|
|
|
|
pick at pprint-cell
|
|
|
|
] with-row
|
|
|
|
] each 2drop
|
2009-03-11 04:17:30 -04:00
|
|
|
] tabular-output nl ;
|
2009-10-27 04:32:28 -04:00
|
|
|
|
|
|
|
: collect-gc-events ( quot -- events )
|
|
|
|
enable-gc-events [ ] [ disable-gc-events drop ] cleanup
|
2009-10-27 17:31:45 -04:00
|
|
|
disable-gc-events byte-array>gc-event-array ; inline
|
|
|
|
|
|
|
|
: generation-sizes-before ( events -- sizes )
|
|
|
|
[
|
|
|
|
{
|
|
|
|
[ start-time>> ]
|
|
|
|
[ nursery-size-before>> ]
|
|
|
|
[ aging-size-before>> ]
|
|
|
|
[ tenured-size-before>> ]
|
|
|
|
[ code-size-before>> ]
|
|
|
|
} cleave 5 narray
|
|
|
|
] { } map-as ;
|
|
|
|
|
|
|
|
: generation-sizes-after ( events -- sizes )
|
|
|
|
[
|
|
|
|
{
|
|
|
|
[ start-time>> ]
|
|
|
|
[ nursery-size-after>> ]
|
|
|
|
[ aging-size-after>> ]
|
|
|
|
[ tenured-size-after>> ]
|
|
|
|
[ code-size-after>> ]
|
|
|
|
} cleave 5 narray
|
|
|
|
] { } map-as ;
|
|
|
|
|
|
|
|
: reclaimed-space ( events -- sizes )
|
|
|
|
[
|
|
|
|
[ start-time>> ] [
|
|
|
|
{
|
|
|
|
[ [ nursery-size-before>> ] [ nursery-size-after>> ] bi - ]
|
|
|
|
[ [ aging-size-before>> ] [ aging-size-after>> ] bi - ]
|
|
|
|
[ [ tenured-size-before>> ] [ tenured-size-after>> ] bi - ]
|
|
|
|
[ [ code-size-before>> ] [ code-size-after>> ] bi - ]
|
|
|
|
} cleave
|
|
|
|
+ + +
|
|
|
|
] bi 2array
|
|
|
|
] { } map-as ;
|
|
|
|
|
|
|
|
: allocated-space ( events -- sizes )
|
|
|
|
2 <sliced-clumps> [
|
|
|
|
[ second start-time>> ] [
|
|
|
|
{
|
|
|
|
[ [ second nursery-size-before>> ] [ first nursery-size-after>> ] bi - ]
|
|
|
|
[ [ second aging-size-before>> ] [ first aging-size-after>> ] bi - ]
|
|
|
|
[ [ second tenured-size-before>> ] [ first tenured-size-after>> ] bi - ]
|
|
|
|
[ [ second code-size-before>> ] [ first code-size-after>> ] bi - ]
|
|
|
|
} cleave
|
|
|
|
+ + +
|
|
|
|
] bi 2array
|
|
|
|
] { } map-as ;
|