LCG Project | LCG Applications Area | |
$Date: 2004/10/18 16:25:06 $ |
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.
The following classes are provided for measuring the time :
These Chrono classes are used together with the class SealTimer to measure the time spend in a block of code.
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");
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.