Line | Branch | Exec | Source |
---|---|---|---|
1 | /*************************************** | ||
2 | Auteur : Pierre Aubert | ||
3 | Mail : pierre.aubert@lapp.in2p3.fr | ||
4 | Licence : CeCILL-C | ||
5 | ****************************************/ | ||
6 | |||
7 | #include <math.h> | ||
8 | #include "PFunctionPerf.h" | ||
9 | |||
10 | ///Default constructor of PFunctionPerf | ||
11 | /** @param name : name of the function to profile | ||
12 | */ | ||
13 | 6 | PFunctionPerf::PFunctionPerf(const std::string & name){ | |
14 |
1/1✓ Branch 0 (9→10) taken 6 times.
|
6 | initialisationPFunctionPerf(name); |
15 | 6 | } | |
16 | |||
17 | ///Copy constructor of PFunctionPerf | ||
18 | /** @param other : class to copy | ||
19 | */ | ||
20 | 8 | PFunctionPerf::PFunctionPerf(const PFunctionPerf & other){ | |
21 |
1/1✓ Branch 0 (9→10) taken 8 times.
|
8 | copyPFunctionPerf(other); |
22 | 8 | } | |
23 | |||
24 | ///Destructor of PFunctionPerf | ||
25 | 14 | PFunctionPerf::~PFunctionPerf(){ | |
26 | |||
27 | 14 | } | |
28 | |||
29 | ///Definition of equal operator of PFunctionPerf | ||
30 | /** @param other : class to copy | ||
31 | * @return copied class | ||
32 | */ | ||
33 | 1 | PFunctionPerf & PFunctionPerf::operator = (const PFunctionPerf & other){ | |
34 | 1 | copyPFunctionPerf(other); | |
35 | 1 | return *this; | |
36 | } | ||
37 | |||
38 | ///Set the name of the function profiled by the current PFunctionPerf | ||
39 | /** @param name : name of the function to profile | ||
40 | */ | ||
41 | 2 | void PFunctionPerf::setName(const std::string & name){ | |
42 | 2 | p_name = name; | |
43 | 2 | } | |
44 | |||
45 | ///Resize the PFunctionPerf by respect to the number of thread which call the function | ||
46 | /** @param nbThread : number of threads which call the function | ||
47 | */ | ||
48 | 10 | void PFunctionPerf::resize(size_t nbThread){ | |
49 | 10 | p_timeBegin.resize(nbThread); | |
50 | 10 | p_nbCall.resize(nbThread); | |
51 | 10 | p_fullTime.resize(nbThread); | |
52 | 10 | p_fullSqrTime.resize(nbThread); | |
53 | 10 | p_minTime.resize(nbThread); | |
54 | 10 | p_maxTime.resize(nbThread); | |
55 | 10 | reset(); | |
56 | 10 | } | |
57 | |||
58 | ///Start the timing for one function | ||
59 | /** @param threadIndex : index of the current thread to be measured | ||
60 | */ | ||
61 | 3990 | void PFunctionPerf::start(size_t threadIndex){ | |
62 | 3990 | p_timeBegin[threadIndex] = phoenix_hardware_rdtsc(); | |
63 | 3992 | } | |
64 | |||
65 | ///Stop the timing of one function | ||
66 | /** @param threadIndex : index of the current thread to be measured | ||
67 | */ | ||
68 | 3979 | void PFunctionPerf::stop(size_t threadIndex){ | |
69 | 3979 | size_t elapsedTime = phoenix_hardware_rdtsc() - p_timeBegin[threadIndex]; | |
70 | 3992 | double dTime = elapsedTime; | |
71 | 3992 | p_fullTime[threadIndex] += dTime; | |
72 | 3983 | p_fullSqrTime[threadIndex] += dTime*dTime; | |
73 |
2/2✓ Branch 0 (7→8) taken 129 times.
✓ Branch 1 (7→10) taken 3859 times.
|
3982 | if(elapsedTime > p_maxTime[threadIndex]){p_maxTime[threadIndex] = elapsedTime;} |
74 |
2/2✓ Branch 0 (11→12) taken 165 times.
✓ Branch 1 (11→14) taken 3821 times.
|
3988 | if(elapsedTime < p_minTime[threadIndex]){p_minTime[threadIndex] = elapsedTime;} |
75 | 3986 | ++(p_nbCall[threadIndex]); | |
76 | 3989 | } | |
77 | |||
78 | ///Reset the profiling | ||
79 | /** @param threadIndex : index of the current thread to be measured | ||
80 | */ | ||
81 | 41 | void PFunctionPerf::reset(size_t threadIndex){ | |
82 | 41 | p_timeBegin[threadIndex] = 0lu; | |
83 | 41 | p_nbCall[threadIndex] = 0lu; | |
84 | 41 | p_fullTime[threadIndex] = 0.0; | |
85 | 41 | p_fullSqrTime[threadIndex] = 0.0; | |
86 | 41 | p_minTime[threadIndex] = -1lu; | |
87 | 41 | p_maxTime[threadIndex] = 0lu; | |
88 | 41 | } | |
89 | |||
90 | ///Reset the profiling | ||
91 | 12 | void PFunctionPerf::reset(){ | |
92 |
2/2✓ Branch 0 (6→3) taken 21 times.
✓ Branch 1 (6→7) taken 12 times.
|
33 | for(size_t i(0lu); i < p_timeBegin.size(); ++i){ |
93 | 21 | reset(i); | |
94 | } | ||
95 | 12 | } | |
96 | |||
97 | ///Sum the given vector | ||
98 | /** @param vec : vector of value | ||
99 | * @return sum of vector value | ||
100 | */ | ||
101 | template<typename T> | ||
102 | 115 | T reduceVectorVale(const std::vector<T> & vec){ | |
103 | 115 | T sum(0); | |
104 |
2/2✓ Branch 0 (15→3) taken 151 times.
✓ Branch 1 (15→16) taken 115 times.
|
532 | for(typename std::vector<T>::const_iterator it(vec.begin()); it != vec.end(); ++it){ |
105 | 151 | sum += *it; | |
106 | } | ||
107 | 115 | return sum; | |
108 | } | ||
109 | |||
110 | ///Get the performances of the current function | ||
111 | /** @param[out] nbCall : number of time this function was called | ||
112 | * @param[out] fullTime : total time of all function calls | ||
113 | * @param[out] averageTime : average time of one function calls | ||
114 | * @param[out] stdTime : standard deviation between all function calls (if nbCall is small this result can be unrelevant) | ||
115 | * @param[out] minTime : minimum time of a single execution | ||
116 | * @param[out] maxTime : maximum time of a single execution | ||
117 | */ | ||
118 | 27 | void PFunctionPerf::getPerf(size_t & nbCall, double & fullTime, double & averageTime, double & stdTime, size_t & minTime, size_t & maxTime) const{ | |
119 | 27 | nbCall = reduceVectorVale(p_nbCall); | |
120 |
2/2✓ Branch 0 (3→4) taken 22 times.
✓ Branch 1 (3→9) taken 5 times.
|
27 | if(nbCall != 0lu){ |
121 | 22 | fullTime = reduceVectorVale(p_fullTime); | |
122 | 22 | averageTime = fullTime/((double)nbCall); | |
123 | 22 | stdTime = sqrt((reduceVectorVale(p_fullSqrTime)/((double)nbCall)) - (averageTime*averageTime)); | |
124 | 22 | minTime = reduceVectorVale(p_minTime)*0.5; | |
125 | 22 | maxTime = reduceVectorVale(p_maxTime)*0.5; | |
126 | }else{ | ||
127 | 5 | fullTime = 0.0; | |
128 | 5 | averageTime = 0.0; | |
129 | 5 | stdTime = 0.0; | |
130 | 5 | minTime = 0.0; | |
131 | 5 | maxTime = 0.0; | |
132 | } | ||
133 | 27 | } | |
134 | |||
135 | ///Get the name of the function to profile | ||
136 | /** @return name of the function to profile | ||
137 | */ | ||
138 | 2 | const std::string & PFunctionPerf::getName() const{ | |
139 | 2 | return p_name; | |
140 | } | ||
141 | |||
142 | ///Print the performance of the function | ||
143 | /** @param[out] : out : ostream to be used | ||
144 | */ | ||
145 | 16 | void PFunctionPerf::print(std::ostream & out) const{ | |
146 | 16 | size_t nbCall(0lu); | |
147 | 16 | double fullTime(0.0), averageTime(0.0), stdTime(0.0); | |
148 | 16 | size_t minTime(0lu), maxTime(0lu); | |
149 |
1/1✓ Branch 0 (2→3) taken 16 times.
|
16 | getPerf(nbCall, fullTime, averageTime, stdTime, minTime, maxTime); |
150 |
16/16✓ Branch 0 (3→4) taken 16 times.
✓ Branch 2 (4→5) taken 16 times.
✓ Branch 4 (5→6) taken 16 times.
✓ Branch 6 (6→7) taken 16 times.
✓ Branch 8 (7→8) taken 16 times.
✓ Branch 10 (8→9) taken 16 times.
✓ Branch 12 (9→10) taken 16 times.
✓ Branch 14 (10→11) taken 16 times.
✓ Branch 16 (11→12) taken 16 times.
✓ Branch 18 (12→13) taken 16 times.
✓ Branch 20 (13→14) taken 16 times.
✓ Branch 22 (14→15) taken 16 times.
✓ Branch 24 (15→16) taken 16 times.
✓ Branch 26 (16→17) taken 16 times.
✓ Branch 28 (17→18) taken 16 times.
✓ Branch 30 (18→19) taken 16 times.
|
16 | out << "Function "<<p_name<<"(nbCall = " << nbCall << ", fullTime = " << fullTime << " cy, averageTime = " << averageTime << " cy, stdTime = " << stdTime << " cy, minTime = " << minTime << " cy, maxTime = " << maxTime << " cy)" << std::endl; |
151 | 16 | } | |
152 | |||
153 | ///Print the performance of the function in CSV format | ||
154 | /** @param[out] : out : ostream to be used | ||
155 | */ | ||
156 | 11 | void PFunctionPerf::printCsv(std::ostream & out) const{ | |
157 | 11 | size_t nbCall(0lu); | |
158 | 11 | double fullTime(0.0), averageTime(0.0), stdTime(0.0); | |
159 | 11 | size_t minTime(0lu), maxTime(0lu); | |
160 |
1/1✓ Branch 0 (2→3) taken 11 times.
|
11 | getPerf(nbCall, fullTime, averageTime, stdTime, minTime, maxTime); |
161 |
14/14✓ Branch 0 (3→4) taken 11 times.
✓ Branch 2 (4→5) taken 11 times.
✓ Branch 4 (5→6) taken 11 times.
✓ Branch 6 (6→7) taken 11 times.
✓ Branch 8 (7→8) taken 11 times.
✓ Branch 10 (8→9) taken 11 times.
✓ Branch 12 (9→10) taken 11 times.
✓ Branch 14 (10→11) taken 11 times.
✓ Branch 16 (11→12) taken 11 times.
✓ Branch 18 (12→13) taken 11 times.
✓ Branch 20 (13→14) taken 11 times.
✓ Branch 22 (14→15) taken 11 times.
✓ Branch 24 (15→16) taken 11 times.
✓ Branch 26 (16→17) taken 11 times.
|
11 | out <<p_name<<"," << nbCall << "," << fullTime << "," << averageTime << "," << stdTime << "," << minTime << "," << maxTime << std::endl; |
162 | 11 | } | |
163 | |||
164 | ///Copy function of PFunctionPerf | ||
165 | /** @param other : class to copy | ||
166 | */ | ||
167 | 9 | void PFunctionPerf::copyPFunctionPerf(const PFunctionPerf & other){ | |
168 | 9 | p_name = other.p_name; | |
169 | 9 | p_timeBegin = other.p_timeBegin; | |
170 | 9 | p_nbCall = other.p_nbCall; | |
171 | 9 | p_fullTime = other.p_fullTime; | |
172 | 9 | p_fullSqrTime = other.p_fullSqrTime; | |
173 | 9 | p_minTime = other.p_minTime; | |
174 | 9 | p_maxTime = other.p_maxTime; | |
175 | 9 | } | |
176 | |||
177 | /** @param name : name of the function to profile | ||
178 | */ | ||
179 | ///Initialisation function of the class PFunctionPerf | ||
180 | 6 | void PFunctionPerf::initialisationPFunctionPerf(const std::string & name){ | |
181 | 6 | p_name = name; | |
182 | 6 | resize(1lu); | |
183 | 6 | } | |
184 | |||
185 | |||
186 | |||
187 | |||
188 | |||
189 |