From aed0ca0d1952468b3c538017d23ceaac953ab56e Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Sat, 16 Feb 2008 15:54:53 -0600 Subject: [PATCH] Profiler now supports method profiling --- .../annotations/annotations-tests.factor | 21 ++++++++++++++++++- extra/tools/profiler/profiler-docs.factor | 9 ++++++-- extra/tools/profiler/profiler.factor | 11 +++++++++- extra/ui/tools/profiler/profiler.factor | 4 ++++ 4 files changed, 41 insertions(+), 4 deletions(-) mode change 100644 => 100755 extra/tools/annotations/annotations-tests.factor mode change 100644 => 100755 extra/tools/profiler/profiler-docs.factor mode change 100644 => 100755 extra/ui/tools/profiler/profiler.factor diff --git a/extra/tools/annotations/annotations-tests.factor b/extra/tools/annotations/annotations-tests.factor old mode 100644 new mode 100755 index f1ffdd25ae..da0c85196d --- a/extra/tools/annotations/annotations-tests.factor +++ b/extra/tools/annotations/annotations-tests.factor @@ -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 diff --git a/extra/tools/profiler/profiler-docs.factor b/extra/tools/profiler/profiler-docs.factor old mode 100644 new mode 100755 index a8c700b490..89e84bbc86 --- a/extra/tools/profiler/profiler-docs.factor +++ b/extra/tools/profiler/profiler-docs.factor @@ -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 } "." } ; diff --git a/extra/tools/profiler/profiler.factor b/extra/tools/profiler/profiler.factor index c35d5a72c8..784c9e8da6 100755 --- a/extra/tools/profiler/profiler.factor +++ b/extra/tools/profiler/profiler.factor @@ -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 M: string (profile.) dup write-object ; +M: method-body (profile.) + "method" word-prop + dup method-specializer over method-generic 2array synopsis + swap method-generic 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. ; diff --git a/extra/ui/tools/profiler/profiler.factor b/extra/ui/tools/profiler/profiler.factor old mode 100644 new mode 100755 index 2c25474fa0..cceebbec8b --- a/extra/ui/tools/profiler/profiler.factor +++ b/extra/ui/tools/profiler/profiler.factor @@ -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