profile.core

A Clojure library for profiling.

## Example

```clojure
(require '[profile.core :refer :all])
(defn my-add [a b] (+ a b))
(defn my-mult [a b] (* a b))

(profile-vars my-add my-mult)

(profile {}
 (my-add (my-mult (rand-int 100000) (rand-int 1000000))
         (my-mult (rand-int 100000) (rand-int 1000000))))
```

`profile` prints output to `*err*` using `pprint/print-table`; it
looks like this:

```
|          :name | :n | :sum | :q1 | :med | :q3 | :sd | :mad |
|----------------+----+------+-----+------+-----+-----+------|
|  #'user/my-add |  1 |  2µs | 2µs |  2µs | 2µs | 0µs |  0µs |
| #'user/my-mult |  2 | 11µs | 3µs |  8µs | 3µs | 3µs |  5µs |
```

*profile-data*

dynamic

clear-profile-data

(clear-profile-data)

max-sample-count

(max-sample-count)
Return maximum sample count of current profile session.

print-entry-summary

(print-entry-summary name)(print-entry-summary session name)
Prints a table of profiling statistics to `*err*` for var with
`name` if present. Returns nul.

print-summary

(print-summary)(print-summary session)
Prints to *err* statistics for profiled names. Returns nil.

profile

macro

(profile options & body)
Execute body in a new profile session using `options` and print
summary of collected profile data to `*err*` using `print-summary`.

profile-ns

(profile-ns ns)(profile-ns ns include-private?)
Equivalent to evaluating `profile-var*` on each function-containing
var is `ns`. If `include-private?` is present and true, profile
functions associated with private vars in addition to public vars,
otherwise profile only public functions. Returns true value.

profile-session

(profile-session max-sample-count)(profile-session)
Inititalize profile session with optional maximum sample
count. Default maximum sample count is 10,000.

profile-var

macro

(profile-var var)
If `var` is not already profiled, wraps the associated value with a
function that accrues time to the current profile session.

profile-var*

(profile-var* var)
Given a var value, profile it if it is not already profiled.

profile-vars

macro

(profile-vars & vars)
Equivalent to evaluating `profile-var` on each element of `vars`.

profiled?

(profiled? f)
Reurns a true value if `f` is currently profiled.

set-max-sample-count

(set-max-sample-count n)
Set maximum sample count of current profile session. Maximum sample
count refers to the the maximum number of samples any individual
name may be associated with. Value is applied when time is accured;
this call will not truncate any profile data.

summary

(summary)(summary session)
Returns a map containing two keys, `:stats` and `:agg-stats`. The
former containts a sequence of maps containing statistics describing
the profile data for each profiled name. `:agg-stats` contains a map
of statistics relevant to the aggregate of all profiles names.

toggle-profile-ns

(toggle-profile-ns ns)(toggle-profile-ns ns include-private?)
If any vars in `ns` are profiled, unprofile all vars in `ns`,
regardless whether public or private. If no vars in `ns` are
profiled, profiles each public (and private, if `include-private?`
is present and true) function-containing var. Returns true value if
namespace is profiled.

toggle-profile-var

macro

(toggle-profile-var var)
Profiles or unprofiles `var` depending on its current
state. Returns a truthy value if `var` is profiled subsequent to
evaluation of this macro.

toggle-profile-var*

(toggle-profile-var* v)
For use by cider-nrepl.

unprofile-ns

(unprofile-ns ns)
Equivalent to evaluating `unprofile-var*` on each
function-containing var in `ns`, whether public or private. Returns
not-true value.

unprofile-var

macro

(unprofile-var var)
If `var` is profiled, replaces binding with original function.

unprofile-var*

(unprofile-var* var)
Given a var value, unprofile it if it is profiled.

unprofile-vars

macro

(unprofile-vars & vars)
Equivalent to evaluating `unprofile-var` on each element of
`vars`.

with-session

macro

(with-session options & body)
Evaluate `body` in context of a new profile sassion initializaed
with `options`, a map that may contain a `:max-sample-count`.