I'm looking at the docs on the profiler and having some trouble. What I see is the following:
-
profile
will accept some expressions, run them, gather timing data, analyze it, and render it. It's a macro wrapper aroundprofile-thunk
, which does the same end-to-end profiling but takes a thunk. -
create-sampler
accepts a thread, a custodian, or a list thereof. It will return a function that is able to gather data in response to messages. No idea what the difference is between passing a thread versus a custodian, why I would do one over the other, or what the implications are. If I pass a thread, maybe I should start off with the thread suspended so that the timing data will be accurate? Maybe it doesn't matter? Dunno. -
analyze-samples
accepts profile data and analyzes it. The profile data comes from...somewhere? Presumablycreate-sampler
is involved but I have no idea how. It emits aprofile
struct. -
render
and its variants take aprofile
struct that was generated byanalyze-samples
and spit out the encapsulated information in the desired representation (text, JSON, graphviz, etc).
I've googled around but cannot find any examples of the profiler that clear up my confusion.
Here's some sample code. If I want to run this in the profiler and then spit the results out in, for example, graphviz, how do I do that?
(require profile
profile/render-graphviz
simple-qr
)
(define png-file "out.png")
(define str (port->string (open-input-file "./sample-text.txt")))
(when (file-exists? png-file) (delete-file png-file))
(profile-thunk (thunk (qr-write str png-file #:error_level "L")))
;; A bunch of text-based data comes pouring forth. Excellent. Still, it's a little hard
;; to follow and I'd like to be able to use the hide-* arguments to streamline what gets
;; shown. Let's try again.
(when (file-exists? png-file) (delete-file png-file))
; (define results ...gather the profile data here...)
; (define prof (analyze-samples results))
; (render prof #:hide-self 5/100) ; should produce a graphviz as render-graphviz is required
(NB: I recognize that the graphviz renderer is marked experimental.)