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 (
StringLiteral
): 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
,
Copyable
,
ExplicitlyCopyable
,
Movable
,
UnknownDestructibility
Methods
__init__
@implicit
__init__(out self, name: StringLiteral)
Initialize a new ProfileBlock.
Args:
- name (
StringLiteral
): 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?
Thank you! We'll create more content like this.
Thank you for helping us improve!