Profiler now supports method profiling
parent
a832b4d445
commit
aed0ca0d19
|
@ -1,7 +1,26 @@
|
||||||
USING: tools.test tools.annotations ;
|
USING: tools.test tools.annotations math parser ;
|
||||||
IN: temporary
|
IN: temporary
|
||||||
|
|
||||||
: foo ;
|
: foo ;
|
||||||
\ foo watch
|
\ foo watch
|
||||||
|
|
||||||
[ ] [ foo ] unit-test
|
[ ] [ 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
|
||||||
|
|
|
@ -3,10 +3,11 @@ quotations io strings words definitions ;
|
||||||
IN: tools.profiler
|
IN: tools.profiler
|
||||||
|
|
||||||
ARTICLE: "profiling" "Profiling code"
|
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
|
{ $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."
|
"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 " { $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."
|
"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:"
|
"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 profile. }
|
||||||
{ $subsection vocab-profile. }
|
{ $subsection vocab-profile. }
|
||||||
{ $subsection usage-profile. }
|
{ $subsection usage-profile. }
|
||||||
{ $subsection vocabs-profile. } ;
|
{ $subsection vocabs-profile. }
|
||||||
|
{ $subsection method-profile. } ;
|
||||||
|
|
||||||
ABOUT: "profiling"
|
ABOUT: "profiling"
|
||||||
|
|
||||||
|
@ -48,6 +50,9 @@ HELP: usage-profile.
|
||||||
HELP: vocabs-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." } ;
|
{ $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 ( ? -- )
|
HELP: profiling ( ? -- )
|
||||||
{ $values { "?" "a boolean" } }
|
{ $values { "?" "a boolean" } }
|
||||||
{ $description "Internal primitive to switch on call counting. This word should not be used; instead use " { $link profile } "." } ;
|
{ $description "Internal primitive to switch on call counting. This word should not be used; instead use " { $link profile } "." } ;
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
USING: words sequences math prettyprint kernel arrays io
|
USING: words sequences math prettyprint kernel arrays io
|
||||||
io.styles namespaces assocs kernel.private strings combinators
|
io.styles namespaces assocs kernel.private strings combinators
|
||||||
sorting math.parser vocabs definitions tools.profiler.private
|
sorting math.parser vocabs definitions tools.profiler.private
|
||||||
continuations ;
|
continuations generic ;
|
||||||
IN: tools.profiler
|
IN: tools.profiler
|
||||||
|
|
||||||
: profile ( quot -- )
|
: profile ( quot -- )
|
||||||
|
@ -28,6 +28,11 @@ C: <vocab-profile> vocab-profile
|
||||||
M: string (profile.)
|
M: string (profile.)
|
||||||
dup <vocab-profile> write-object ;
|
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 -- )
|
: counter. ( obj n -- )
|
||||||
[
|
[
|
||||||
>r [ (profile.) ] with-cell r>
|
>r [ (profile.) ] with-cell r>
|
||||||
|
@ -63,3 +68,7 @@ M: string (profile.)
|
||||||
[ "predicating" word-prop not ] subset
|
[ "predicating" word-prop not ] subset
|
||||||
[ profile-counter ] map sum
|
[ profile-counter ] map sum
|
||||||
] { } map>assoc counters. ;
|
] { } map>assoc counters. ;
|
||||||
|
|
||||||
|
: method-profile. ( -- )
|
||||||
|
all-words [ subwords ] map concat
|
||||||
|
counters counters. ;
|
||||||
|
|
|
@ -24,6 +24,9 @@ TUPLE: profiler-gadget pane ;
|
||||||
: com-vocabs-profile ( gadget -- )
|
: com-vocabs-profile ( gadget -- )
|
||||||
[ vocabs-profile. ] with-profiler-pane ;
|
[ vocabs-profile. ] with-profiler-pane ;
|
||||||
|
|
||||||
|
: com-method-profile ( gadget -- )
|
||||||
|
[ method-profile. ] with-profiler-pane ;
|
||||||
|
|
||||||
: profiler-help "ui-profiler" help-window ;
|
: profiler-help "ui-profiler" help-window ;
|
||||||
|
|
||||||
\ profiler-help H{ { +nullary+ t } } define-command
|
\ profiler-help H{ { +nullary+ t } } define-command
|
||||||
|
@ -31,6 +34,7 @@ TUPLE: profiler-gadget pane ;
|
||||||
profiler-gadget "toolbar" f {
|
profiler-gadget "toolbar" f {
|
||||||
{ f com-full-profile }
|
{ f com-full-profile }
|
||||||
{ f com-vocabs-profile }
|
{ f com-vocabs-profile }
|
||||||
|
{ f com-method-profile }
|
||||||
{ T{ key-down f f "F1" } profiler-help }
|
{ T{ key-down f f "F1" } profiler-help }
|
||||||
} define-command-map
|
} define-command-map
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue