Profiler now supports method profiling

db4
Slava Pestov 2008-02-16 15:54:53 -06:00
parent a832b4d445
commit aed0ca0d19
4 changed files with 41 additions and 4 deletions

21
extra/tools/annotations/annotations-tests.factor Normal file → Executable file
View File

@ -1,7 +1,26 @@
USING: tools.test tools.annotations ;
USING: tools.test tools.annotations math parser ;
IN: temporary
: foo ;
\ foo watch
[ ] [ foo ] unit-test
! erg's bug
GENERIC: some-generic
M: integer some-generic 1+ ;
[ 4 ] [ 3 some-generic ] unit-test
[ ] [ \ some-generic watch ] unit-test
[ 4 ] [ 3 some-generic ] unit-test
[ ] [ "IN: temporary USE: math M: integer some-generic 1- ;" eval ] unit-test
[ 2 ] [ 3 some-generic ] unit-test
[ ] [ \ some-generic reset ] unit-test
[ 2 ] [ 3 some-generic ] unit-test

9
extra/tools/profiler/profiler-docs.factor Normal file → Executable file
View File

@ -3,10 +3,11 @@ quotations io strings words definitions ;
IN: tools.profiler
ARTICLE: "profiling" "Profiling code"
"The " { $vocab-link "tools.profiler" } " vocabulary implements a simple call counting profiler. The profiler is completely accurate with words which are compiled with the non-optimizing compiler. Some optimizations performed by the optimizing compiler can inhibit accurate call counting, however:"
"The " { $vocab-link "tools.profiler" } " vocabulary implements a simple call counting profiler. The profiler is completely accurate with words and methods which are compiled with the non-optimizing compiler. Some optimizations performed by the optimizing compiler can inhibit accurate call counting, however:"
{ $list
"The optimizing compiler open-codes certain primitives with inline machine code, and in some cases optimizes them out altogether; this includes stack shuffling operations, conditionals, and many object allocation operations."
{ "Calls to " { $link POSTPONE: inline } " words are not counted.." }
{ "Calls to methods which were inlined as a result of type inference are not counted." }
"Tail-recursive loops will only count the initial invocation of the word, not every tail call."
}
"Quotations can be passed to a combinator which calls them with the profiler enabled:"
@ -15,7 +16,8 @@ ARTICLE: "profiling" "Profiling code"
{ $subsection profile. }
{ $subsection vocab-profile. }
{ $subsection usage-profile. }
{ $subsection vocabs-profile. } ;
{ $subsection vocabs-profile. }
{ $subsection method-profile. } ;
ABOUT: "profiling"
@ -48,6 +50,9 @@ HELP: usage-profile.
HELP: vocabs-profile.
{ $description "Print a table of cumilative call counts for each vocabulary. Vocabularies whose words were not called are supressed from the output." } ;
HELP: method-profile.
{ $description "Print a table of cumilative call counts for each method. Methods which were not called are supressed from the output." } ;
HELP: profiling ( ? -- )
{ $values { "?" "a boolean" } }
{ $description "Internal primitive to switch on call counting. This word should not be used; instead use " { $link profile } "." } ;

View File

@ -3,7 +3,7 @@
USING: words sequences math prettyprint kernel arrays io
io.styles namespaces assocs kernel.private strings combinators
sorting math.parser vocabs definitions tools.profiler.private
continuations ;
continuations generic ;
IN: tools.profiler
: profile ( quot -- )
@ -28,6 +28,11 @@ C: <vocab-profile> vocab-profile
M: string (profile.)
dup <vocab-profile> write-object ;
M: method-body (profile.)
"method" word-prop
dup method-specializer over method-generic 2array synopsis
swap method-generic <usage-profile> write-object ;
: counter. ( obj n -- )
[
>r [ (profile.) ] with-cell r>
@ -63,3 +68,7 @@ M: string (profile.)
[ "predicating" word-prop not ] subset
[ profile-counter ] map sum
] { } map>assoc counters. ;
: method-profile. ( -- )
all-words [ subwords ] map concat
counters counters. ;

4
extra/ui/tools/profiler/profiler.factor Normal file → Executable file
View File

@ -24,6 +24,9 @@ TUPLE: profiler-gadget pane ;
: com-vocabs-profile ( gadget -- )
[ vocabs-profile. ] with-profiler-pane ;
: com-method-profile ( gadget -- )
[ method-profile. ] with-profiler-pane ;
: profiler-help "ui-profiler" help-window ;
\ profiler-help H{ { +nullary+ t } } define-command
@ -31,6 +34,7 @@ TUPLE: profiler-gadget pane ;
profiler-gadget "toolbar" f {
{ f com-full-profile }
{ f com-vocabs-profile }
{ f com-method-profile }
{ T{ key-down f f "F1" } profiler-help }
} define-command-map