Sound Byte Libs
0.5.1-121-g3358a44
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
section.hpp
Go to the documentation of this file.
1
/**
2
* @file section.hpp
3
* @brief Per-section tick profiling with EWMA smoothing
4
*
5
* Measures ticks consumed by named code sections in audio callbacks.
6
* Uses integer EWMA (alpha = 1/128, shift-based) for low-overhead smoothing.
7
*
8
* Gated behind SBL_PROFILING_ENABLED. When disabled, SectionProfile::avg
9
* is a static constexpr zero so format strings compile without #ifdef.
10
*
11
* Usage:
12
* static sbl::diagnostics::SectionProfile s_prof_osc;
13
* static sbl::diagnostics::SectionProfile s_prof_svf;
14
*
15
* void audio_callback(...) {
16
* SBL_PROF_MARK(t);
17
* // ... oscillator rendering ...
18
* SBL_PROF_SECTION(s_prof_osc, t);
19
* // ... filter processing ...
20
* SBL_PROF_SECTION(s_prof_svf, t);
21
* }
22
*/
23
#ifndef SBL_COMMON_DIAGNOSTICS_SECTION_HPP_
24
#define SBL_COMMON_DIAGNOSTICS_SECTION_HPP_
25
26
#include <cstdint>
27
28
#ifdef SBL_PROFILING_ENABLED
29
#include <
sbl/common/diagnostics/ticks.hpp
>
30
#endif
31
32
namespace
sbl::diagnostics
{
33
34
#ifdef SBL_PROFILING_ENABLED
35
36
struct
SectionProfile {
37
uint32_t
avg
= 0;
// EWMA accumulator (alpha = 1/128)
38
39
void
update
(uint32_t cyc) {
40
avg
=
avg
- (
avg
>> 7) + (cyc >> 7);
41
}
42
};
43
44
#else
45
46
struct
SectionProfile
{
47
static
constexpr
uint32_t
avg
= 0;
48
49
void
update
(uint32_t) {}
50
};
51
52
#endif
53
54
}
// namespace sbl::diagnostics
55
56
/// Mark a timestamp variable for section profiling
57
#ifdef SBL_PROFILING_ENABLED
58
#define SBL_PROF_MARK(var) uint32_t var = sbl::diagnostics::ticks()
59
#else
60
#define SBL_PROF_MARK(var) (void)0
61
#endif
62
63
/// Measure ticks since 'start', update section profile, advance start
64
#ifdef SBL_PROFILING_ENABLED
65
#define SBL_PROF_SECTION(section, start) do { \
66
uint32_t _end = sbl::diagnostics::ticks(); \
67
section.update(_end - start); \
68
start = _end; \
69
} while(0)
70
#else
71
#define SBL_PROF_SECTION(section, start) (void)0
72
#endif
73
74
#endif
// SBL_COMMON_DIAGNOSTICS_SECTION_HPP_
sbl::diagnostics
Diagnostics and profiling.
Definition
audio_budget.hpp:39
sbl::diagnostics::SectionProfile
Definition
section.hpp:46
sbl::diagnostics::SectionProfile::avg
static constexpr uint32_t avg
Definition
section.hpp:47
sbl::diagnostics::SectionProfile::update
void update(uint32_t)
Definition
section.hpp:49
ticks.hpp
Tick counter interface for profiling.
src
sbl
common
diagnostics
section.hpp
Generated by
1.9.8