User Tools

Site Tools


for_developers:timing_measurement

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
for_developers:timing_measurement [2016/08/17 11:10] – [How the timer works] gehrigfor_developers:timing_measurement [2018/04/18 22:05] (current) – removed graf
Line 1: Line 1:
-====== Using built in timer for measuring real time performance ====== 
- 
-===== How the timer works ===== 
-The timer function is included in the Executer object. It registers the system time each time the executor executes its list of tasks (//counter.tick()//). When all tasks are done the system time is registered again (//counter.tock()//). The timer keeps track of the previous measurement and calculates the run time in between consecutive runs as well as period and jitter.  
-  * 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 are calculated. 
- 
-===== Influence of the measurement on the real time performance of the system ===== 
-Don't use //log.trace()// for data output during a real time critical process. This command introduces unwanted jitter. Use //std::cout// instead, which effects the jitter of the real time process much less. 
-Don't use multiple lines (//std:endl//). Multiple line outputs introduces a significant jitter with a periodicity of 1 second. 
- 
-===== 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 [[:for_developers:signal_probe_block|signalProbeBlock]]. 
- 
-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 ===== 
-To integrate the measurement, following code has to be integrated after a task is created and before the task is added to the //Executor//. Following example shows the integration of the measurement including creation and assignment to the executor of a control system: 
-<code cpp> 
-using namespace eeros::logger; 
- 
- 
- 
-eeros::task::Periodic td("control system",dt, timedomain); 
- 
-td.monitors.push_back([&](eeros::PeriodicCounter &c, Logger<LogWriter> &log) { 
- static int ticks = 0; // mseconds  
-  
- if (++ticks < 1000) return;  
- ticks = 0; 
-  
- // timing measurement (tictoc) 
- eeros::PeriodicCounter counter = c; 
- c.reset(); 
- std::cout << "CS: period max: " << setw(7)  << counter.period.max*1000 
- << "   run max: " << std::setw(8) << counter.run.max*1000 
- << std::endl; 
-}); 
- 
-eeros::Executor::instance().add(td); 
-</code> 
- 
- 
-==== Explanation of the implementation ==== 
-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 in line 3. 
- 
-Line 7 defines which date should be written to the terminal output. Following options are available for //run// time and //period// time: 
-  * min 
-  * max 
-  * mean 
-  * variance 
-The time is measured in nanoseconds. 
- 
- 
-===== Save terminal output on a host computer via SSH ===== 
-Because of memory restriction or because writing a file would affect the real time behavior of the system it is maybe not possible to save the output of the terminal directly on the target system. The output can be saved on a different computer with following command: 
-<code>ssh <username>@<hostname> "<path to eeros project>/eerosproject" > <path to logfile>/<name of logfile></code> 
-With this command it is possible to measure for multiple hours or even multiple days. 
- 
  
for_developers/timing_measurement.1471425006.txt.gz · Last modified: 2016/08/17 11:10 by gehrig