]> gitweb.factorcode.org Git - factor.git/blob - basis/tools/profiler/profiler-docs.factor
Fix permission bits
[factor.git] / basis / tools / profiler / profiler-docs.factor
1 USING: tools.profiler.private tools.time help.markup help.syntax
2 quotations io strings words definitions ;
3 IN: tools.profiler
4
5 ARTICLE: "profiling" "Profiling code" 
6 "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:"
7 { $list
8     "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."
9     { "Calls to " { $link POSTPONE: inline } " words are not counted.." }
10     { "Calls to methods which were inlined as a result of type inference are not counted." }
11     "Tail-recursive loops will only count the initial invocation of the word, not every tail call."
12 }
13 "Quotations can be passed to a combinator which calls them with the profiler enabled:"
14 { $subsection profile }
15 "After a quotation has been profiled, call counts can be presented in various ways:"
16 { $subsection profile. }
17 { $subsection vocab-profile. }
18 { $subsection usage-profile. }
19 { $subsection vocabs-profile. }
20 { $subsection method-profile. } ;
21
22 ABOUT: "profiling"
23
24 HELP: counters
25 { $values { "words" "a sequence of words" } { "assoc" "an association list mapping words to integers" } }
26 { $description "Outputs an association list of word call counts." } ;
27
28 HELP: counters.
29 { $values { "assoc" "an association list mapping words to integers" } }
30 { $description "Prints an association list of call counts to " { $link output-stream } "." } ;
31
32 HELP: profile
33 { $values { "quot" quotation } }
34 { $description "Calls the quotation while collecting word call counts, which can then be displayed using " { $link profile. } " or related words." } ;
35
36 HELP: profile.
37 { $description "Prints a table of call counts from the most recent invocation of " { $link profile } "." } ;
38
39 HELP: vocab-profile.
40 { $values { "vocab" string } }
41 { $description "Prints a table of call counts from the most recent invocation of " { $link profile } ", for words in the " { $snippet "vocab" } " vocabulary only." }
42 { $examples { $code "\"math\" vocab-profile." } } ;
43
44 HELP: usage-profile.
45 { $values { "word" word } }
46 { $description "Prints a table of call counts from the most recent invocation of " { $link profile } ", for words which directly call " { $snippet "word" } " only." }
47 { $notes "This word obtains the list of static usages with the " { $link smart-usage } " word, and is not aware of dynamic call history. Consider the following scenario. A word " { $snippet "X" } " can execute word " { $snippet "Y" } " in a conditional branch, and " { $snippet "X" } " is executed many times during the profiling run, but this particular branch executing " { $snippet "Y" } " is never taken. However, some other word does execute " { $snippet "Y" } " multiple times. Then " { $snippet "\\ Y usage-profile." } " will list a number of calls to " { $snippet "X" } ", even though " { $snippet "Y" } " was never executed " { $emphasis "from" } " " { $snippet "X" } "." }
48 { $examples { $code "\\ + usage-profile." } } ;
49
50 HELP: vocabs-profile.
51 { $description "Print a table of cumilative call counts for each vocabulary. Vocabularies whose words were not called are supressed from the output." } ;
52
53 HELP: method-profile.
54 { $description "Print a table of cumilative call counts for each method. Methods which were not called are supressed from the output." } ;
55
56 HELP: profiling ( ? -- )
57 { $values { "?" "a boolean" } }
58 { $description "Internal primitive to switch on call counting. This word should not be used; instead use " { $link profile } "." } ;
59
60 { time profile } related-words