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.

prepare(record)[source]

Perform any setup required before the recorder is used.

Parameters:record (NamedTuple) – The record class that is going to be used.
finalize()[source]

Perform any tasks to finalize and clean up when the recording has completed.

record(data)[source]

Record a measurement.

Parameters:data (NamedTuple) – An instance of the record class that is going to be used.

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.
prepare(record)[source]

Write the header in the csv file the first time it is called.

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]

Record the data entry when the filter function returns True.

Parameters:values (NamedTuple) – The record entry.
Raises:RecorderError – Raised if the method is called without the recorder been ready to accept data.

class pikos.recorders.csv_file_recorder.CSVFileRecorder(filename, filter_=None, **csv_kwargs)[source]

Bases: pikos.recorders.csv_recorder.CSVRecorder

A CSVRecorder that creates the stream (i.e. file) for the records.

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.
_filename : string
The name and path of the file to be used for output.
_file : file
The file object where records are stored.
__init__(filename, filter_=None, **csv_kwargs)[source]

Class initialization.

Parameters:
  • filename (string) – The file path to use.
  • filter_ (callable) – A callable function that accepts a data tuple and returns True if the input sould be recorded. Default is None.
  • **csv_kwargs – Key word arguments to be passed to the cvs.writer.
prepare(record)[source]

Open the csv file and write the header in the csv file.

finalize()[source]

Finalize the recorder.

Raises:RecorderError – Raised if the method is called without the recorder been ready to accept data.

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.
prepare(record)[source]

Prepare the recorder to accept data.

Note

nothing to do for the ListRecorder.

finalize()[source]

Finalize the recorder.

Note

nothing to do for the ListRecorder.

ready[source]

Is the recorder ready to accept data?

record(data)[source]

Record the data entry when the filter function returns True.

Parameters:data (NamedTuple) – The record entry.

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.


class pikos.recorders.text_file_recorder.TextFileRecorder(filename, filter_=None, formatted=False, auto_flush=False)[source]

Bases: pikos.recorders.text_stream_recorder.TextStreamRecorder

The TextStreamRecorder that creates the file for the records.

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.
_filename : string
The name and path of the file to be used for output.
__init__(filename, filter_=None, formatted=False, auto_flush=False)[source]

Class initialization.

Parameters:
  • filename (string) – The file path to use.
  • filter_ (callable) – A callable function that accepts a data tuple and returns True if the input sould be recorded. Default is None.
  • 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]

Open the file and write the header.

finalize()[source]

Finalize the recorder.

Raises:RecorderError – Raised if the method is called without the recorder been ready to accept data.

class pikos.recorders.zeromq_recorder.ZeroMQRecorder(zmq_host='127.0.0.1', zmq_port=9001, filter_=None, wait_for_ready=True, **kwargs)[source]

Bases: pikos.recorders.abstract_recorder.AbstractRecorder

The ZeroMQ Recorder is a recorder that publishes each set of values on a 0MQ publish socket.

Private

_filter : callable
Used to check if the set record should be recored. The function accepts a tuple of the record values and return True is the input sould be recored.
_ready : bool
Singify that the Recorder is ready to accept data. Please use the Recorder.ready property
__init__(zmq_host='127.0.0.1', zmq_port=9001, filter_=None, wait_for_ready=True, **kwargs)[source]

Class initialization.

Parameters:filter_ (callable) – A callable function that accepts a data tuple and returns True if the input sould be recorded.
prepare(record)[source]

Write the header in the csv file the first time it is called.

finalize()[source]

Signal that recording has ended.

ready[source]

Is the recorder ready to accept data?

record(record)[source]

Rerord entry onlty when the filter function returns True.