Recorders¶
- class pikos.recorders.abstract_recorder.AbstractRecorder[source]¶
Bases: object
Abstract recorder class.
A recorder is reposnible for storing the record data that are provided by the monitor or profiler. The records are expected to be nametuple-like classes.
- class pikos.recorders.csv_recorder.CSVRecorder(stream, filter_=None, **csv_kwargs)[source]¶
Bases: pikos.recorders.abstract_recorder.AbstractRecorder
The CSV Recorder is a simple text based recorder that records the tuple of values using a scv writer.
Private
- _filter = callable¶
Used to check if the set record should be recorded. The function accepts a tuple of the record values and return True is the input sould be recored.
- _writer = csv.writer¶
The writer object is owned by the CSVRecorder and exports the record values according to the configured dialect.
- _ready = bool¶
Singify that the Recorder is ready to accept data.
- __init__(stream, filter_=None, **csv_kwargs)[source]¶
Class initialization.
Parameters: - stream (file) – A file-like object to use for output.
- filter (callable) – A callable function that accepts a data tuple and returns True if the input sould be recorded.
- **csv_kwargs – Key word arguments to be passed to the cvs.writer.
- class pikos.recorders.list_recorder.ListRecorder(filter_=None)[source]¶
Bases: pikos.recorders.abstract_recorder.AbstractRecorder
The ListRecorder is simple recorder that records the tuple of values in memory as a list.
Public
- records = list¶
List of records. The Recorder assumes that the record method is provided with a tuple and accumulates all the records in a list.
Private
- _filter = callable¶
Used to check if the data entry should be recorded. The function accepts a namedtuple record and return True is the input sould be recored.
- __init__(filter_=None)[source]¶
Class initialization.
Parameters: filter (callable) – A callable function to filter out the data entries that are going to be recorded.
- class pikos.recorders.text_stream_recorder.TextStreamRecorder(text_stream, filter_=None, formatted=False, auto_flush=False)[source]¶
Bases: pikos.recorders.abstract_recorder.AbstractRecorder
The TextStreamRecorder is simple recorder that formats and writes the records directly to a stream.
Private
- _stream = TextIOBase¶
A text stream what supports the TextIOBase interface. The Recorder will write the values as a single line.
- _filter = callable¶
Used to check if the set record should be recorded. The function accepts a tuple of the record values and return True is the input should be recorded.
- _template = str¶
A string (using the Format Specification Mini-Language) to format the set of values in a line. It is constructed when the prepare method is called.
- _auto_flush = bool¶
A bool to enable/disable automatic flushing of the string after each record process.
- _ready = bool¶
Signify that the Recorder is ready to accept data.
- __init__(text_stream, filter_=None, formatted=False, auto_flush=False)[source]¶
Class initialization.
Parameters: - text_stream (TextIOBase) – A text stream what supports the TextIOBase interface.
- filter (callable) – A callable function that accepts a data tuple and returns True if the input sould be recorded.
- formatted (Bool) – Use the predefined formatting in the records. Default value is false.
- auto_flush (Bool) – When set the stream buffer is always flushed after each record process. Default value is False.
- prepare(record)[source]¶
Prepare the recorder to accept data.
Parameters: data (NamedTuple) – An example record to prepare the recorder and write the header to the stream.
- finalize()[source]¶
Finalize the recorder
A do nothing method.
Raises: RecorderError – Raised if the method is called without the recorder been ready to accept data.
- record(data)[source]¶
Rerord the data entry when the filter function returns True.
Parameters: data (NamedTuple) – The record entry. Raises: RecorderError – Raised if the method is called without the recorder been ready to accept data. Note
Given the value of _auto_flush the recorder will flush the stream buffers after each record.