2008-06-28 03:36:20 -04:00
|
|
|
! Copyright (C) 2007, 2008 Slava Pestov.
|
2007-09-20 18:09:08 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2008-06-28 03:36:20 -04:00
|
|
|
USING: accessors words sequences math prettyprint kernel arrays io
|
2007-10-28 04:33:36 -04:00
|
|
|
io.styles namespaces assocs kernel.private strings combinators
|
2007-10-29 01:12:27 -04:00
|
|
|
sorting math.parser vocabs definitions tools.profiler.private
|
2008-12-18 03:19:33 -05:00
|
|
|
continuations generic compiler.units sets ;
|
2007-09-20 18:09:08 -04:00
|
|
|
IN: tools.profiler
|
|
|
|
|
2007-10-28 04:33:36 -04:00
|
|
|
: profile ( quot -- )
|
|
|
|
[ t profiling call ] [ f profiling ] [ ] cleanup ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
: counters ( words -- assoc )
|
2008-06-28 03:36:20 -04:00
|
|
|
[ dup counter>> ] { } map>assoc ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
GENERIC: (profile.) ( obj -- )
|
|
|
|
|
|
|
|
TUPLE: usage-profile word ;
|
|
|
|
|
|
|
|
C: <usage-profile> usage-profile
|
|
|
|
|
|
|
|
M: word (profile.)
|
2008-12-18 03:19:33 -05:00
|
|
|
[ name>> "( no name )" or ] [ <usage-profile> ] bi write-object ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
TUPLE: vocab-profile vocab ;
|
|
|
|
|
|
|
|
C: <vocab-profile> vocab-profile
|
|
|
|
|
|
|
|
M: string (profile.)
|
|
|
|
dup <vocab-profile> write-object ;
|
|
|
|
|
2008-02-16 16:54:53 -05:00
|
|
|
M: method-body (profile.)
|
2008-12-18 03:19:33 -05:00
|
|
|
[ synopsis ] [ "method-generic" word-prop <usage-profile> ] bi
|
|
|
|
write-object ;
|
2008-02-16 16:54:53 -05:00
|
|
|
|
2007-09-20 18:09:08 -04:00
|
|
|
: counter. ( obj n -- )
|
|
|
|
[
|
2008-12-03 09:46:16 -05:00
|
|
|
[ [ (profile.) ] with-cell ] dip
|
2007-09-20 18:09:08 -04:00
|
|
|
[ number>string write ] with-cell
|
|
|
|
] with-row ;
|
|
|
|
|
|
|
|
: counters. ( assoc -- )
|
2008-04-26 00:17:08 -04:00
|
|
|
[ second 0 > ] filter sort-values
|
2007-09-20 18:09:08 -04:00
|
|
|
standard-table-style [
|
|
|
|
[ counter. ] assoc-each
|
|
|
|
] tabular-output ;
|
|
|
|
|
|
|
|
: profile. ( -- )
|
|
|
|
"Call counts for all words:" print
|
|
|
|
all-words counters counters. ;
|
|
|
|
|
|
|
|
: vocab-profile. ( vocab -- )
|
|
|
|
"Call counts for words in the " write
|
|
|
|
dup dup vocab write-object
|
|
|
|
" vocabulary:" print
|
|
|
|
words counters counters. ;
|
|
|
|
|
|
|
|
: usage-profile. ( word -- )
|
|
|
|
"Call counts for words which call " write
|
|
|
|
dup pprint
|
|
|
|
":" print
|
2008-12-18 03:19:33 -05:00
|
|
|
[ smart-usage [ word? ] filter ]
|
|
|
|
[ compiled-generic-usage keys ]
|
|
|
|
[ compiled-usage keys ]
|
|
|
|
tri 3append prune counters counters. ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
: vocabs-profile. ( -- )
|
|
|
|
"Call counts for all vocabularies:" print
|
|
|
|
vocabs [
|
2008-02-15 15:16:45 -05:00
|
|
|
dup words
|
2008-04-26 00:17:08 -04:00
|
|
|
[ "predicating" word-prop not ] filter
|
2008-06-28 03:36:20 -04:00
|
|
|
[ counter>> ] map sum
|
2007-09-20 18:09:08 -04:00
|
|
|
] { } map>assoc counters. ;
|
2008-02-16 16:54:53 -05:00
|
|
|
|
|
|
|
: method-profile. ( -- )
|
|
|
|
all-words [ subwords ] map concat
|
|
|
|
counters counters. ;
|