Skip to content

Trace

zelos_sdk.trace

TraceSourceCacheLast(name)

A TraceSource wrapper that caches the last value of each field.

Example: source = TraceSourceCacheLast("motor_controller") source.add_event("motor_stats", [ TraceEventFieldMetadata("rpm", DataType.Float64), TraceEventFieldMetadata("torque", DataType.Float64, "Nm") ])

# Log some data
source.log("motor_stats", {"rpm": 3500.0, "torque": 42.8})

# Access cached values
assert source.motor_stats.rpm.get() == 3500.0
assert source.motor_stats.torque.get() == 42.8

# Dictionary-style access
assert source["motor_stats"].rpm.get() == 3500.0
assert source["motor_stats/rpm"] == 3500.0

# Log via event object
source.motor_stats.log(rpm=3250.0, torque=45.2)

__getattr__(name)

Get an event by attribute access. Only returns existing events.

__getitem__(key)

Support dictionary-style access for events and fields.

Examples: source["my_event"] # Returns TraceSourceCacheLastEvent source["my_event/subevent"] # Returns nested TraceSourceCacheLastEvent source["my_event/field"] # Returns TraceSourceCacheLastField object source["event/sub/field"] # Returns deeply nested TraceSourceCacheLastField object

add_event(name, schema, conditions=None)

Add an event to the source and create a cached version.

get_source()

Get the underlying TraceSource.

log(name, data)

Log data to an event and update the cache.

log_at(time_ns, name, data)

Log data to an event at a specific time and update the cache.

set_default_log_condition(condition=DefaultLogCondition())

Set a default log condition that applies to all fields without explicit conditions.

This will also update existing fields that currently use the default condition to use the new default.

Args: condition: The default logging condition to use, or None to disable default conditions.

TraceSourceCacheLastEvent(name, event, source, conditions=None)

A cached event that provides access to fields and submessages.

Example: event = source.motor_stats event.rpm.get() # Get field value event.thermal.temp.get() # Get nested field value event.log(rpm=3500) # Log new values

get_field(name)

Get a field by name, even if there's a submessage with the same name.

get_submessage(name)

Get a submessage by name.

log(**kwargs)

Log values to this event and update the cache.

log_at(time_ns, **kwargs)

Log values to this event at a specific time and update the cache.

TraceSourceCacheLastField(name, metadata, full_path, condition=None, uses_default=False)

A cached field that stores the last logged value.

Example: field = event.rpm # Get field field.get() # Get cached value field.name # Get full path like "motor_stats.rpm"

data_type property

Get the field's data type.

get()

Get the cached value.

on_logged(value, current_time_ns)

Called when this field is actually logged.

set(value)

Set the cached value.

should_log(value, current_time_ns)

Check if this field should be logged based on its condition.