Historic.jl

Defining recorder

Historic.@defineMacro
Historic.@define RecordModule

Define a recorder module named RecordModule with a private event recording buffer.

RecordModule has a macro RecordModule.@record(name, k₁ = v₁, …) that can be used for defining (a pice of code to emit) events. The recorder is disabled by default. It has to be enabled by RecordModule.enable at run-time. Once the recorder is enabled, the events are recorded whenever execution of the program encounter the code path including @record.

RecordModule defines the following functions for manipulating recording:

RecordModule defines the following overloadable functions:

  • RecordModule.defaultdata() returns a named tuple to be included in the event record by default.
  • RecordModule.prefix() returns a string to be used asa prefix of the log message.
  • RecordModule.isrecording() returns a Bool indicating if the events recorded by RecordModule.@record should be recorded by default.
source
Historic.ScratchModule
Historic.Scratch

Pre-defined recorder module generated by Historic.@define Scratch. Historic.@record is an alias of Historic.Scratch.@record.

source

Defining events

Historic.Scratch.@recordMacro
Scratch.@record($name, $k₁ = $v₁, …, $kₙ = $vₙ)
Scratch.@record($name, $k₁ = $v₁, …, $kₙ = $vₙ, {$a₁ = $b₁, …, $aₙ = $bₙ})

Record event named $name and optional event data (key-value pairs $kᵢ = $vᵢ) with optional control arguments $aᵢ = $bᵢ.

Extended help

Examples

  • @record(:n1) records an event named :n1.
  • @record(:n2, k1 = 0) records an event named :n2 with optional data key k1 and value 0.
  • @record(rand(Bool) ? :n3 : :n4) records either an event named :n3 or an event named :n4.
  • @record(:n5, {log = nothing}) records an event without logging it.

Arguments

The first argument $name is an expression evaluates to a Symbol.

If the last argument is wrapped in a pair of { and }, it is treated as a set of control argument (see below).

The rest of the arguments are optional. Each of these argument is either an assignment of form $k = $v or a variable name $k. The latter is equivalent to $k = $k.

Optional control argument

If the last argument is of form {$a₁ = $b₁, …, $aₙ = $bₙ}, each assignment expression $a = $b specifies a (non-data) control option.

  • log ($b::Union{Nothing,NamedTuple}): Options to the logger. log = nothing disables logging.
  • yield ($b::Bool): Passing yield = false tries to avoid code paths that may yield to the scheduler.
source

Tools for defining event data

Historic.taskidFunction
Historic.taskid(task::Task = current_task())

Get a (pseudo) id for a task.

It does not uniquely identify a task (thus "pseudo") when the task is garbage collected and the corresponding memory region is re-used.

source
Historic.objidFunction
Historic.objid(x)

Get a (pseudo) id for arbitrary object x.

It does not uniquely identify an object (thus "pseudo") when the object is garbage collected and the corresponding memory region is re-used.

source
Historic.uniqueidFunction
Historic.uniqueid() -> id::UInt64

Generate a number unique within a julia process.

source

Recording events

Note

Historic.Scratch is an example of the module defined by Historic.@define. If you define the recorder module using Historic.@define YourRecorder, Use, e.g., YourRecorder.enable() instead of Historic.Scratch.enable().

Historic.Scratch.enableFunction
Scratch.enable()
Scratch.disable()

Enable/disable recording of the events generated by Scratch.@record.

Note

Since Historic.jl uses the method invalidation to toggle on and off the recordings, the recordings inside tasks started prior to the call to Scratch.enable()/Scratch.disable() cannot be enabled/disabled.

source
Historic.clearFunction
Historic.clear()

Remove recorded events in all existing recorder modules.

source

Analyzing events

Historic.eventsFunction
Historic.events() -> eventtable
Historic.events(recordmodule::Module) -> eventtable

Return a table of events recoded by recordmodule.@record. If used without an argument, return all events in all recorder modules.

source
Historic.flattableFunction
Historic.flattable() -> flattable
Historic.flattable(recordmodule::Module) -> flattable
Historic.flattable(eventtable) -> flattable

Return a flatten table of events; i.e., all custom event data key-value pairs passed to @record can accessed as columns.

See also Historic.events.

source

See lib/HistoricAnalysis as an example usage.