Skip to content

qttools.profiling.profiler#

source module qttools.profiling.profiler

Classes

  • Profiler Singleton Profiler class to collect and report profiling data.

source class Profiler()

Singleton Profiler class to collect and report profiling data.

Attributes

  • eventlog : list A list of profiling data.

  • devices : list A list of CUDA device IDs.

Methods

  • get_stats Computes statistics from profiling data accross all ranks.

  • 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.

source method Profiler.get_stats()dict

Computes statistics from profiling data accross all ranks.

Returns

  • dict A dictionary containing the profiling data.

source method Profiler.dump_stats(filepath: str, format: Literal['pickle', 'json'] = 'pickle')

Dumps the profiling statistics to a file.

Parameters

  • filepath : str The path to the output file. The correct file extension will be appended based on the format.

  • format : {"pickle", "json"}, optional The format in which to save the profiling data.

Raises

  • ValueError

source method Profiler.profile(level: str = QTX_PROFILE_LEVEL)

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

Notes

Two environment variables control the profiling behavior: - PROFILE_GPU: Whether to separately measure the time spent on the GPU. If turned on, this will cause device synchronization for every profiled event. - PROFILE_LEVEL: The profiling level for functions. The following levels are implemented: - "off": The function is not profiled. - "basic": The function is part of the core profiling. - "api": The function is part of the API and does not always need to be timed. It is part of the underlying infrastructure. - "debug": This function only needs to be profiled for debugging purposes. - "full": The function does not even need to be profiled for debugging purposes unless the user explicitly requests it.

Parameters

  • level : str, optional The profiling level controls whether the function is profiled or not. By default, the level is set to the PROFILE_LEVEL environment variable. The function is thus always profiled. The following levels are implemented:

    • "off": The function is not profiled.
    • "basic": The function is part of the core profiling.
    • "api": The function is part of the API and does not always need to be timed. It is part of the underlying infrastructure.
    • "debug": This function only needs to be profiled for debugging purposes.
    • "full": The function does not even need to be profiled for debugging purposes unless the user explicitly requests it to be profiled.

Returns

  • callable The wrapped function with profiling according to the specified level.

Raises

  • ValueError

source method Profiler.profile_range(label: str = 'range', level: str = QTX_PROFILE_LEVEL)

Profiles a range of code.

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

Parameters

  • label : str, optional A label for the profiled range. This is used to identify the profiled range in the profiling data.

  • level : str, optional The profiling level controls whether the function is profiled or not. By default, the function is always profiled, irrespective of the PROFILE_LEVEL environment variable. The following levels are implemented:

    • "off": The function is not profiled.
    • "basic": The function is part of the core profiling.
    • "api": The function is part of the API and does not always need to be timed. It is part of the underlying infrastructure.
    • "debug": This function only needs to be profiled for debugging purposes.
    • "full": The function does not even need to be profiled for debugging purposes unless the user explicitly requests it to be profiled.

Yields

  • None The context manager does not return anything.

Raises

  • ValueError