for_developers:timing_measurement
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revisionLast revisionBoth sides next revision | ||
for_developers:timing_measurement [2016/06/02 10:40] – created gehrig | for_developers:timing_measurement [2016/11/29 09:47] – [How the timer works] graf | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Using built in timer for measuring real time performance | + | ====== Using Periodic Counter to measure Realtime Performance |
===== How the timer works ===== | ===== How the timer works ===== | ||
- | The timer function is included in the Executer object. It measures | + | The timer function is included in the Executer object. It registers |
+ | * run time: counter.tock() - counter.tick() | ||
+ | * period: counter.tick()[t=n] - counter.tick()[t=n-1] | ||
+ | * jitter: |actual period - set period| | ||
+ | Of these three measurements the minimal value, maximal value, mean value and the variance | ||
+ | Implementation in // | ||
+ | <code cpp> | ||
+ | ... | ||
+ | loop { | ||
+ | counter.tick(); | ||
+ | //code under test (list.run(); | ||
+ | counter.tock(); | ||
+ | } | ||
+ | ... | ||
+ | </ | ||
+ | |||
+ | ===== Influence of the measurement on the real time performance of the system ===== | ||
+ | Don't use // | ||
+ | Don't use multiple lines (// | ||
+ | |||
+ | ===== Accuracy of the measurement ===== | ||
+ | This measurement provides only statistical data over 1000 (or 100) cycles at a time and not for each iteration. To measure jitter for each iteration use the [[: | ||
+ | |||
+ | It is possible to measure a 15% CPU load and over 300us run time per 1ms period. This indicates, that the run time measurement is not accurate. | ||
===== Implementation ===== | ===== Implementation ===== | ||
- | To integrate the measurement, | + | To integrate the measurement, |
- | < | + | < |
- | td.monitors.push_back([](eeros::PeriodicCounter &c, Logger< | + | using namespace eeros:: |
- | static int ticks = 0; | + | |
- | if (++ticks < 1000) return; | + | |
+ | |||
+ | eeros:: | ||
+ | |||
+ | per.monitors.push_back([&](PeriodicCounter &c, Logger< | ||
+ | static int ticks = 0; // mseconds | ||
+ | |||
+ | if (++ticks < 1000) return; | ||
ticks = 0; | ticks = 0; | ||
- | eeros::PeriodicCounter counter = c; | + | |
+ | // timing measurement (tictoc) | ||
+ | PeriodicCounter counter = c; | ||
c.reset(); | c.reset(); | ||
- | log.trace() | + | std::cout << "CS: period max: " << |
- | << | + | << " |
- | << | + | << |
}); | }); | ||
+ | |||
+ | eeros:: | ||
</ | </ | ||
- | + | If the executor has a small cycle time (less than 1 second) it is not advisable to update the log output each time. In the example the output is only updated after 1000 cycles. Depending on the cycle time, this number can be adjusted.\\ | |
- | ==== Explanation of the implementation ==== | + | Every periodic includes a periodic counter object. In case you simply define a time domain and add it to the executor its corresponding periodic object is created internally and you cannot access its periodic counter object. In such cases you manually create a periodic object and pass its time domain as a parameter. |
- | If the executor has a small cycle time (less than 1 second) it is not advisable to update the log output each time. In the implementation of the code example the output is only updated after 1000 cycles. Depending on the cycle time, this number can be adjusted | + | <code cpp> |
+ | eeros:: | ||
+ | eeros:: | ||
+ | eeros:: | ||
+ | eeros:: | ||
+ | eeros:: | ||
+ | </ | ||
Line 7 defines which date should be written to the terminal output. Following options are available for //run// time and //period// time: | Line 7 defines which date should be written to the terminal output. Following options are available for //run// time and //period// time: |