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
sbl::system::profiling::AudioBudget Class Reference

Cycle budget of the audio callback: load, peak, minimum, overruns and a load histogram. More...

Detailed Description

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:

// At startup, after clock configuration:
sbl::system::profiling::init(); // start the cycle counter
budget.init(48000, 48);
budget.register_as("audio"); // into the registry, for the reporter
void audio_callback(int32_t* tx, const int32_t* rx, uint16_t frames) {
budget.on_block_start();
// ... DSP ...
budget.on_block_end();
}
// In control loop:
budget.avg_load() // [0.0, 1.0+]
budget.peak_load() // worst-case since the last reset() or reset_window()
budget.overruns() // count of callbacks that exceeded budget
budget.reset_window() // not registered: peak, min and overruns start over
Audio callback cycle budget tracker.
Cycle budget of the audio callback: load, peak, minimum, overruns and a load histogram.
void init(uint32_t sample_rate, uint16_t block_size)
bool register_as(const char *name)
The cycle counter behind the profiling tools.

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 ()
 

Member Function Documentation

◆ init()

void sbl::system::profiling::AudioBudget::init ( uint32_t  sample_rate,
uint16_t  block_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().

◆ register_as()

bool sbl::system::profiling::AudioBudget::register_as ( const char *  name)
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.

◆ on_block_start()

void sbl::system::profiling::AudioBudget::on_block_start ( )
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().

◆ on_block_end()

void sbl::system::profiling::AudioBudget::on_block_end ( )
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.

◆ avg_load()

float sbl::system::profiling::AudioBudget::avg_load ( ) const
inline

Average load as fraction [0.0, 1.0+]

Definition at line 131 of file audio_budget.hpp.

◆ peak_load()

float sbl::system::profiling::AudioBudget::peak_load ( ) const
inline

Peak (worst-case) load since the last reset() or reset_window()

Definition at line 140 of file audio_budget.hpp.

◆ min_load()

float sbl::system::profiling::AudioBudget::min_load ( ) const
inline

Minimum load since the last reset() or reset_window(); 1 before the first block

Definition at line 149 of file audio_budget.hpp.

◆ avg_cycles()

uint32_t sbl::system::profiling::AudioBudget::avg_cycles ( ) const
inline

Raw cycle counts

Definition at line 158 of file audio_budget.hpp.

◆ peak_cycles()

uint32_t sbl::system::profiling::AudioBudget::peak_cycles ( ) const
inline

Definition at line 166 of file audio_budget.hpp.

◆ min_cycles()

uint32_t sbl::system::profiling::AudioBudget::min_cycles ( ) const
inline

Definition at line 174 of file audio_budget.hpp.

◆ budget_cycles()

uint32_t sbl::system::profiling::AudioBudget::budget_cycles ( ) const
inline

Definition at line 182 of file audio_budget.hpp.

◆ overruns()

uint32_t sbl::system::profiling::AudioBudget::overruns ( ) const
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.

◆ count()

uint32_t sbl::system::profiling::AudioBudget::count ( ) const
inline

Total callbacks measured

Definition at line 200 of file audio_budget.hpp.

◆ hist_size()

static constexpr size_t sbl::system::profiling::AudioBudget::hist_size ( )
inlinestaticconstexpr

Number of histogram buckets

Definition at line 211 of file audio_budget.hpp.

Referenced by sbl::system::profiling::format_tagged_histogram().

◆ hist_bucket()

uint32_t sbl::system::profiling::AudioBudget::hist_bucket ( size_t  i) const
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().

◆ reset_window()

void sbl::system::profiling::AudioBudget::reset_window ( )
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.

◆ reset()

void sbl::system::profiling::AudioBudget::reset ( )
inline

Reset statistics (budget preserved)

Definition at line 236 of file audio_budget.hpp.

Referenced by init().


The documentation for this class was generated from the following file: