Outputs API¶
This module contains class that will be used by the measure decorator or the Measurement.export method to export
recorded measurement
example with the measure decorator:
output_instance = pyRAPL.outputs.XXXOutput(...)
@pyRAPL.measure(output=output_instance)
def foo():
...
example with the Measurement.export function:
measure = pyRAPL.Measurement('label')
...
output_instance = pyRAPL.outputs.XXXOutput(...)
measure.export(output_instance)
You can define your one output by inherit from the Output class and implements the add method.
This method will receive the measured energy consumption data as a Result instance and must handle it.
For example, the PrintOutput.add method will print the Result instance.
Abstract Class¶
-
class
pyRAPL.outputs.Output¶ Abstract class that represent an output handler for the Measurement class
-
add(result)¶ Handle the object Result
- Parameters
result (
Result) – data to handle
-
-
class
pyRAPL.outputs.BufferedOutput¶ Use a buffer to batch the output process
The method
addadd data to the buffer and the methodsaveoutputs each data in the buffer. After that, the buffer is flushedImplement the abstract method
_output_bufferto define how to output buffered data-
_output_buffer()¶ Abstract method
Output all the data contained in the buffer
- Parameters
data – data to output
-
add(result)¶ Add the given data to the buffer
- Parameters
result – data that must be added to the buffer
-
property
buffer¶ Return the buffer content
- Return type
List[Result]- Returns
a list of all the
Resultinstances contained in the buffer
-
save()¶ Output each data in the buffer and empty the buffer
-
Class¶
-
class
pyRAPL.outputs.PrintOutput(raw=False)¶ Output that print data on standard output
- Parameters
raw (
bool) – if True, print the raw result class to standard output. Otherwise, print a fancier representation of result
-
add(result)¶ print result on standard output
- Parameters
result (
Result) – data to print
-
class
pyRAPL.outputs.CSVOutput(filename, separator=', ', append=True)¶ Write the recorded measure in csv format on a file
if the file already exists, the result will be append to the end of the file, otherwise it will create a new file.
This instance act as a buffer. The method
addadd data to the buffer and the methodsaveappend each data in the buffer at the end of the csv file. After that, the buffer is flushed- Parameters
filename (
str) – file’s name were the result will be writtenseparator (
str) – character used to separate columns in the csv fileappend (
bool) – Turn it to False to delete file if it already exist.
-
class
pyRAPL.outputs.MongoOutput(uri, database, collection)¶ Store the recorded measure in a MongoDB database
This instance act as a buffer. The method
addadd data to the buffer and the methodsavestore each data in the buffer in the MongoDB database. After that, the buffer is flushed- Parameters
uri (
str) – uri used to connect to the mongoDB instancedatabase (
str) – database name to store the datacollection (
str) – collection name to store the data