Skip to main content
Log in

Mojo struct

Trace

struct Trace[level: TraceLevel, *, category: TraceCategory = TraceCategory(4), target: Optional[StringSlice[StaticConstantOrigin]] = Optional(None)]

An object representing a specific trace.

This struct provides functionality for creating and managing trace events for profiling and debugging purposes.

Parameters

  • level (TraceLevel): The trace level to use.
  • category (TraceCategory): The trace category to use (defaults to TraceCategory.MAX).
  • target (Optional[StringSlice[StaticConstantOrigin]]): Optional target information to include in the trace.

Fields

  • int_payload (OptionalReg[Int]): Optional integer payload, typically used for task IDs that are appended to trace names.
  • detail (String): Additional details about the trace event, included when detailed tracing is enabled.
  • event_id (Int): Unique identifier for the trace event, assigned when the trace begins.
  • parent_id (Int): Identifier of the parent trace event, used for creating hierarchical trace relationships.

Implemented traits

AnyType, Copyable, ExplicitlyCopyable, Movable, UnknownDestructibility

Methods

__init__

__init__(out self, *, owned _name_value: Variant[String, StringSlice[StaticConstantOrigin]], detail: String = __init__[__mlir_type.!kgen.string](""), parent_id: Int = 0, task_id: OptionalReg[Int] = OptionalReg[Int]({:i1 0, 1}))

Creates a Mojo trace with the given name.

Args:

  • _name_value (Variant[String, StringSlice[StaticConstantOrigin]]): The name that is used to identify this Mojo trace.
  • detail (String): Details of the trace entry.
  • parent_id (Int): Parent to associate the trace with. Trace name will be appended to parent name. 0 (default) indicates no parent.
  • task_id (OptionalReg[Int]): Int that is appended to name.

__init__(out self, owned name: String, detail: String = __init__[__mlir_type.!kgen.string](""), parent_id: Int = 0, *, task_id: OptionalReg[Int] = OptionalReg[Int]({:i1 0, 1}))

Creates a Mojo trace with the given string name.

Args:

  • name (String): The name that is used to identify this Mojo trace.
  • detail (String): Details of the trace entry.
  • parent_id (Int): Parent to associate the trace with. Trace name will be appended to parent name. 0 (default) indicates no parent.
  • task_id (OptionalReg[Int]): Int that is appended to name.

__init__(out self, name: StringSlice[StaticConstantOrigin], detail: String = __init__[__mlir_type.!kgen.string](""), parent_id: Int = 0, *, task_id: OptionalReg[Int] = OptionalReg[Int]({:i1 0, 1}))

Creates a Mojo trace with the given static string name.

Args:

  • name (StringSlice[StaticConstantOrigin]): The name that is used to identify this Mojo trace.
  • detail (String): Details of the trace entry.
  • parent_id (Int): Parent to associate the trace with. Trace name will be appended to parent name. 0 (default) indicates no parent.
  • task_id (OptionalReg[Int]): Int that is appended to name.

__init__(out self, name: StringLiteral[value], detail: String = __init__[__mlir_type.!kgen.string](""), parent_id: Int = 0, *, task_id: OptionalReg[Int] = OptionalReg[Int]({:i1 0, 1}))

Creates a Mojo trace with the given string literal name.

Args:

  • name (StringLiteral[value]): The name that is used to identify this Mojo trace.
  • detail (String): Details of the trace entry.
  • parent_id (Int): Parent to associate the trace with. Trace name will be appended to parent name. 0 (default) indicates no parent.
  • task_id (OptionalReg[Int]): Int that is appended to name.

__enter__

__enter__(mut self)

Enters the trace context.

This begins recording of the trace event.

__exit__

__exit__(self)

Exits the trace context.

This finishes recording of the trace event.

mark

mark(self)

Marks the tracer with the info at the specific point of time.

This creates a point event in the trace timeline rather than a range.

name

name(self) -> String

Returns the name of the trace.

Returns:

The name of the trace as a String.

start

start(mut self)

Start recording trace event.

This begins recording of the trace event, similar to enter.

end

end(mut self)

End recording trace event.

This finishes recording of the trace event, similar to exit.