|
Sound Byte Libs 0.5.1-340-gab5b79a
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
|
Cycle budget of the audio callback: load, peak, minimum, overruns and a load histogram. More...
Cycle budget of the audio callback: load, peak, minimum, overruns and a load histogram.
Measures per-block cycle consumption in audio callbacks using the platform timing backend. Tracks average (EWMA), peak, min, overrun count, and a per-block load histogram (11 buckets, 10% each).
A budget registered with register_as() is an entry of the profiling registry (registry.hpp): the reporter and a reader over SWD find it there, and the end of each of its blocks is where the registry closes a window a reader asked for. The histogram stays in the budget.
Gated behind SBL_PROFILING_ENABLED. When the define is absent, all methods compile to no-ops and the class has no data members. An app's build defines it with the CMake option SBL_PROFILING (tools/cmake/SblHooks.cmake).
The cycle counter has to be started before the budget measures anything: sbl::system::profiling::init() (cycles.hpp), once at startup after clock configuration. The budget does not start it. With the counter stopped, every block reads zero cycles.
Usage:
Definition at line 66 of file audio_budget.hpp.
#include <audio_budget.hpp>
Public Member Functions | |
| void | init (uint32_t sample_rate, uint16_t block_size) |
| bool | register_as (const char *name) |
| void | on_block_start () |
| void | on_block_end () |
| float | avg_load () const |
| float | peak_load () const |
| float | min_load () const |
| uint32_t | avg_cycles () const |
| uint32_t | peak_cycles () const |
| uint32_t | min_cycles () const |
| uint32_t | budget_cycles () const |
| uint32_t | overruns () const |
| uint32_t | count () const |
| uint32_t | hist_bucket (size_t i) const |
| void | reset_window () |
| void | reset () |
Static Public Member Functions | |
| static constexpr size_t | hist_size () |
|
inline |
Configure budget from audio parameters. budget_cycles = (cycle_rate() / sample_rate) * block_size
Definition at line 74 of file audio_budget.hpp.
References sbl::system::profiling::cycle_rate(), and reset().
|
inline |
Enter the registry under name, with the statistics so far. False if already registered or the table is full. Startup only.
Definition at line 88 of file audio_budget.hpp.
|
inline |
Mark the start of audio processing (call first in callback)
Definition at line 98 of file audio_budget.hpp.
References sbl::system::profiling::cycles().
|
inline |
Mark the end of audio processing (call last in callback)
Definition at line 105 of file audio_budget.hpp.
References sbl::system::profiling::cycles(), sbl::system::profiling::Entry::limit, sbl::system::profiling::Entry::measure(), and sbl::system::profiling::Entry::overruns.
|
inline |
Average load as fraction [0.0, 1.0+]
Definition at line 131 of file audio_budget.hpp.
|
inline |
Peak (worst-case) load since the last reset() or reset_window()
Definition at line 140 of file audio_budget.hpp.
|
inline |
Minimum load since the last reset() or reset_window(); 1 before the first block
Definition at line 149 of file audio_budget.hpp.
|
inline |
Raw cycle counts
Definition at line 158 of file audio_budget.hpp.
|
inline |
Definition at line 166 of file audio_budget.hpp.
|
inline |
Definition at line 174 of file audio_budget.hpp.
|
inline |
Definition at line 182 of file audio_budget.hpp.
|
inline |
Number of callbacks that exceeded the cycle budget since the last reset() or reset_window()
Definition at line 191 of file audio_budget.hpp.
|
inline |
Total callbacks measured
Definition at line 200 of file audio_budget.hpp.
|
inlinestaticconstexpr |
Number of histogram buckets
Definition at line 211 of file audio_budget.hpp.
Referenced by sbl::system::profiling::format_tagged_histogram().
|
inline |
Read histogram bucket count (0-indexed, last bucket is >100%)
Definition at line 214 of file audio_budget.hpp.
Referenced by sbl::system::profiling::format_tagged_histogram().
|
inline |
Start a new reporting window: the peak, the minimum and the overrun count start over. The average, the block count and the histogram carry on. For a budget that is not registered; the registry does it for one that is, at the end of a block (registry.hpp).
Definition at line 229 of file audio_budget.hpp.
|
inline |
Reset statistics (budget preserved)
Definition at line 236 of file audio_budget.hpp.
Referenced by init().