SEAL Timers

LCG Project | LCG Applications Area

SEAL Project | Project Portal

 

$Date: 2004/10/18 16:25:06 $

Functionality

Seal provides various timers for measuring the amount of time spent in a block of code. They can measure not only the real time (wall clock time) but also the CPU time spent in that particular process, differentiating between user and system, and idle time. They are based on various method to extract the time information and they differentiate for the precision and the latency time.

In addition helper classes are provided for performing repetitive measurements and getting averages of the time spent in the same block of code.

Timer Classes

The following classes are provided for measuring the time :

  1. SealChrono Measures Real time, CPU user and system time and idle time. It is uses the functionality provided by the SealBase class TimeInfo. It uses TimeInfo::processTimes( ) to get the CPU and real time for the process. On Linux machines the resolution is of the order of milliseconds. See the TimeInfo documentation for more details.
  2. SimpleChrono Measure Wall clock time using the time provided by the Time class from SealBase. Time measures the time elapsed since 00:00:00 on January 1, 1970 in nanoseconds. Resolution, however on Linux machine is typically not better than milliseconds.
  3. SealHRChrono High resolution timer measuring real time and process virtual time. It uses TimeInfo::realNsecs() and TimeInfo::virtualNsecs() to get the time with the highest resolution available on the system.
  4. SealHRRTChrono High resolution timer measuring only real time. It uses TimeInfo::realNsecs(). On Linux machines, it is based on clock ticks measurements, and it has a very low overhead of around 100 clock ticks (75 ns on a 1.5 GHZ machine).
  5. SealTickChrono High resolution timer similar to SealHRRTChrono, but measuring clock ticks. It uses TimeInfo::realCycles(). The overhead on Linux machine is of the order of 100 clock cycles.

These Chrono classes are used together with the class SealTimer to measure the time spend in a block of code.

Examples of Usage

How to measure time

To measure the time in your code you have to instrument your code as following. You create an instance of SealTimer and automatically on destruction SealTimer will report the elapsed time since its existence. SealTimer uses by default the SealChrono class, but can be created passing as argument any other of the Chrono classes.

// measure time spent in function f using default Chrono SealChrono 
void f() { 
  seal::SealTimer("Function f"); 
  doSomething(); 
  return; 
}

when executed, it will print the following message when the instance of SealTimer is destructed:

Timing in Function f : Real Time = 1.19 (s), User Time = 0.68 (s), System Time = 0 (s), Cpu Time = 0.68 (s), 
Idle Time = 0.51 (s)

To use another Chrono class, one need to create SealTimer passing as argument the Chrono class:

seal::SealHRChrono hr_chrono;
seal::SealTimer(hr_chrono, "Function f");

Using Time report

An additional functionality provided is in collecting statistics on the time measurements and reporting the results. Two additional classes exist: TimeItem and TimeReport. TimeItem identifies with the item of code we want to measure and collects the statistics of all the measurements while TimeReport reports the result. TimeItem has as template parameter the Chrono class. By default it uses SealChrono.

Here is an example of usage:

seal::TimingReport tr;
seal::TimingItem & timing1 = tr.item("doSomething1"); 
seal::TimingItem & timing2 = tr.item<seal::SealHRChrono>("soSomething2"); 

// later in the code ...... and in a  loop 
for (int i = 0; i < 10; ++i) 
{ 
  { 
    seal::SealTimer(timing1); 
    doSomething1(); 
  }

  { 
    seal::SealTimer(timing2); 
    doSomething2(); 
  }
}

// at the end dump the result 
tr.dump(); 

At the end call tr.dump() to print the timing statistics. The print of this example will be :

>>>>>>    Timing Results  <<<<<<<<<<
----- doSomething1 :        (  n = 10  )
Real Time :  mean = 0.091 (s),  RMS = 0.003 (s)
User Time :  mean = 0.092 (s),  RMS = 0.004 (s)
System Time :  mean = 0 (s),  RMS = 0 (s)
Cpu Time :  mean = 0.092 (s),  RMS = 0.004 (s)
Idle Time :  mean = -0.001 (s),  RMS = 0.00538516 (s)

----- doSomething2 :        (  n = 10  )
Real Time :  mean = 0.0808664 (s),  RMS = 0.00133085 (s)
Process Time :  mean = 0.081 (s),  RMS = 0.003 (s)

TimingItem contains in addition method to retrieve each time measurements, for example to fill an histogram. More examples on the usage of timers can be found looking at the tests present in the repository.


Contact: Lorenzo Moneta