Skip to main content

Python function

traced

traced()

max.profiler.traced(func: _FuncType, *, message: str | None = None, color: str = 'modular_purple') → _FuncType

source

max.profiler.traced(func: None = None, *, message: str | None = None, color: str = 'modular_purple') → Callable[[_FuncType], _FuncType]

Decorator for creating a profiling span for a function.

Creates a profiling span that measures the execution time of the decorated function. This is useful for identifying performance bottlenecks without modifying the function’s internal code. The decorator supports both synchronous and asynchronous functions.

from max.profiler import traced

@traced(message="inference", color="red")
def run_model() -> None:
    # The profiling span is named "inference"
    model.execute()

# Decorator with default span name (uses function name)
@traced
def preprocess_data() -> None:
    # The profiling span is named "preprocess_data"
    data.normalize()

Parameters:

  • func – The function to profile.
  • message – The name of the profiling span. If None, uses the function name.
  • color – The color of the profiling span for visualization tools.

Returns:

The decorated function wrapped in a trace object.

Return type:

Callable