2006-03-25 01:06:52 -05:00
|
|
|
! Copyright (C) 2004, 2006 Slava Pestov.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2005-02-14 21:58:07 -05:00
|
|
|
IN: memory
|
2005-09-11 20:46:55 -04:00
|
|
|
USING: arrays errors generic hashtables io kernel
|
2006-06-17 16:51:44 -04:00
|
|
|
kernel-internals math namespaces parser prettyprint sequences
|
|
|
|
strings styles vectors words ;
|
2004-11-25 21:53:27 -05:00
|
|
|
|
2006-09-26 19:00:41 -04:00
|
|
|
: full-gc ( -- ) generations 1- data-gc ;
|
2005-09-24 15:21:17 -04:00
|
|
|
|
2005-02-18 19:02:06 -05:00
|
|
|
! Printing an overview of heap usage.
|
|
|
|
|
2006-06-08 00:38:34 -04:00
|
|
|
: total/used/free, ( free total str -- )
|
|
|
|
[
|
|
|
|
,
|
|
|
|
dup number>string ,
|
|
|
|
over - number>string ,
|
|
|
|
number>string ,
|
|
|
|
] { } make , ;
|
|
|
|
|
|
|
|
: total, ( n str -- )
|
|
|
|
[ , number>string , "" , "" , ] { } make , ;
|
|
|
|
|
2006-07-28 03:54:46 -04:00
|
|
|
: simple-table ( table -- )
|
|
|
|
H{ { table-gap { 10 0 } } }
|
|
|
|
[ dup string? [ write ] [ pprint ] if ]
|
|
|
|
tabular-output ;
|
|
|
|
|
|
|
|
: room. ( -- )
|
2006-09-26 01:08:05 -04:00
|
|
|
[
|
2006-06-08 00:38:34 -04:00
|
|
|
{ "" "Total" "Used" "Free" } ,
|
2006-09-26 01:08:05 -04:00
|
|
|
data-room 0 [
|
2006-06-08 00:38:34 -04:00
|
|
|
"Generation " pick number>string append
|
|
|
|
>r first2 r> total/used/free, 1+
|
|
|
|
] reduce drop
|
|
|
|
"Semi-space" total,
|
|
|
|
"Cards" total,
|
2006-09-26 01:08:05 -04:00
|
|
|
code-room "Code space" total/used/free,
|
2006-07-28 03:54:46 -04:00
|
|
|
] { } make simple-table ;
|
2004-11-25 21:53:27 -05:00
|
|
|
|
2005-02-18 19:02:06 -05:00
|
|
|
! Some words for iterating through the heap.
|
2005-02-14 21:58:07 -05:00
|
|
|
|
2005-08-19 21:46:12 -04:00
|
|
|
: (each-object) ( quot -- )
|
2005-09-14 00:37:50 -04:00
|
|
|
next-object dup
|
2005-09-24 15:21:17 -04:00
|
|
|
[ swap [ call ] keep (each-object) ] [ 2drop ] if ; inline
|
2005-08-19 21:46:12 -04:00
|
|
|
|
2005-02-17 22:49:19 -05:00
|
|
|
: each-object ( quot -- )
|
2005-09-21 01:12:16 -04:00
|
|
|
[ begin-scan [ (each-object) ] keep ]
|
|
|
|
[ end-scan ] cleanup drop ; inline
|
2005-02-17 22:49:19 -05:00
|
|
|
|
2005-11-12 00:37:24 -05:00
|
|
|
: (instances) ( obj quot seq -- )
|
|
|
|
>r over >r call [ r> r> push ] [ r> r> 2drop ] if ; inline
|
|
|
|
|
2005-10-01 01:44:49 -04:00
|
|
|
: instances ( quot -- seq )
|
2005-11-12 00:37:24 -05:00
|
|
|
10000 <vector> [
|
|
|
|
-rot [ (instances) ] 2keep
|
|
|
|
] each-object nip ; inline
|
2005-02-18 19:02:06 -05:00
|
|
|
|
2005-02-18 20:37:01 -05:00
|
|
|
: heap-stat-step ( counts sizes obj -- )
|
2006-03-22 17:21:41 -05:00
|
|
|
[ dup size swap class rot hash+ ] keep
|
|
|
|
1 swap class rot hash+ ;
|
2005-02-18 20:37:01 -05:00
|
|
|
|
2005-07-24 22:59:23 -04:00
|
|
|
: heap-stats ( -- counts sizes )
|
2005-02-18 20:37:01 -05:00
|
|
|
#! Return a list of instance count/total size pairs.
|
2006-03-22 17:21:41 -05:00
|
|
|
H{ } clone H{ } clone
|
2005-07-24 22:59:23 -04:00
|
|
|
[ >r 2dup r> heap-stat-step ] each-object ;
|
2005-02-18 20:37:01 -05:00
|
|
|
|
2005-02-18 19:02:06 -05:00
|
|
|
: heap-stats. ( -- )
|
2006-06-04 15:35:00 -04:00
|
|
|
heap-stats dup hash-keys natural-sort [
|
2006-06-08 00:38:34 -04:00
|
|
|
{ "Class" "Bytes" "Instances" } ,
|
|
|
|
[
|
|
|
|
( hash hash key -- )
|
|
|
|
[ dup , dup pick hash , pick hash , ] { } make ,
|
|
|
|
] each 2drop
|
2006-07-28 03:54:46 -04:00
|
|
|
] { } make simple-table ;
|