Skip to content

Extra Tools from hydra callbacks

Resource Monitor Utilities.

ProcessTimer

Bases: Process

Timer behavior using Process instead of Thread.

Using a process make sure that we won't be block by the GIL.

Adapted from: https://stackoverflow.com/a/25297758

cancel()

Stop the timer if it hasn't finished yet.

run()

Run the timer.

ResourceMonitorService

A Service that monitor a PID with a certain frequency to a file.

A threading or a process backend is available. The process backend is recommended for single core application that do not release the GIL. The threading backend is recommended for multi core / multi processes application that release the GIL

Adapted from: https://github.com/nipy/nipype/blob/master/nipype/utils/profiler.py

Parameters:

  • pid (int | None, default: None ) –

    The process ID to monitor

  • interval (int | float, default: 1 ) –

    The sampling interval in seconds, default 1s.

  • base_name (str, default: '' ) –

    Base name for the monitoring trace file.

  • gpu_monit (bool, default: False ) –

    If True, also monitor gpu usage and memory, default False.

__del__()

Close the log file.

get_values()

Return the values collected by the monitor.

start()

Start monitoring.

stop()

Stop monitoring.

int_or_0(byte_str)

Return the int value of a byte string or 0.

Performance tracking tool.

PerfLogger

Simple Performance logger to use as a context manager.

Parameters:

  • logger (Logger | Callable) –

    A logger object or a callable

  • level (int, default: INFO ) –

    log level, default=0 , infos

  • time_format (str, default: '{name} duration: {:.2f}s' ) –

    format string to display the elapsed time

Example

with PerfLogger(print) as pfl: time.sleep(1)

get_timer(name) classmethod

Return the elapsed time of a timer.

recap(logger=None) classmethod

Return a string summarizing all the registered timers.

reset() classmethod

Reset all the registered timers.