1 ! Copyright (C) 2010 Joe Groff.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: arrays calendar help.markup help.syntax math quotations threads
4 tools.profiler.sampling tools.profiler.sampling.private ;
5 IN: tools.profiler.sampling
7 { cross-section flat top-down top-down-max-depth profile profile. } related-words
8 { cross-section* flat* top-down* top-down-max-depth* most-recent-profile-data } related-words
10 { total-sample-count gc-sample-count jit-sample-count foreign-sample-count foreign-thread-sample-count sample-thread sample-callstack } related-words
12 { total-time gc-time foreign-time foreign-thread-time } related-words
17 { "tree" "a profile report" }
19 { $description "Generates a cross-section profile at " { $snippet "depth" } " from the results of the most recent " { $link profile } ". Each sample's time will be charged to the function " { $snippet "depth" } " levels deep in the callstack, or to the deepest function in the callstack if the callstack at the time of the sample is fewer than " { $snippet "depth" } " levels deep. The output " { $snippet "tree" } " can be printed with the " { $link profile. } " word." } ;
23 { "depth" integer } { "profile-data" "raw profile data" }
24 { "tree" "a profile report" }
26 { $description "Generates a cross-section profile at " { $snippet "depth" } " from the profile results in " { $snippet "profile-data" } ". Each sample's time will be charged to the function " { $snippet "depth" } " levels deep in the callstack, or to the deepest function in the callstack if the callstack at the time of the sample is fewer than " { $snippet "depth" } " levels deep. The output " { $snippet "tree" } " can be printed with the " { $link profile. } " word." } ;
30 { "flat" "a profile report" }
32 { $description "Generates a flat profile from the results of the most recent " { $link profile } ". Each sample's time will be charged to every function in the callstack at the time of the sample. The output " { $snippet "tree" } " can be printed with the " { $link profile. } " word." } ;
36 { "profile-data" "raw profile data" }
37 { "flat" "a profile report" }
39 { $description "Generates a flat profile from the profile results in " { $snippet "profile-data" } ". Each sample's time will be charged to every function in the callstack at the time of the sample. The output " { $snippet "tree" } " can be printed with the " { $link profile. } " word." } ;
41 HELP: foreign-sample-count
43 { "sample" "a raw profile sample" }
46 { $description "Returns the number of sample intervals spent in non-Factor code (such as the Factor VM, or FFI calls) during " { $snippet "sample" } "." } ;
48 HELP: foreign-thread-sample-count
50 { "sample" "a raw profile sample" }
53 { $description "Returns the number of sample intervals spent executing non-Factor threads within the Factor process during " { $snippet "sample" } "." } ;
55 HELP: foreign-thread-time
59 { $description "Returns the total time spent executing non-Factor threads within the Factor process during the last " { $link profile } "." } ;
61 HELP: foreign-thread-time*
63 { "profile-data" "raw profile data" }
66 { $description "Returns the total time spent executing non-Factor threads within the Factor process from the given " { $snippet "profile-data" } "." } ;
72 { $description "Returns the total time spent in non-Factor code (such as the Factor VM, or FFI calls) during the last " { $link profile } "." } ;
76 { "profile-data" "raw profile data" }
79 { $description "Returns the total time spent in non-Factor code (such as the Factor VM, or FFI calls) from the given " { $snippet "profile-data" } "." } ;
83 { "sample" "a raw profile sample" }
86 { $description "Returns the number of sample intervals spent in the garbage collector during " { $snippet "sample" } "." } ;
92 { $description "Returns the total time spent in the garbage collector during the last " { $link profile } "." } ;
96 { "profile-data" "raw profile data" }
99 { $description "Returns the total time spent in the garbage collector from the given " { $snippet "profile-data" } "." } ;
101 HELP: jit-sample-count
103 { "sample" "a raw profile sample" }
106 { $description "Returns the number of sample intervals spent in the non-optimizing compiler during " { $snippet "sample" } "." } ;
108 HELP: most-recent-profile-data
110 { "profile-data" "raw profile data" }
112 { $description "Returns the raw profile data from the most recent " { $link profile } ". This data can be saved and used with the " { $snippet "*" } " variants of reporting words, such as " { $link top-down* } " and " { $link flat* } ", independent of later executions of the profiler.." } ;
118 { $description "Executes " { $snippet "quot" } " with the sampling profiler enabled. The results of the profile can subsequently be reported with words such as " { $link top-down } " and " { $link flat } ", or the raw data can be saved and inspected with " { $link most-recent-profile-data } "." } ;
121 { $class-description "Objects of this type are generated by profile reporting words such as " { $link top-down } ", " { $link top-down-max-depth } ", " { $link cross-section } ", and " { $link flat } "." } ;
125 { "tree" "a profile report" }
127 { $description "Formats and prints a profile report generated by " { $link top-down } ", " { $link top-down-max-depth } ", " { $link cross-section } ", or " { $link flat } "." } ;
129 HELP: raw-profile-data
130 { $var-description "Holds raw profiling data. Set by the " { $link profile } " word after the profiling run is over." } ;
132 HELP: sample-callstack
134 { "sample" "a raw profile sample" }
137 { $description "Returns the callstack (the stack of functions currently executing) at the time of " { $snippet "sample" } "." } ;
141 { "sample" "a raw profile sample" }
144 { $description "Returns the currently-executing Factor thread at the time of " { $snippet "sample" } "." } ;
146 HELP: samples-per-second
147 { $var-description "This variable controls the rate at which the profiler takes samples during calls to " { $link profile } "." } ;
151 { "samples" integer }
152 { "seconds" integer }
154 { $description "Converts a sample interval count to an integer based on the value of " { $link samples-per-second } "." } ;
158 { "tree" "a profile report" }
160 { $description "Generates a top-down tree profile from the results of the most recent " { $link profile } ". The output " { $snippet "tree" } " can be printed with the " { $link profile. } " word." } ;
164 { "profile-data" "raw profile data" }
165 { "tree" "a profile report" }
167 { $description "Generates a top-down tree profile from the profile results in " { $snippet "profile-data" } ". The output " { $snippet "tree" } " can be printed with the " { $link profile. } " word." } ;
169 HELP: top-down-max-depth
171 { "max-depth" integer }
172 { "tree" "a profile report" }
174 { $description "Generates a top-down tree profile from the results of the most recent " { $link profile } ". Functions at a callstack depth greater than " { $snippet "max-depth" } " will be filtered out. The output " { $snippet "tree" } " can be printed with the " { $link profile. } " word." } ;
176 HELP: top-down-max-depth*
178 { "max-depth" integer } { "profile-data" "raw profile data" }
179 { "tree" "a profile report" }
181 { $description "Generates a top-down tree profile from the profile results in " { $snippet "profile-data" } ". Functions at a callstack depth greater than " { $snippet "max-depth" } " will be filtered out. The output " { $snippet "tree" } " can be printed with the " { $link profile. } " word." } ;
183 HELP: total-sample-count
185 { "sample" "a raw profile sample" }
188 { $description "Returns the total number of sample intervals spent during " { $snippet "sample" } "." } ;
194 { $description "Returns the total time spent during the most recent " { $link profile } "." } ;
198 { "profile-data" "raw profile data" }
201 { $description "Returns the total time spent from the given " { $snippet "profile-data" } "." } ;
203 ARTICLE: "tools.profiler.sampling" "Sampling profiler"
204 "The " { $vocab-link "tools.profiler.sampling" } " vocabulary provides an interface to Factor's sampling profiler. It provides words for running the profiler:"
205 { $subsections profile }
206 "General statistics can then be collected:"
207 { $subsections total-time gc-time foreign-time foreign-thread-time }
208 "More detailed by-function profile reports can be generated:"
209 { $subsections top-down top-down-max-depth cross-section flat }
210 "The report data can then be printed:"
211 { $subsections profile. }
212 "Profile data can be saved for future reporting:"
213 { $subsections most-recent-profile-data top-down* top-down-max-depth* cross-section* flat* }
214 "For example, the following will profile a call to the foo word, and generate and display a top-down tree profile from the results:"
215 { $code "[ foo ] profile
219 ABOUT: "tools.profiler.sampling"
226 ! not compensated for sample collection time
227 ! nearest-neighbor reporting