API Documentation

Subpackages

wattameter.tracker module

class wattameter.tracker.BaseTracker(dt_read: float = 1.0) None

Bases: AbstractContextManager

Base class for trackers that read data at a specified frequency.

Parameters:

dt_read (float) – Time interval (in seconds) between consecutive readings. (default: 1.0)

abstractmethod read() float

Read data.

Return type:

float

Returns:

Time taken for the reading (in seconds).

start(freq_write: int = 0)

Start asynchronous task _update_series().

Parameters:

freq_write (int) – Frequency (in number of reads) to write the collected data. If set to 0, data is never written. (default: 0)

stop(freq_write: int = 0)

Stop async task _update_series() and reads data one last time.

On exit, perform a final read and write of the collected data.

Parameters:

freq_write (int) – Frequency (in number of reads) to write the collected data. If set to 0, data is never written. (default: 0)

track_until_forced_exit(freq_write: int = 0, *args, **kwargs)

Track data as the main task of the program until a forced exit.

On exit, perform a final read and write of the collected data.

Note

This is the preferred way to track data of programs that are being executed in the machine. This method will block the main thread until a forced exit is detected (e.g., SIGINT or SIGTERM).

Parameters:

freq_write (int) – Frequency (in number of reads) to write the collected data. If set to 0, data is never written. (default: 0)

abstractmethod write() None

Write data.

Return type:

None

abstractmethod write_header() None

Write header.

Return type:

None

class wattameter.tracker.Tracker(reader: BaseReader, dt_read: float = 1.0, freq_write: int = 3600, output=None) None

Bases: BaseTracker

Generic tracker that reads data from a BaseReader at a specified frequency.

Parameters:
  • reader (BaseReader) – An instance of BaseReader to read data from.

  • dt_read (float) – Time interval (in seconds) between consecutive readings. (default: 1.0)

  • freq_write (int) – Frequency (in number of reads) to write the collected data. If set to 0, data is never written. (default: 3600)

  • output – Optional output stream to write the collected data. If not provided, the output stream is as defined in output(). (default: None)

reader

An instance of BaseReader that provides the data to be tracked.

time_series

A deque that stores the timestamps of the readings.

reading_time

A deque that stores the time taken for each reading (in nanoseconds). This information can be useful for adjusting the reading frequency. Usually, the time taken for reading should be much smaller than dt_read.

data

A deque that stores the data read from the reader.

freq_write

Frequency (in number of reads) to write the collected data. If set to 0, data is never written.

flush_data()

Flush all collected data from the tracker.

Returns:

A tuple containing three lists:

  • time_series: List of timestamps (in nanoseconds).

  • reading_time: List of time taken for each reading (in nanoseconds).

  • data: 2D array of the collected data. Each row corresponds to a reading, and each column corresponds to a quantity read by the reader.

format_timestamp(timestamp_ns: int) str

Format a timestamp in nanoseconds to a human-readable string.

Parameters:

timestamp_ns (int) – Timestamp in nanoseconds.

Return type:

str

property output

Output file to write the collected data.

read() float

Read data.

Return type:

float

Returns:

Time taken for the reading (in seconds).

track_until_forced_exit()

Track data as the main task of the program until a forced exit.

On exit, perform a final read and write of the collected data.

Note

This is the preferred way to track data of programs that are being executed in the machine. This method will block the main thread until a forced exit is detected (e.g., SIGINT or SIGTERM).

Parameters:

freq_write – Frequency (in number of reads) to write the collected data. If set to 0, data is never written.

write()

Write data.

write_data(time_series, reading_time, data)

Write the collected data to the output stream.

Parameters:
  • time_series – Array of timestamps (in nanoseconds).

  • reading_time – Array of time taken for each reading (in nanoseconds).

  • data – 2D array of the collected data. Each row corresponds to a reading, and each column corresponds to a quantity read by the reader.

write_header()

Write the header to the output stream.

class wattameter.tracker.TrackerArray(readers: list[BaseReader], dt_read: float = 1.0, freq_write: int = 3600, outputs: list = []) None

Bases: BaseTracker

Tracker that manages multiple Tracker instances.

Parameters:
  • readers (list[BaseReader]) – List of BaseReader instances to read data from.

  • dt_read (float) – Time interval (in seconds) between consecutive readings. (default: 1.0)

  • freq_write (int) – Frequency (in number of reads) to write the collected data. If set to 0, data is never written. (default: 3600)

  • outputs (list) – List of output streams for each tracker. If not provided, the output streams are as defined in each tracker’s output(). (default: [])

trackers

List of Tracker instances managed by this tracker.

freq_write

Frequency (in number of reads) to write the collected data. If set to 0, data is never written.

read() float

Read data.

Return type:

float

Returns:

Time taken for the reading (in seconds).

track_until_forced_exit()

Track data as the main task of the program until a forced exit.

On exit, perform a final read and write of the collected data.

Note

This is the preferred way to track data of programs that are being executed in the machine. This method will block the main thread until a forced exit is detected (e.g., SIGINT or SIGTERM).

Parameters:

freq_write – Frequency (in number of reads) to write the collected data. If set to 0, data is never written.

write()

Write data.

write_header() None

Write header.

Return type:

None