Code Generation

The set of possible tracing events and their fields is defined in a simple python code generation script here. Based on this, the c event encoder, an event event decoder test file, the rust event decoder, and the event index documentation is generated.

Example Output

Consider the following isr_name event as an example:

Field Name:idisr_idname
Field Type:u8u32str
Note:0x03requiredvarlen
  • Metadata: yes
  • Max length (unframed): 6 bytes + varlen field

C Encoder

First, the code generator will emit a macro that specifies if the event is a metadata event (meaning it should be appended to the metadata buffer) and a macro that gives the maximum framed length of the event so that a buffer can be pre-allocated. Then, a function is generated that takes the event fields and encodes them into a buffer, returning the actual encoded length of the message (including a trailing zero termination).

#define EVT_ISR_NAME_IS_METADATA (1)
#define EVT_ISR_NAME_MAXLEN (COBS_MAXLEN((6 + tband_configMAX_STR_LEN)))
static inline size_t encode_isr_name(uint8_t buf[EVT_ISR_NAME_MAXLEN], uint32_t isr_id, const char *name) {/* .. */}

Rust Decoder

The rust code generator emits a struct for each field, and a decoder function that attempts to reconstruct the event from a given buffer:

#[derive(Debug, Clone, Serialize)]
pub struct BaseIsrNameEvt {
    pub isr_id: u32,
    pub name: String,
}

impl BaseIsrNameEvt {
    fn decode(buf: &[u8], current_idx: &mut usize) -> anyhow::Result<RawEvt> { /* .. */ }
}