ChibiOS 21.11.4
Tracing

Detailed Description

System events tracing service.

Collaboration diagram for Tracing:

Trace record types

#define CH_TRACE_TYPE_UNUSED   0U
#define CH_TRACE_TYPE_READY   1U
#define CH_TRACE_TYPE_SWITCH   2U
#define CH_TRACE_TYPE_ISR_ENTER   3U
#define CH_TRACE_TYPE_ISR_LEAVE   4U
#define CH_TRACE_TYPE_HALT   5U
#define CH_TRACE_TYPE_USER   6U

Events to trace

#define CH_DBG_TRACE_MASK_DISABLED   255U
#define CH_DBG_TRACE_MASK_NONE   0U
#define CH_DBG_TRACE_MASK_READY   1U
#define CH_DBG_TRACE_MASK_SWITCH   2U
#define CH_DBG_TRACE_MASK_ISR   4U
#define CH_DBG_TRACE_MASK_HALT   8U
#define CH_DBG_TRACE_MASK_USER   16U
#define CH_DBG_TRACE_MASK_SLOW
#define CH_DBG_TRACE_MASK_ALL

Debug related settings

#define CH_DBG_TRACE_MASK   CH_DBG_TRACE_MASK_DISABLED
 Trace buffer entries.
#define CH_DBG_TRACE_BUFFER_SIZE   128
 Trace buffer entries.

Data Structures

struct  trace_event_t
 Trace buffer record. More...
struct  trace_buffer_t
 Trace buffer header. More...

Macros

#define __trace_ready(tp, msg)
#define __trace_switch(ntp, otp)
#define __trace_isr_enter(isr)
#define __trace_isr_leave(isr)
#define __trace_halt(reason)
#define chDbgWriteTraceI(up1, up2)
#define chDbgWriteTrace(up1, up2)

Functions

static NOINLINE void trace_next (os_instance_t *oip)
 Writes a time stamp and increases the trace buffer pointer.
void __trace_object_init (trace_buffer_t *tbp)
 Circular trace buffer initialization.
void __trace_ready (thread_t *tp, msg_t msg)
 Inserts in the circular debug trace buffer a ready record.
void __trace_switch (thread_t *ntp, thread_t *otp)
 Inserts in the circular debug trace buffer a context switch record.
void __trace_isr_enter (const char *isr)
 Inserts in the circular debug trace buffer an ISR-enter record.
void __trace_isr_leave (const char *isr)
 Inserts in the circular debug trace buffer an ISR-leave record.
void __trace_halt (const char *reason)
 Inserts in the circular debug trace buffer an halt record.
void chTraceWriteI (void *up1, void *up2)
 Adds an user trace record to the trace buffer.
void chTraceWrite (void *up1, void *up2)
 Adds an user trace record to the trace buffer.
void chTraceSuspendI (uint16_t mask)
 Suspends one or more trace events.
void chTraceSuspend (uint16_t mask)
 Suspends one or more trace events.
void chTraceResumeI (uint16_t mask)
 Resumes one or more trace events.
void chTraceResume (uint16_t mask)
 Resumes one or more trace events.

Macro Definition Documentation

◆ CH_TRACE_TYPE_UNUSED

#define CH_TRACE_TYPE_UNUSED   0U

Definition at line 39 of file chtrace.h.

Referenced by __trace_object_init().

◆ CH_TRACE_TYPE_READY

#define CH_TRACE_TYPE_READY   1U

Definition at line 40 of file chtrace.h.

Referenced by __trace_ready().

◆ CH_TRACE_TYPE_SWITCH

#define CH_TRACE_TYPE_SWITCH   2U

Definition at line 41 of file chtrace.h.

Referenced by __trace_switch().

◆ CH_TRACE_TYPE_ISR_ENTER

#define CH_TRACE_TYPE_ISR_ENTER   3U

Definition at line 42 of file chtrace.h.

Referenced by __trace_isr_enter().

◆ CH_TRACE_TYPE_ISR_LEAVE

#define CH_TRACE_TYPE_ISR_LEAVE   4U

Definition at line 43 of file chtrace.h.

Referenced by __trace_isr_leave().

◆ CH_TRACE_TYPE_HALT

#define CH_TRACE_TYPE_HALT   5U

Definition at line 44 of file chtrace.h.

Referenced by __trace_halt().

◆ CH_TRACE_TYPE_USER

#define CH_TRACE_TYPE_USER   6U

Definition at line 45 of file chtrace.h.

Referenced by chTraceWriteI().

◆ CH_DBG_TRACE_MASK_DISABLED

#define CH_DBG_TRACE_MASK_DISABLED   255U

Definition at line 52 of file chtrace.h.

◆ CH_DBG_TRACE_MASK_NONE

#define CH_DBG_TRACE_MASK_NONE   0U

Definition at line 53 of file chtrace.h.

◆ CH_DBG_TRACE_MASK_READY

#define CH_DBG_TRACE_MASK_READY   1U

Definition at line 54 of file chtrace.h.

Referenced by __trace_ready().

◆ CH_DBG_TRACE_MASK_SWITCH

#define CH_DBG_TRACE_MASK_SWITCH   2U

Definition at line 55 of file chtrace.h.

Referenced by __trace_switch().

◆ CH_DBG_TRACE_MASK_ISR

#define CH_DBG_TRACE_MASK_ISR   4U

Definition at line 56 of file chtrace.h.

Referenced by __trace_isr_enter(), and __trace_isr_leave().

◆ CH_DBG_TRACE_MASK_HALT

#define CH_DBG_TRACE_MASK_HALT   8U

Definition at line 57 of file chtrace.h.

Referenced by __trace_halt().

◆ CH_DBG_TRACE_MASK_USER

#define CH_DBG_TRACE_MASK_USER   16U

Definition at line 58 of file chtrace.h.

Referenced by chTraceWriteI().

◆ CH_DBG_TRACE_MASK_SLOW

#define CH_DBG_TRACE_MASK_SLOW
Value:
#define CH_DBG_TRACE_MASK_USER
Definition chtrace.h:58
#define CH_DBG_TRACE_MASK_HALT
Definition chtrace.h:57
#define CH_DBG_TRACE_MASK_READY
Definition chtrace.h:54
#define CH_DBG_TRACE_MASK_SWITCH
Definition chtrace.h:55

Definition at line 59 of file chtrace.h.

◆ CH_DBG_TRACE_MASK_ALL

#define CH_DBG_TRACE_MASK_ALL

◆ CH_DBG_TRACE_MASK

#define CH_DBG_TRACE_MASK   CH_DBG_TRACE_MASK_DISABLED

Trace buffer entries.

Definition at line 82 of file chtrace.h.

◆ CH_DBG_TRACE_BUFFER_SIZE

#define CH_DBG_TRACE_BUFFER_SIZE   128

Trace buffer entries.

Note
The trace buffer is only allocated if CH_DBG_TRACE_MASK is different from CH_DBG_TRACE_MASK_DISABLED.

Definition at line 91 of file chtrace.h.

Referenced by __trace_object_init(), and trace_next().

◆ __trace_ready

#define __trace_ready ( tp,
msg )

Definition at line 221 of file chtrace.h.

Referenced by __sch_ready_ahead(), and __sch_ready_behind().

◆ __trace_switch

#define __trace_switch ( ntp,
otp )

Definition at line 224 of file chtrace.h.

◆ __trace_isr_enter

#define __trace_isr_enter ( isr)

Definition at line 227 of file chtrace.h.

◆ __trace_isr_leave

#define __trace_isr_leave ( isr)

Definition at line 230 of file chtrace.h.

◆ __trace_halt

#define __trace_halt ( reason)

Definition at line 233 of file chtrace.h.

Referenced by chSysHalt().

◆ chDbgWriteTraceI

#define chDbgWriteTraceI ( up1,
up2 )

Definition at line 236 of file chtrace.h.

◆ chDbgWriteTrace

#define chDbgWriteTrace ( up1,
up2 )

Definition at line 239 of file chtrace.h.

Function Documentation

◆ trace_next()

NOINLINE void trace_next ( os_instance_t * oip)
static

Writes a time stamp and increases the trace buffer pointer.

Function Class:
Not an API, this function is for internal use only.

Definition at line 57 of file chtrace.c.

References trace_buffer_t::buffer, CH_CFG_TRACE_HOOK, CH_DBG_TRACE_BUFFER_SIZE, chSysGetRealtimeCounterX, chVTGetSystemTimeX, NOINLINE, trace_buffer_t::ptr, trace_event_t::rtstamp, trace_event_t::time, and ch_os_instance::trace_buffer.

Referenced by __trace_halt(), __trace_isr_enter(), __trace_isr_leave(), __trace_ready(), __trace_switch(), and chTraceWriteI().

◆ __trace_object_init()

void __trace_object_init ( trace_buffer_t * tbp)

Circular trace buffer initialization.

Note
Internal use only.
Parameters
[out]tbppointer to the trace_buffer_t structure
Function Class:
Not an API, this function is for internal use only.

Definition at line 88 of file chtrace.c.

References trace_buffer_t::buffer, CH_DBG_TRACE_BUFFER_SIZE, CH_DBG_TRACE_MASK, CH_TRACE_TYPE_UNUSED, trace_buffer_t::ptr, trace_buffer_t::size, trace_buffer_t::suspended, and trace_event_t::type.

Referenced by chInstanceObjectInit().

◆ __trace_ready()

void __trace_ready ( thread_t * tp,
msg_t msg )

Inserts in the circular debug trace buffer a ready record.

Parameters
[in]tpthe thread that just become ready
[in]msgthe thread ready message
Function Class:
Not an API, this function is for internal use only.

Definition at line 107 of file chtrace.c.

References CH_DBG_TRACE_MASK_READY, CH_TRACE_TYPE_READY, currcore, trace_event_t::msg, trace_buffer_t::ptr, trace_event_t::rdy, ch_thread::state, trace_event_t::state, trace_buffer_t::suspended, trace_event_t::tp, ch_os_instance::trace_buffer, trace_next(), trace_event_t::type, and trace_event_t::u.

Here is the call graph for this function:

◆ __trace_switch()

void __trace_switch ( thread_t * ntp,
thread_t * otp )

Inserts in the circular debug trace buffer a context switch record.

Parameters
[in]ntpthe thread being switched in
[in]otpthe thread being switched out
Function Class:
Not an API, this function is for internal use only.

Definition at line 127 of file chtrace.c.

References CH_DBG_TRACE_MASK_SWITCH, CH_TRACE_TYPE_SWITCH, currcore, trace_event_t::ntp, trace_buffer_t::ptr, ch_thread::state, trace_event_t::state, trace_buffer_t::suspended, trace_event_t::sw, ch_os_instance::trace_buffer, trace_next(), trace_event_t::type, ch_thread::u, trace_event_t::u, ch_thread::wtobjp, and trace_event_t::wtobjp.

Here is the call graph for this function:

◆ __trace_isr_enter()

void __trace_isr_enter ( const char * isr)

Inserts in the circular debug trace buffer an ISR-enter record.

Parameters
[in]isrname of the isr
Function Class:
Not an API, this function is for internal use only.

Definition at line 146 of file chtrace.c.

References CH_DBG_TRACE_MASK_ISR, CH_TRACE_TYPE_ISR_ENTER, currcore, trace_event_t::isr, trace_event_t::name, port_lock_from_isr(), port_unlock_from_isr(), trace_buffer_t::ptr, trace_event_t::state, trace_buffer_t::suspended, ch_os_instance::trace_buffer, trace_next(), trace_event_t::type, and trace_event_t::u.

Here is the call graph for this function:

◆ __trace_isr_leave()

void __trace_isr_leave ( const char * isr)

Inserts in the circular debug trace buffer an ISR-leave record.

Parameters
[in]isrname of the isr
Function Class:
Not an API, this function is for internal use only.

Definition at line 166 of file chtrace.c.

References CH_DBG_TRACE_MASK_ISR, CH_TRACE_TYPE_ISR_LEAVE, currcore, trace_event_t::isr, trace_event_t::name, port_lock_from_isr(), port_unlock_from_isr(), trace_buffer_t::ptr, trace_event_t::state, trace_buffer_t::suspended, ch_os_instance::trace_buffer, trace_next(), trace_event_t::type, and trace_event_t::u.

Here is the call graph for this function:

◆ __trace_halt()

void __trace_halt ( const char * reason)

Inserts in the circular debug trace buffer an halt record.

Parameters
[in]reasonthe halt error string
Function Class:
Not an API, this function is for internal use only.

Definition at line 186 of file chtrace.c.

References CH_DBG_TRACE_MASK_HALT, CH_TRACE_TYPE_HALT, currcore, trace_event_t::halt, trace_buffer_t::ptr, trace_event_t::reason, trace_event_t::state, trace_buffer_t::suspended, ch_os_instance::trace_buffer, trace_next(), trace_event_t::type, and trace_event_t::u.

Here is the call graph for this function:

◆ chTraceWriteI()

void chTraceWriteI ( void * up1,
void * up2 )

Adds an user trace record to the trace buffer.

Parameters
[in]up1user parameter 1
[in]up2user parameter 2
Function Class:
This is an I-Class API, this function can be invoked from within a system lock zone by both threads and interrupt handlers.

Definition at line 205 of file chtrace.c.

References CH_DBG_TRACE_MASK_USER, CH_TRACE_TYPE_USER, chDbgCheckClassI, currcore, trace_buffer_t::ptr, trace_event_t::state, trace_buffer_t::suspended, ch_os_instance::trace_buffer, trace_next(), trace_event_t::type, trace_event_t::u, trace_event_t::up1, trace_event_t::up2, and trace_event_t::user.

Referenced by chTraceWrite().

Here is the call graph for this function:

◆ chTraceWrite()

void chTraceWrite ( void * up1,
void * up2 )

Adds an user trace record to the trace buffer.

Parameters
[in]up1user parameter 1
[in]up2user parameter 2
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 227 of file chtrace.c.

References chSysLock, chSysUnlock, and chTraceWriteI().

Here is the call graph for this function:

◆ chTraceSuspendI()

void chTraceSuspendI ( uint16_t mask)

Suspends one or more trace events.

Parameters
[in]maskmask of the trace events to be suspended
Function Class:
This is an I-Class API, this function can be invoked from within a system lock zone by both threads and interrupt handlers.

Definition at line 241 of file chtrace.c.

References chDbgCheckClassI, and currcore.

Referenced by chTraceSuspend().

◆ chTraceSuspend()

void chTraceSuspend ( uint16_t mask)

Suspends one or more trace events.

Parameters
[in]maskmask of the trace events to be suspended
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 255 of file chtrace.c.

References chSysLock, chSysUnlock, and chTraceSuspendI().

Here is the call graph for this function:

◆ chTraceResumeI()

void chTraceResumeI ( uint16_t mask)

Resumes one or more trace events.

Parameters
[in]maskmask of the trace events to be resumed
Function Class:
This is an I-Class API, this function can be invoked from within a system lock zone by both threads and interrupt handlers.

Definition at line 269 of file chtrace.c.

References chDbgCheckClassI, and currcore.

Referenced by chTraceResume().

◆ chTraceResume()

void chTraceResume ( uint16_t mask)

Resumes one or more trace events.

Parameters
[in]maskmask of the trace events to be resumed
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 283 of file chtrace.c.

References chSysLock, chSysUnlock, and chTraceResumeI().

Here is the call graph for this function: