AceRoutine  1.5.0
A low-memory, fast-switching, cooperative multitasking library using stackless coroutines on Arduino platforms.
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
ace_routine::LogBinProfilerTemplate< T_COROUTINE > Class Template Reference

Class that maintains the frequency count of the elapsed time of runCoroutine() in an array of bins where each bin is a log2() logarithm of the elapsed time in microseconds. More...

#include <LogBinProfiler.h>

Inheritance diagram for ace_routine::LogBinProfilerTemplate< T_COROUTINE >:
Inheritance graph
[legend]
Collaboration diagram for ace_routine::LogBinProfilerTemplate< T_COROUTINE >:
Collaboration graph
[legend]

Public Member Functions

 LogBinProfilerTemplate ()
 Constructor.
 
void clear ()
 Clear the bins.
 
void updateElapsedMicros (uint32_t micros) override
 Update the count for the calculated elapsed time bin. More...
 
- Public Member Functions inherited from ace_routine::CoroutineProfiler
 CoroutineProfiler ()=default
 Use default constructor.
 
virtual ~CoroutineProfiler ()=default
 The destructor is NON-virtual on AVR processors because adding a virtual destructor causes flash consumption to increase by 600 bytes, even if the profiler is never used. More...
 

Static Public Member Functions

static void createProfilers ()
 Create a new profiler on the heap and attach it to each coroutine. More...
 
static void deleteProfilers ()
 Delete the profilers created by createProfilers().
 
static void clearProfilers ()
 Clear counters for all profilers.
 

Public Attributes

uint16_t mBins [kNumBins]
 Event count bins.
 

Static Public Attributes

static const uint8_t kNumBins = 32
 Number of event counter bins used by this class.
 

Detailed Description

template<typename T_COROUTINE>
class ace_routine::LogBinProfilerTemplate< T_COROUTINE >

Class that maintains the frequency count of the elapsed time of runCoroutine() in an array of bins where each bin is a log2() logarithm of the elapsed time in microseconds.

An instance of this class can be attached to a given coroutine through the Coroutine::setProfiler() method.

After sufficient number of samples are collected, the frequency distribution of all profilers for all coroutines can be printed by a renderer. Two renderer are provided:

Template Parameters
T_COROUTINEclass of the specific CoroutineTemplate instantiation, usually Coroutine

Definition at line 54 of file LogBinProfiler.h.

Member Function Documentation

◆ createProfilers()

template<typename T_COROUTINE >
static void ace_routine::LogBinProfilerTemplate< T_COROUTINE >::createProfilers ( )
inlinestatic

Create a new profiler on the heap and attach it to each coroutine.

If the coroutine has an existing profiler attached to it, the previous profiler is simply replaced, but not deleted. The reason is that the previous profiler could have been created statically, instead of on the heap, and we would crash the program if we tried to call delete on that pointer.

If createProfilers() is called twice within the same application, (which should rarely happen), the program must ensure that deleteProfilers() is called before the second call to createProfilers(). Otherwise, heap memory will be leaked.

Definition at line 106 of file LogBinProfiler.h.

◆ updateElapsedMicros()

template<typename T_COROUTINE >
void ace_routine::LogBinProfilerTemplate< T_COROUTINE >::updateElapsedMicros ( uint32_t  micros)
inlineoverridevirtual

Update the count for the calculated elapsed time bin.

The bin index is the bit number (0-31) of the most significant bit. So each bin contains the number of samples whose elapsed micros is between 2^i and 2^(i+1). Example, for Bin 3, and this bin contains the number of samples which satsify (8us <= elapsed < 16us). The exception is Bin 0 because it includes samples where elapsed is 0 as well, so the sample interval for Bin 0 is (0 <= elapsed < 2), instead of (1 <= elapsed < 2).

Implements ace_routine::CoroutineProfiler.

Definition at line 79 of file LogBinProfiler.h.


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