GCC Code Coverage Report


Directory: ./
File: src/PTimer.cpp
Date: 2024-09-19 16:05:14
Exec Total Coverage
Lines: 36 36 100.0%
Branches: 5 5 100.0%

Line Branch Exec Source
1 /***************************************
2 Auteur : Pierre Aubert
3 Mail : pierre.aubert@lapp.in2p3.fr
4 Licence : CeCILL-C
5 ****************************************/
6
7 #include "PTimer.h"
8
9 ///Default constructor of PTimer
10 /** @param ellapsedTime : ellapsed time between two calls (in nanoseconds)
11 */
12 3 PTimer::PTimer(size_t ellapsedTime)
13 3 :p_ellapsedTime(ellapsedTime)
14 {
15 3 initialisationPTimer();
16 3 }
17
18 ///Copy constructor of PTimer
19 /** @param other : class to copy
20 */
21 1 PTimer::PTimer(const PTimer & other){
22 1 copyPTimer(other);
23 1 }
24
25 ///Destructor of PTimer
26 8 PTimer::~PTimer(){
27
28 }
29
30 ///Definition of equal operator of PTimer
31 /** @param other : class to copy
32 * @return copied class
33 */
34 1 PTimer & PTimer::operator = (const PTimer & other){
35 1 copyPTimer(other);
36 1 return *this;
37 }
38
39 ///Start the current clock
40 13 void PTimer::start(){
41 13 p_startTime = std::chrono::steady_clock::now();
42 13 }
43
44 ///Set the ellapsed time in nanoseconds
45 /** @param ellapsedTime : ellapsed time in nanoseconds
46 */
47 1 void PTimer::setEllapsedTime(size_t ellapsedTime){
48 1 p_ellapsedTime = ellapsedTime;
49 1 }
50
51 ///Get the ellapsed time in nanoseconds
52 /** @return ellapsed time in nanoseconds
53 */
54 4 size_t PTimer::getEllapsedTime() const{
55 4 return p_ellapsedTime;
56 }
57
58 ///Returns true if the given ellapsed time between to call is passed
59 /** @return true if the given ellapsed time between to call is passed, false otherwise
60 */
61 9546259 bool PTimer::isTime(){
62 9546259 size_t ellapsedTimeNs(0lu);
63
1/1
✓ Branch 1 taken 9546259 times.
19092518 return isTime(ellapsedTimeNs);
64 }
65
66 ///Returns true if the given ellapsed time between to call is passed
67 /** @param[out] ellapsedTimeNs : real ellapsed time in nanoseconds between the call of isTime and the last start of the PTimer (maybe in another isTime)
68 * @return true if the given ellapsed time between to call is passed, false otherwise
69 */
70 19092517 bool PTimer::isTime(size_t & ellapsedTimeNs){
71
1/1
✓ Branch 2 taken 19092517 times.
19092517 std::chrono::nanoseconds ellapsedTime(std::chrono::steady_clock::now() - p_startTime);
72 19092517 ellapsedTimeNs = ellapsedTime.count();
73 19092517 bool b(ellapsedTimeNs >= p_ellapsedTime);
74
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 19092507 times.
19092517 if(b){
75
1/1
✓ Branch 1 taken 10 times.
10 start();
76 }
77 19092517 return b;
78 }
79
80 ///Copy function of PTimer
81 /** @param other : class to copy
82 */
83 2 void PTimer::copyPTimer(const PTimer & other){
84 2 p_ellapsedTime = other.p_ellapsedTime;
85 2 p_startTime = other.p_startTime;
86 2 }
87
88 ///Initialisation function of the class PTimer
89 3 void PTimer::initialisationPTimer(){
90 3 start();
91 3 }
92
93
94
95
96
97