{"size": 3626, "ext": "scrbl", "max_stars_repo_path": "profile-doc/profile/scribblings/sampler.scrbl", "max_stars_repo_name": "pavpanchekha/profile", "max_stars_repo_stars_event_min_datetime": "2018-07-29T04:13:52.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-14T16:11:17.000Z", "max_issues_repo_path": "profile-doc/profile/scribblings/sampler.scrbl", "max_issues_repo_name": "pavpanchekha/profile", "max_issues_repo_issues_event_min_datetime": "2017-08-25T20:26:37.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-26T17:48:40.000Z", "max_forks_repo_path": "profile-doc/profile/scribblings/sampler.scrbl", "max_forks_repo_name": "pavpanchekha/profile", "max_forks_repo_forks_event_min_datetime": "2016-01-09T16:19:27.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-23T17:17:35.000Z"}
{"max_stars_count": 10, "max_issues_count": 15, "max_forks_count": 6, "avg_line_length": 45.325, "max_line_length": 81, "alphanum_fraction": 0.7275234418}
#lang scribble/doc

@(require scribble/manual
          (for-label racket/base racket/contract profile/sampler profile/analyzer
                     errortrace/errortrace-key))

@title[#:tag "sampler"]{Collecting Profile Information}

@defmodule[profile/sampler]

@defproc[(create-sampler [to-track (or/c thread? custodian?
                                         (listof (or/c thread? custodian?)))]
                         [delay (>=/c 0.0)]
                         [super-cust custodian? (current-custodian)]
                         [custom-keys (listof any/c) '()]
                         [#:use-errortrace? use-errortrace? any/c #f])
         ((symbol?) (any/c) . ->* . any/c)]{

Creates a stack-snapshot collector thread, which tracks the given
@racket[to-track] value every @racket[delay] seconds.  The
@racket[to-track] value can be either a thread (track just that
thread), a custodian (track all threads managed by the custodian), or
a list of threads and/or custodians.  If a custodian is given, it must
be subordinate to @racket[super-cust], which defaults to the current
custodian.

When @racket[custom-keys] are provided, the sampler takes snapshots of the
continuation marks corresponding to the given keys, in addition to taking
snapshots of the stack.

When @racket[use-errortrace?] is not @racket[#f], the @racket[errortrace-key] is 
used to sample snapshots instead of the implicit key used by 
@racket[continuation-mark-set->context].

The resulting value is a controller function, which consumes a message
consisting of a symbol and an optional argument, and can affect the
sampler.  The following messages are currently supported:
@itemize[

@item{@racket['pause] and @racket['resume] will stop or resume
  snapshot collection.  These messages can be nested.  Note that the
  thread will continue running---it will just stop collecting
  snapshots.}

@item{@racket['stop] kills the sampler thread.  It should be called
  when no additional data should be collected.  (This is currently
  irreversible: there is no message to start a new sampler thread.)}

@item{@racket['set-tracked!] with a value will change the tracked
  object(s) which were initially specified as the @racket[to-track]
  argument.}

@item{@racket['set-tracked!] with a numeric value will change the
  delay that the sampler is taking between snapshots.  Note that
  although changing this means that the snapshots are not uniformly
  distributed, the results will still be correct: the cpu time between
  samples is taken into account when the collected data is analyzed.}

@item{A @racket['get-snapshots] message will make the controller return
  the currently collected data.  Note that this can be called multiple
  times, each call will return the data that is collected up to that
  point in time.  In addition, it can be (and usually is) called after
  the sampler was stopped.

  The value that is returned should be considered as an undocumented
  internal detail of the profiler, intended to be sent to
  @racket[analyze-samples] for analysis.  The reason this is not done
  automatically, is that a future extension might allow you to combine
  several sampler results, making it possible to combine a profile
  analysis from several individual runs, possibly from different
  machines.}

@item{Finally, a @racket['get-custom-snapshots] message will make the
  controller return the currently collected snapshots corresponding to
  @racket[custom-keys]. This returns a list of samples, where each sample
  is a list of vectors of marks in the same format as the output of
  @racket[continuation-mark-set->list*].}

]}
