Skip to content

profiler#

Includes the profiling singleton class.

Classes:

  • Profiler

    Singleton Profiler class to collect and report profiling data.

Profiler #

Singleton Profiler class to collect and report profiling data.

Attributes:

  • eventlog (list) –

    A list of profiling data.

  • depth (int) –

    The current depth of the profiled functions. This is used to indent the printed profiling data.

  • print_file (_OutputFile) –

    The file to which the profiling data is printed. This can be set through the set_parameters method.

  • save_path (Path) –

    The path to which the profiling data is saved. This can be set through the set_parameters method.

  • save_format (str) –

    The format in which the profiling data is saved. This can be set through the set_parameters method. The following formats are supported: - "pickle": The profiling data is saved as a pickle file. - "json": The profiling data is saved as a json file.

Methods:

  • dump_stats

    Dumps the profiling statistics to a file.

  • profile

    Profiles a function and adds profiling data to the event log.

  • profile_range

    Profiles a range of code.

dump_stats #

dump_stats()

Dumps the profiling statistics to a file.

profile #

profile(label: str, level: str, comm=None)

Profiles a function and adds profiling data to the event log.

Notes

Two environment variables control the profiling behavior: - PROFILE_LEVEL: The profiling level for functions. The following levels are implemented: - "off": The function is not profiled. - "default": The function is part of the core profiling. - "debug": This function only needs to be profiled for debugging purposes. - PROFILE_COMM_SYNC: If set to True, a communicator barrier is called after the profiled function to ensure that all processes are synchronized before recording the end time. Through this, differences in between processes can be better captured.

Parameters:

  • label (str) –

    A label for the profiled range. This is used to identify the profiled range in the profiling data.

  • level (str) –

    The profiling level controls whether the function is profiled or not. The following levels are implemented: - "off": The function is not profiled. - "default": The function is part of the core profiling. - "debug": This function only needs to be profiled for debugging purposes.

  • comm (optional, default: None ) –

    An optional communicator to use for synchronization

Returns:

  • callable

    The wrapped function with profiling according to the specified level.

profile_range #

profile_range(label: str, level: str, comm=None)

Profiles a range of code.

This is a context manager that profiles a range of code.

Parameters:

  • label (str) –

    A label for the profiled range. This is used to identify the profiled range in the profiling data.

  • level (str) –

    The profiling level controls whether the function is profiled or not: - "off": The function is not profiled. - "default": The function is part of the core profiling. - "debug": This function only needs to be profiled for debugging purposes.

  • comm (optional, default: None ) –

    An optional communicator to use for synchronization. comm_world is not used to not potentially deadlock.

Yields:

  • None

    The context manager does not return anything.