]> gitweb.factorcode.org Git - factor.git/blob - basis/tools/profiler/profiler.factor
Fix conflict in images vocab
[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     standard-table-style [
50         sort-values simple-table.
51     ] tabular-output ;
52
53 : profile. ( -- )
54     "Call counts for all words:" print
55     all-words counters counters. ;
56
57 : vocab-profile. ( vocab -- )
58     "Call counts for words in the " write
59     dup dup vocab write-object
60     " vocabulary:" print
61     words counters counters. ;
62
63 : usage-profile. ( word -- )
64     "Call counts for words which call " write
65     dup pprint
66     ":" print
67     usage-counters counters. ;
68
69 : vocabs-profile. ( -- )
70     "Call counts for all vocabularies:" print
71     vocab-counters counters. ;
72
73 : generic-profile. ( -- )
74     "Call counts for methods on generic words:" print
75     generic-counters counters. ;
76
77 : class-profile. ( -- )
78     "Call counts for methods on classes:" print
79     class-counters counters. ;
80
81 : method-profile. ( -- )
82     "Call counts for all methods:" print
83     method-counters counters. ;