Recorder Events
InfrastructureSystems.jl
provides a mechanism to store structured data in events that get recorded in one or more files. They can be filtered and displayed in tabular form.
The primary use is to store information that can help debug problems and it is largely used in PowerSimulations.jl. For example, you may want to store all state transitions in a simulation or every update of a variable. If a problem occurs you can then display filtered tables of that data to figure out what went wrong.
Instructions
Create events that are subtypes of
InfrastructureSystems.AbstractRecorderEvent
. Include an instance ofRecorderEventCommon
in each struct.Call
InfrastructureSystems.register_recorder!
with argumentsrecorder-name
for each recorder object you want to create.- Depending on how often your code create events you may want to make this conditional. You may only need it for debug runs.
- PowerSimulations creates one recorder for simulation step and stage start/stop events that is always enabled. It creates another that is optional but used for frequently-generated events.
Call
@InfrastructureSystems.record
with argumentsrecorder-name
event
wherever you want to generate events in your code. The event will only get constructed if the recorder is registered.Call
InfrastructureSystems.unregister_recorder!
with argumentsrecorder-name
for each registered recorder. You should guarantee this gets called, even if an exception is thrown. Otherwise, the file may not get flushed and closed.After your code runs call
InfrastructureSystems.show_recorder_events
to view events. Refer to the docstrings for more information.Refer to
PowerSimulations.show_simulation_events
for an example on how to customize this behavior for your package.