Sound Byte Libs 0.5.1-340-gab5b79a
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
scheduler_report.hpp
Go to the documentation of this file.
1/**
2 * @file scheduler_report.hpp
3 * @brief A Scheduler slot's timing as a tagged line
4 *
5 * One `#SYS.SCHED` tagged-output line with the slot's
6 * counts since the scheduler started: runs that began late, periods skipped,
7 * and the worst delay in microseconds.
8 *
9 * @code
10 * sbl::control::write_scheduler_report<SBL_LOG_OUTPUT>(sched, SLOT_1KHZ, Clock::TICKS_PER_SECOND);
11 * // #SYS.SCHED late=0 skipped=0 delay_us=12
12 * @endcode
13 */
14
15#ifndef SBL_CONTROL_SCHEDULER_REPORT_HPP_
16#define SBL_CONTROL_SCHEDULER_REPORT_HPP_
17
18#include <cstdint>
19
21
22namespace sbl::control {
23
24/** A count of ticks in microseconds, at a tick rate in ticks per second. */
25inline constexpr uint32_t ticks_to_us(uint64_t ticks, uint32_t ticks_per_second) {
26 constexpr uint64_t US_PER_SECOND = 1000000;
27 return ticks_per_second ? static_cast<uint32_t>(ticks * US_PER_SECOND / ticks_per_second) : 0;
28}
29
30/**
31 * Write a slot's late runs, skipped periods and worst delay as a `#SYS.SCHED` line.
32 * @param ticks_per_second the rate of the clock the scheduler runs on
33 */
34template<typename Output, typename Sched>
35void write_scheduler_report(const Sched& scheduler, uint8_t slot, uint32_t ticks_per_second) {
36 sbl::log::TaggedLine<> line{"SYS.SCHED"};
37 line.field("late", scheduler.late_runs(slot))
38 .field("skipped", scheduler.skipped_periods(slot))
39 .field("delay_us", ticks_to_us(scheduler.worst_delay_ticks(slot), ticks_per_second));
40 line.template write<Output>();
41}
42
43} // namespace sbl::control
44
45#endif // SBL_CONTROL_SCHEDULER_REPORT_HPP_
One #TAG key=value ... line in a fixed buffer.
Definition tagged.hpp:59
TaggedLine & field(const char *key, float value, uint8_t decimals=3)
A float field, rounded to decimals places.
Definition tagged.hpp:82
The control stack: scheduler, event queue, merge, CC mapping, calibration.
void write_scheduler_report(const Sched &scheduler, uint8_t slot, uint32_t ticks_per_second)
constexpr uint32_t ticks_to_us(uint64_t ticks, uint32_t ticks_per_second)
Tagged output lines: a builder and a throttled value report.