IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /get-started.md). For the complete documentation index, see llms.txt.
Skip to main content
For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /get-started.md).

Mojo struct

Trace

struct Trace[level: TraceLevel, *, category: TraceCategory = TraceCategory.MAX, target: Optional[StringSlice[ImmStaticOrigin]] = None]

An object representing a specific trace.

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

Parameters​

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.
  • ​color (Optional[Color]): Color of the trace span in NSight Systems viewer, only used for NVTX markers.

Implemented traits​

AnyType, Copyable, ImplicitlyCopyable, ImplicitlyDeletable, Movable

Methods​

__init__​

def __init__(out self, *, var _name_value: Variant[String, StringSlice[ImmStaticOrigin]], detail: String = "", parent_id: Int = Int(0), task_id: OptionalReg[Int] = None, color: Optional[Color] = None)

Creates a Mojo trace with the given name.

Args:

  • ​_name_value (Variant[String, StringSlice[ImmStaticOrigin]]): 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.
  • ​color (Optional[Color]): Color of the trace span when visualized.

def __init__(out self, var name: String, detail: String = "", parent_id: Int = Int(0), color: Optional[Color] = None, *, task_id: OptionalReg[Int] = None)

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.
  • ​color (Optional[Color]): Color of the trace span when visualized.
  • ​task_id (OptionalReg[Int]): Int that is appended to name.

def __init__(out self, name: StringSlice[ImmStaticOrigin], detail: String = "", parent_id: Int = Int(0), color: Optional[Color] = None, *, task_id: OptionalReg[Int] = None)

Creates a Mojo trace with the given static string name.

Args:

  • ​name (StringSlice[ImmStaticOrigin]): 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.
  • ​color (Optional[Color]): Color of the trace span when visualized.
  • ​task_id (OptionalReg[Int]): Int that is appended to name.

def __init__(out self, name: StringLiteral, detail: String = "", parent_id: Int = Int(0), color: Optional[Color] = None, *, task_id: OptionalReg[Int] = None)

Creates a Mojo trace with the given string literal name.

Args:

  • ​name (StringLiteral): 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.
  • ​color (Optional[Color]): Color of the trace span when visualized.
  • ​task_id (OptionalReg[Int]): Int that is appended to name.

__enter__​

def __enter__(mut self)

Enters the trace context.

This begins recording of the trace event.

Raises:

If the operation fails.

__exit__​

def __exit__(self)

Exits the trace context.

This finishes recording of the trace event.

mark​

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

Raises:

If the operation fails.

name​

def name(self) -> String

Returns the name of the trace.

Returns:

String: The name of the trace as a String.

start​

def start(mut self)

Start recording trace event.

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

Raises:

If the operation fails.

end​

def end(mut self)

End recording trace event.

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

Raises:

If the operation fails.