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.
add_event_from_dict(name, data)
¶
Add an event from a dictionary and create a cached version.
Args: name: The name of the event. data: A dictionary representing the event data.
Returns: TraceSourceCacheLastEvent: The cached event.
add_value_table(name, field_name, data)
¶
Add a value table (enum mapping) to the underlying TraceSource.
Args: name: The name of the value table (typically the event name). field_name: The field name this value table applies to. data: A dictionary mapping integer values to string labels.
Examples: >>> source.add_value_table("motor_status", "state", {0: "stopped", 1: "running"})
get_event(name)
¶
Get a cached event by name.
Args: name: The name of the event.
Returns: TraceSourceCacheLastEvent: The cached event.
Raises: KeyError: If the event doesn't exist.
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.
log_dict(name, data)
¶
Log data to an event using dictionary format and update the cache.
This is an alias for log() to match the TraceSource API.
Args: name: The name of the event. data: A dictionary of field values to log.
log_dict_at(time_ns, name, data)
¶
Log data to an event at a specific time using dictionary format and update the cache.
This is an alias for log_at() to match the TraceSource API.
Args: time_ns: The timestamp in nanoseconds. name: The name of the event. data: A dictionary of field values to log.
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
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"