tracer Class Template
Tracing API bound to a given policy class. More...
Declaration
class micro_os_plus::trace::detail::tracer<T> { ... }
Included Headers
Public Constructors Index
template <trace_policy T> | |
| tracer ()=delete | |
|
Deleted default constructor. More... | |
Public Static Functions Index
template <trace_policy T> | |
| static void | dump_args (int argc, char *argv[], const char *name="main") noexcept |
|
Send the argv[] array to the trace output channel. More... | |
template <trace_policy T> | |
| static void | flush (void) noexcept |
|
Flush the trace output channel. More... | |
template <trace_policy T> | |
| static void | initialise (void) noexcept |
|
Initialise the trace output channel. More... | |
template <trace_policy T> | |
| static int | printf (const char *format,...) noexcept |
|
Write a formatted string to the trace output channel. More... | |
template <trace_policy T> | |
| static int | putchar (int c) noexcept |
|
Write the single character to the trace output channel. More... | |
template <trace_policy T> | |
| static int | puts (const char *s="") noexcept |
|
Write the string and a line terminator to the trace output channel. More... | |
template <trace_policy T> | |
| static int | vprintf (const char *format, std::va_list arguments) noexcept |
|
Write a formatted variable arguments list to the trace output channel. More... | |
template <trace_policy T> | |
| static ssize_t | write (const void *buf, std::size_t nbyte) noexcept |
|
Write the given number of bytes to the trace output channel. More... | |
Description
Tracing API bound to a given policy class.
- Template Parameters
-
T Policy class providing the static initialise(), write(), and flush() primitives (e.g. micro_os_plus::trace::detail::implementation).
All methods are static; tracer is never instantiated as an object. Each distinct T produces an independent set of methods with no shared state, so tracer<implementation> (or any further user-defined policy class) can coexist in the same translation unit and binary.
The main reason for using a class template rather than a namespace is that it allows the policy class to be a template parameter, so that multiple independent instances can coexist in the same binary, each bound to a different policy class. This is used in testing, where a testing_implementation policy class is defined to capture the output for verification.
Definition at line 403 of file cpp-api.h.
Public Constructors
tracer()
| delete |
Public Static Functions
dump_args()
| noexcept static |
Send the argv[] array to the trace output channel.
- Parameters
-
argc The number of argv[] strings.
argv An array of pointers to argument strings.
name A null terminated string used as the function name prefix (default: "main").
- Returns
Nothing.
Formats and writes the argument list in the form name(argc=N, argv=["arg0", "arg1", ...]), followed by a newline. Intended to be called at the start of main() to record the process arguments in the trace output. Each argument string is quoted; no escaping is applied to the string content.
Declaration at line 573 of file cpp-api.h, definition at line 210 of file cpp-api-inlines.h.
Reference micro_os_plus::trace::printf.
Referenced by micro_os_plus::trace::dump_args and micro_os_plus_trace_dump_args.
flush()
| inline noexcept static |
Flush the trace output channel.
- Parameters
None.
- Returns
Nothing.
Delegates unconditionally to T::flush().
For buffered output channels, the policy method must drain any internally buffered data to the output device. For unbuffered or character-mode channels (e.g. ITM), the policy method body can be left empty. Unconditionally noexcept, since the trace_policy concept already requires T::flush() to be noexcept.
Definition at line 477 of file cpp-api.h.
Referenced by micro_os_plus::trace::flush and micro_os_plus_trace_flush.
initialise()
| inline noexcept static |
Initialise the trace output channel.
- Parameters
None.
- Returns
Nothing.
Delegates unconditionally to T::initialise().
Called during startup, as early as possible, to enable the trace channel. Unconditionally noexcept, since the trace_policy concept already requires T::initialise() to be noexcept.
Definition at line 432 of file cpp-api.h.
Referenced by micro_os_plus::trace::initialise and micro_os_plus_trace_initialise.
printf()
| noexcept static |
Write a formatted string to the trace output channel.
- Parameters
-
format A null terminated string with the format.
... Additional arguments matching the format specifiers.
- Returns
The number of bytes written, or -1 if an error occurred.
Formatting is performed into a fixed-size stack buffer of MICRO_OS_PLUS_DIAG_TRACE_PRINTF_BUFFER_ARRAY_SIZE_INTEGER bytes (default: 200). Output that exceeds this limit is silently truncated before being passed to write(). The return value reflects the bytes actually written, not the number that the format string would have produced; it cannot be used to detect whether truncation occurred.
Declaration at line 500 of file cpp-api.h, definition at line 76 of file cpp-api-inlines.h.
Reference micro_os_plus::trace::vprintf.
putchar()
| noexcept static |
Write the single character to the trace output channel.
- Parameters
-
c A single byte character, passed as an int.
- Returns
The written character as an int, or EOF (-1) if an error occurred.
Converts c to unsigned char and passes it as a one-byte buffer to write(). On success, returns the original value of c; on failure, returns EOF.
Declaration at line 553 of file cpp-api.h, definition at line 186 of file cpp-api-inlines.h.
Reference micro_os_plus::trace::write.
Referenced by micro_os_plus_trace_putchar and micro_os_plus::trace::putchar.
puts()
| noexcept static |
Write the string and a line terminator to the trace output channel.
- Parameters
-
s A null terminated string (default: empty string).
- Returns
The total number of bytes written (string + newline), or EOF (-1) if an error occurred.
Writes the characters of s followed by a single newline character ('\n'). Unlike the standard C puts(), this function returns the total byte count written. If writing the newline fails after the string has been written successfully, EOF is returned.
Declaration at line 539 of file cpp-api.h, definition at line 141 of file cpp-api-inlines.h.
Reference micro_os_plus::trace::write.
Referenced by micro_os_plus_trace_puts and micro_os_plus::trace::puts.
vprintf()
| noexcept static |
Write a formatted variable arguments list to the trace output channel.
- Parameters
-
format A null terminated string with the format.
arguments A variable arguments list.
- Returns
The number of bytes written to the output channel, or -1 if an error occurred.
Equivalent to printf(), but accepts a std::va_list instead of a variadic argument list. Subject to the same fixed-size stack buffer constraint. When the formatted output exceeds the buffer size, the text is truncated silently; the return value then reflects the bytes actually written to the channel, not the total length that vsnprintf would have produced, and cannot be used to detect whether truncation occurred. Typically called by printf().
Declaration at line 522 of file cpp-api.h, definition at line 89 of file cpp-api-inlines.h.
References MICRO_OS_PLUS_DIAG_TRACE_PRINTF_BUFFER_ARRAY_SIZE_INTEGER and micro_os_plus::trace::write.
Referenced by micro_os_plus_trace_printf, micro_os_plus_trace_vprintf, micro_os_plus::trace::printf and micro_os_plus::trace::vprintf.
write()
| inline noexcept static |
Write the given number of bytes to the trace output channel.
- Parameters
-
buf An array of bytes.
nbyte The number of bytes in the array.
- Returns
The number of bytes actually written, or -1 if error.
Delegates unconditionally to T::write().
The return value must reflect the number of bytes actually transferred; a return value of -1 signals an error. Unconditionally noexcept, since the trace_policy concept already requires T::write() to be noexcept.
Definition at line 453 of file cpp-api.h.
Referenced by micro_os_plus_trace_write and micro_os_plus::trace::write.
The documentation for this class was generated from the following files:
Generated via doxygen2docusaurus 2.2.2 by Doxygen 1.17.0.