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
Last revisionBoth sides next revision
for_developers:timing_measurement [2016/08/15 16:43] – [Accuracy of the measurement] gehrigfor_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 time each start of a cycle (//counter.tick()//). Additionally it measures the run time of all threads with //counter.tock()//. The timer keeps track of previous measurements and calculates after each //counter.tock// minimal value, maximal value, mean value and the variance of the period time and run time as well.+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. 
 + 
 +Implementation in //Executor.cpp//: 
 +<code cpp> 
 +... 
 +loop { 
 +    counter.tick(); 
 +    //code under test (list.run();) 
 +    counter.tock(); 
 +
 +... 
 +</code>
  
 ===== Influence of the measurement on the real time performance of the system ===== ===== Influence of the measurement on the real time performance of the system =====
Line 14: Line 29:
  
 ===== Implementation ===== ===== 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:+To integrate the measurement, following code has to be integrated after a task is created and before the task is added to the //Executor//The following example shows the integration of the measurement including creation and assignment to the executor of a control system:
 <code cpp> <code cpp>
 using namespace eeros::logger; using namespace eeros::logger;
Line 20: Line 35:
  
  
-eeros::task::Periodic td("control system",dt, timedomain);+eeros::task::Periodic per("control system",dt, timedomain);
  
-td.monitors.push_back([&](eeros::PeriodicCounter &c, Logger<LogWriter> &log) {+per.monitors.push_back([&](PeriodicCounter &c, Logger<LogWriter> &log) {
  static int ticks = 0; // mseconds   static int ticks = 0; // mseconds
   
Line 29: Line 44:
   
  // timing measurement (tictoc)  // timing measurement (tictoc)
- eeros::PeriodicCounter counter = c;+ PeriodicCounter counter = c;
  c.reset();  c.reset();
  std::cout << "CS: period max: " << setw(7)  << counter.period.max*1000  std::cout << "CS: period max: " << setw(7)  << counter.period.max*1000
Line 36: Line 51:
 }); });
  
-eeros::Executor::instance().add(td);+eeros::Executor::instance().add(per);
 </code> </code>
  
- +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 in line 3.+<code cpp> 
 +eeros::control::TimeDomain td1("td1",0.01, true);  // periodic counter not accessible 
 +eeros::Executor::instance().add(td1); 
 +eeros::control::TimeDomain td2("td1",0.01, true);   
 +eeros::task::Periodic per2("per2",0.01, td2);  // now you can add monitor functions to its counter 
 +eeros::Executor::instance().add(per2); 
 +</code>
  
 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: