@@ -4,7 +4,7 @@ See the [README.md](README.md) for installation instructions and other
44background information. This document describes how to use the library once it
55is installed.
66
7- ** Version** : 1.5.0 (2022-03-19 )
7+ ** Version** : 1.5.1 (2022-09-20 )
88
99## Table of Contents
1010
@@ -1153,22 +1153,25 @@ about 14 bytes of flash per invocation.
11531153
11541154Version 1.5 added the ability to profile the execution time of
11551155` Coroutine::runCoroutine() ` and render the information as a formatted table, or
1156- as a JSON object. If the profiling feature is not used, no additional flash
1157- memory is consumed. The static RAM usage does increase by 2 bytes (8-bits) and 4
1158- bytes (32-bits) per coroutine.
1156+ as a JSON object. (Thanks to peufeu2@ who proposed the idea and provided the
1157+ initial proof of concept in
1158+ [ Discussion #50 ] ( https://github.com/bxparks/AceRoutine/discussions/50 ) ).
1159+
1160+ If the profiling feature is not used, no additional flash memory is consumed.
1161+ The static RAM usage does increase by 2 bytes (8-bits) and 4 bytes (32-bits) per
1162+ coroutine even if this feature is not used. The feature seemed useful enough to
1163+ accept this small increase in static memory size, because most applications will
1164+ not use more than 5-10 coroutines, and that translates into only 10-20 bytes of
1165+ additional static RAM usage on 8-bit processors.
11591166
11601167The following classes and API methods were added to support the profiling
1161- feature. The ` CoroutineProfiler ` class is an interface that allows an object to
1162- receive information about the execution time of the ` Coroutine::runCoroutine() `
1163- method:
1168+ feature. The ` CoroutineProfiler ` class is an interface whose
1169+ ` updateElapsedMicros() ` should be called with the execution time of the
1170+ ` Coroutine::runCoroutine() ` method:
11641171
11651172``` C++
11661173class CoroutineProfiler {
11671174 public:
1168- /**
1169- * Process the completion of the runCoroutine() method which took
1170- * ` micros ` microseconds.
1171- * /
11721175 virtual void updateElapsedMicros(uint32_t micros) = 0;
11731176};
11741177```
@@ -1188,14 +1191,17 @@ class Coroutine {
11881191};
11891192```
11901193
1194+ The ` runCoroutineWithProfiler() ` method calls ` runCoroutine() ` , measures the
1195+ elapsed time in microseconds, then calls the ` profiler->updateElapsedMicros() ` .
1196+
11911197** Note** : When creating Coroutines with profiling enabled, it will probably be
11921198necessary to assign human-readable names to each coroutine for identification
11931199purposes. See [ Coroutine Names] ( #CoroutineNames ) for information on the
11941200` setName() ` , ` getCName() ` , ` getFName() ` , ` getNameType() ` , and ` printNameTo() `
11951201methods. Each coroutine name will consume additional flash memory.
11961202
11971203Currently only a single implementation of ` CoroutineProfiler ` is provided, the
1198- ` LogBinProfiler ` . It contains 32 bins of ` uint16_t ` which tracks the number of
1204+ ` LogBinProfiler ` . It contains 32 bins of ` uint16_t ` which track the number of
11991205times a ` micros ` was seen. The bins are logarithmically scaled, so that Bin 0
12001206collects all events ` <2us ` , Bin 1 collects events ` <4us ` , Bin 2 collects events
12011207` <8us ` , ..., Bin 30 collects events ` <2147s ` , and the last Bin 31 collects
@@ -1242,7 +1248,7 @@ COROUTINE(coroutine1) {
12421248 ...
12431249}
12441250
1245- COROUTINE(coroutine1 ) {
1251+ COROUTINE(coroutine2 ) {
12461252 ...
12471253}
12481254
@@ -1275,10 +1281,12 @@ COROUTINE(coroutine1) {
12751281 ...
12761282}
12771283
1278- COROUTINE(coroutine1 ) {
1284+ COROUTINE(coroutine2 ) {
12791285 ...
12801286}
12811287
1288+ ...
1289+
12821290void setup() {
12831291 ...
12841292 LogBinProfiler::createProfilers();
@@ -1391,7 +1399,7 @@ class LogBinJsonRenderer{
13911399
13921400* The ` printer ` is usually the ` Serial ` object, but can be changed to something
13931401 else if needed.
1394- * The ` startBin ` ( 0-31) and ` endBin ` ( 0-32) identify the bins which should be
1402+ * The ` startBin ` [ 0-31] and ` endBin ` [ 0-32] identify the bins which should be
13951403 printed.
13961404 * A range of something like [ 2, 13) is useful to keep the width of the table
13971405 reasonable.
@@ -1423,6 +1431,9 @@ this:
14231431}
14241432```
14251433
1434+ The ` LogBinProfiler ` uses a ` uint16_t ` counter, so the maximum value is
1435+ saturated to ` 65535 ` .
1436+
14261437<a name =" ProfilerResourceConsumption " ></a >
14271438### Profiler Resource Consumption
14281439
@@ -1459,13 +1470,13 @@ If the profiling feature is enabled, the
14591470
14601471The [ AutoBenchmark] ( examples/AutoBenchmark ) program shows that calling the
14611472profiler-enabled methods, ` Coroutine::runCoroutineWithProfiler() ` and
1462- `CoroutineScheduler::loopWithProfiler(), increases latency by:
1473+ ` CoroutineScheduler::loopWithProfiler() ` , increases latency by:
14631474
1464- * 3 - 3.2 micros on AVR
1475+ * 2.2 - 3.0 micros on AVR
14651476* 0.4 micros on STM32F1
14661477* 0.2 - 0.3 micros on ESP8266
14671478* 0.1 micros on ESP32
1468- * 0.033 - 0.166 micros on Teensy 3.2
1479+ * 0.03 - 0.17 micros on Teensy 3.2
14691480
14701481On 32-bit processors, the overhead seems neglegible. On 8-bit processors, the 3
14711482microsecond of overhead might be an issue with sensitive applications.
0 commit comments