Skip to main content

Mojo struct

ProfileBlock

struct ProfileBlock[enabled: Bool = False]

A struct for profiling code blocks.

This struct provides context manager functionality to profile code blocks. When enabled, it records the start and end time of the block and prints the timing information.

Parameters

  • enabled (Bool): Whether profiling is enabled for this block.

Fields

  • name (StringSlice[StaticConstantOrigin]): Name of the profiling block used for identification in timing output.
  • loc (_SourceLocation): Source code location information for the profiling block, including file, line, and column.
  • start_time (UInt): Start time of the profiling block in nanoseconds, captured using perf_counter_ns().

Implemented traits

AnyType, ExplicitlyCopyable, ImplicitlyCopyable, Movable, UnknownDestructibility

Aliases

__copyinit__is_trivial

alias __copyinit__is_trivial = True

__del__is_trivial

alias __del__is_trivial = True

__moveinit__is_trivial

alias __moveinit__is_trivial = True

Methods

__init__

__init__(out self, name: StringSlice[StaticConstantOrigin])

Initialize a new ProfileBlock.

Args:

  • name (StringSlice): Name to identify this profiling block.

__enter__

__enter__(mut self)

Enter the profiling block and record start time if enabled.

__exit__

__exit__(mut self)

Exit the profiling block, record end time and print timing if enabled.

Was this page helpful?