]> gitweb.factorcode.org Git - factor.git/blob - basis/tools/profiler/profiler.factor
Change tabular-output and smash-pane behavior to fix panes unit tests; re-organize...
[factor.git] / basis / tools / profiler / profiler.factor
1 ! Copyright (C) 2007, 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors words sequences math prettyprint kernel arrays io
4 io.styles namespaces assocs kernel.private strings combinators
5 sorting math.parser vocabs definitions tools.profiler.private
6 continuations generic compiler.units sets classes fry ;
7 IN: tools.profiler
8
9 : profile ( quot -- )
10     [ t profiling call ] [ f profiling ] [ ] cleanup ;
11
12 : filter-counts ( alist -- alist' )
13     [ second 0 > ] filter ;
14
15 : map-counters ( obj quot -- alist )
16     { } map>assoc filter-counts ; inline
17
18 : counters ( words -- alist )
19     [ dup counter>> ] map-counters ;
20
21 : cumulative-counters ( obj quot -- alist )
22     '[ dup @ [ counter>> ] sigma ] map-counters ; inline
23
24 : vocab-counters ( -- alist )
25     vocabs [ words [ predicate? not ] filter ] cumulative-counters ;
26
27 : generic-counters ( -- alist )
28     all-words [ subwords ] cumulative-counters ;
29
30 : methods-on ( class -- methods )
31     dup implementors [ method ] with map ;
32
33 : class-counters ( -- alist )
34     classes [ methods-on ] cumulative-counters ;
35
36 : method-counters ( -- alist )
37     all-words [ subwords ] map concat counters ;
38
39 : profiler-usage ( word -- words )
40     [ smart-usage [ word? ] filter ]
41     [ compiled-generic-usage keys ]
42     [ compiled-usage keys ]
43     tri 3append prune ;
44
45 : usage-counters ( word -- alist )
46     profiler-usage counters ;
47
48 : counters. ( assoc -- )
49     sort-values simple-table. ;
50
51 : profile. ( -- )
52     "Call counts for all words:" print
53     all-words counters counters. ;
54
55 : vocab-profile. ( vocab -- )
56     "Call counts for words in the " write
57     dup dup vocab write-object
58     " vocabulary:" print
59     words counters counters. ;
60
61 : usage-profile. ( word -- )
62     "Call counts for words which call " write
63     dup pprint
64     ":" print
65     usage-counters counters. ;
66
67 : vocabs-profile. ( -- )
68     "Call counts for all vocabularies:" print
69     vocab-counters counters. ;
70
71 : generic-profile. ( -- )
72     "Call counts for methods on generic words:" print
73     generic-counters counters. ;
74
75 : class-profile. ( -- )
76     "Call counts for methods on classes:" print
77     class-counters counters. ;
78
79 : method-profile. ( -- )
80     "Call counts for all methods:" print
81     method-counters counters. ;