PhoenixHardware  0.2.0
Tools to get hardware information
Loading...
Searching...
No Matches
PFunctionPerf Class Reference

Performances of a function. More...

#include <PFunctionPerf.h>

Public Member Functions

const std::string & getName () const
 Get the name of the function to profile.
 
void getPerf (size_t &nbCall, double &fullTime, double &averageTime, double &stdTime, size_t &minTime, size_t &maxTime) const
 Get the performances of the current function.
 
PFunctionPerfoperator= (const PFunctionPerf &other)
 Definition of equal operator of PFunctionPerf.
 
 PFunctionPerf (const PFunctionPerf &other)
 Copy constructor of PFunctionPerf.
 
 PFunctionPerf (const std::string &name="")
 Default constructor of PFunctionPerf.
 
void print (std::ostream &out=std::cout) const
 Print the performance of the function.
 
void printCsv (std::ostream &out=std::cout) const
 Print the performance of the function in CSV format.
 
void reset ()
 Reset the profiling.
 
void reset (size_t threadIndex)
 Reset the profiling.
 
void resize (size_t nbThread)
 Resize the PFunctionPerf by respect to the number of thread which call the function.
 
void setName (const std::string &name)
 Set the name of the function profiled by the current PFunctionPerf.
 
void start (size_t threadIndex=0lu)
 Start the timing for one function.
 
void stop (size_t threadIndex=0lu)
 Stop the timing of one function.
 
virtual ~PFunctionPerf ()
 Destructor of PFunctionPerf.
 

Protected Member Functions

void copyPFunctionPerf (const PFunctionPerf &other)
 Copy function of PFunctionPerf.
 

Private Member Functions

void initialisationPFunctionPerf (const std::string &name)
 Initialisation function of the class PFunctionPerf.
 

Private Attributes

std::vector< double > p_fullSqrTime
 Sum of all square times (used to compute standard deviation)
 
std::vector< double > p_fullTime
 Full time of execution for the current function (compute the averaged time with nbCall)
 
std::vector< size_t > p_maxTime
 Maximum execution time.
 
std::vector< size_t > p_minTime
 Minimum execution time.
 
std::string p_name
 Name of the function to profile.
 
std::vector< size_t > p_nbCall
 Number of calls of the current function.
 
std::vector< size_t > p_timeBegin
 Begin time of the current performance evaluation.
 

Detailed Description

Performances of a function.

Definition at line 17 of file PFunctionPerf.h.

Constructor & Destructor Documentation

◆ PFunctionPerf() [1/2]

PFunctionPerf::PFunctionPerf ( const std::string & name = "")

Default constructor of PFunctionPerf.

Parameters
name: name of the function to profile

Definition at line 13 of file PFunctionPerf.cpp.

13 {
15}
void initialisationPFunctionPerf(const std::string &name)
Initialisation function of the class PFunctionPerf.

References initialisationPFunctionPerf().

Referenced by copyPFunctionPerf(), operator=(), and PFunctionPerf().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ PFunctionPerf() [2/2]

PFunctionPerf::PFunctionPerf ( const PFunctionPerf & other)

Copy constructor of PFunctionPerf.

Parameters
other: class to copy

Definition at line 20 of file PFunctionPerf.cpp.

20 {
21 copyPFunctionPerf(other);
22}
void copyPFunctionPerf(const PFunctionPerf &other)
Copy function of PFunctionPerf.

References copyPFunctionPerf(), and PFunctionPerf().

+ Here is the call graph for this function:

◆ ~PFunctionPerf()

PFunctionPerf::~PFunctionPerf ( )
virtual

Destructor of PFunctionPerf.

Definition at line 25 of file PFunctionPerf.cpp.

25 {
26
27}

Member Function Documentation

◆ copyPFunctionPerf()

void PFunctionPerf::copyPFunctionPerf ( const PFunctionPerf & other)
protected

Copy function of PFunctionPerf.

Parameters
other: class to copy

Definition at line 167 of file PFunctionPerf.cpp.

167 {
168 p_name = other.p_name;
169 p_timeBegin = other.p_timeBegin;
170 p_nbCall = other.p_nbCall;
171 p_fullTime = other.p_fullTime;
173 p_minTime = other.p_minTime;
174 p_maxTime = other.p_maxTime;
175}
std::string p_name
Name of the function to profile.
std::vector< double > p_fullTime
Full time of execution for the current function (compute the averaged time with nbCall)
std::vector< size_t > p_maxTime
Maximum execution time.
std::vector< double > p_fullSqrTime
Sum of all square times (used to compute standard deviation)
std::vector< size_t > p_nbCall
Number of calls of the current function.
std::vector< size_t > p_minTime
Minimum execution time.
std::vector< size_t > p_timeBegin
Begin time of the current performance evaluation.

References p_fullSqrTime, p_fullTime, p_maxTime, p_minTime, p_name, p_nbCall, p_timeBegin, and PFunctionPerf().

Referenced by operator=(), and PFunctionPerf().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getName()

const std::string & PFunctionPerf::getName ( ) const

Get the name of the function to profile.

Returns
name of the function to profile

Definition at line 138 of file PFunctionPerf.cpp.

138 {
139 return p_name;
140}

References p_name.

◆ getPerf()

void PFunctionPerf::getPerf ( size_t & nbCall,
double & fullTime,
double & averageTime,
double & stdTime,
size_t & minTime,
size_t & maxTime ) const

Get the performances of the current function.

Parameters
[out]nbCall: number of time this function was called
[out]fullTime: total time of all function calls
[out]averageTime: average time of one function calls
[out]stdTime: standard deviation between all function calls (if nbCall is small this result can be unrelevant)
[out]minTime: minimum time of a single execution
[out]maxTime: maximum time of a single execution

Definition at line 118 of file PFunctionPerf.cpp.

118 {
119 nbCall = reduceVectorVale(p_nbCall);
120 if(nbCall != 0lu){
121 fullTime = reduceVectorVale(p_fullTime);
122 averageTime = fullTime/((double)nbCall);
123 stdTime = sqrt((reduceVectorVale(p_fullSqrTime)/((double)nbCall)) - (averageTime*averageTime));
124 minTime = reduceVectorVale(p_minTime)*0.5;
125 maxTime = reduceVectorVale(p_maxTime)*0.5;
126 }else{
127 fullTime = 0.0;
128 averageTime = 0.0;
129 stdTime = 0.0;
130 minTime = 0.0;
131 maxTime = 0.0;
132 }
133}
T reduceVectorVale(const std::vector< T > &vec)
Sum the given vector.

References p_fullSqrTime, p_fullTime, p_maxTime, p_minTime, p_nbCall, and reduceVectorVale().

Referenced by print(), and printCsv().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initialisationPFunctionPerf()

void PFunctionPerf::initialisationPFunctionPerf ( const std::string & name)
private

Initialisation function of the class PFunctionPerf.

Parameters
name: name of the function to profile

Definition at line 180 of file PFunctionPerf.cpp.

180 {
181 p_name = name;
182 resize(1lu);
183}
void resize(size_t nbThread)
Resize the PFunctionPerf by respect to the number of thread which call the function.

References p_name, and resize().

Referenced by PFunctionPerf().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator=()

PFunctionPerf & PFunctionPerf::operator= ( const PFunctionPerf & other)

Definition of equal operator of PFunctionPerf.

Parameters
other: class to copy
Returns
copied class

Definition at line 33 of file PFunctionPerf.cpp.

33 {
34 copyPFunctionPerf(other);
35 return *this;
36}

References copyPFunctionPerf(), and PFunctionPerf().

+ Here is the call graph for this function:

◆ print()

void PFunctionPerf::print ( std::ostream & out = std::cout) const

Print the performance of the function.

Parameters
[out]out : ostream to be used

Definition at line 145 of file PFunctionPerf.cpp.

145 {
146 size_t nbCall(0lu);
147 double fullTime(0.0), averageTime(0.0), stdTime(0.0);
148 size_t minTime(0lu), maxTime(0lu);
149 getPerf(nbCall, fullTime, averageTime, stdTime, minTime, maxTime);
150 out << "Function "<<p_name<<"(nbCall = " << nbCall << ", fullTime = " << fullTime << " cy, averageTime = " << averageTime << " cy, stdTime = " << stdTime << " cy, minTime = " << minTime << " cy, maxTime = " << maxTime << " cy)" << std::endl;
151}
void getPerf(size_t &nbCall, double &fullTime, double &averageTime, double &stdTime, size_t &minTime, size_t &maxTime) const
Get the performances of the current function.

References getPerf(), and p_name.

+ Here is the call graph for this function:

◆ printCsv()

void PFunctionPerf::printCsv ( std::ostream & out = std::cout) const

Print the performance of the function in CSV format.

Parameters
[out]out : ostream to be used

Definition at line 156 of file PFunctionPerf.cpp.

156 {
157 size_t nbCall(0lu);
158 double fullTime(0.0), averageTime(0.0), stdTime(0.0);
159 size_t minTime(0lu), maxTime(0lu);
160 getPerf(nbCall, fullTime, averageTime, stdTime, minTime, maxTime);
161 out <<p_name<<"," << nbCall << "," << fullTime << "," << averageTime << "," << stdTime << "," << minTime << "," << maxTime << std::endl;
162}

References getPerf(), and p_name.

+ Here is the call graph for this function:

◆ reset() [1/2]

void PFunctionPerf::reset ( )

Reset the profiling.

Definition at line 91 of file PFunctionPerf.cpp.

91 {
92 for(size_t i(0lu); i < p_timeBegin.size(); ++i){
93 reset(i);
94 }
95}
void reset()
Reset the profiling.

References p_timeBegin, and reset().

Referenced by reset(), and resize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ reset() [2/2]

void PFunctionPerf::reset ( size_t threadIndex)

Reset the profiling.

Parameters
threadIndex: index of the current thread to be measured

Definition at line 81 of file PFunctionPerf.cpp.

81 {
82 p_timeBegin[threadIndex] = 0lu;
83 p_nbCall[threadIndex] = 0lu;
84 p_fullTime[threadIndex] = 0.0;
85 p_fullSqrTime[threadIndex] = 0.0;
86 p_minTime[threadIndex] = -1lu;
87 p_maxTime[threadIndex] = 0lu;
88}

References p_fullSqrTime, p_fullTime, p_maxTime, p_minTime, p_nbCall, and p_timeBegin.

◆ resize()

void PFunctionPerf::resize ( size_t nbThread)

Resize the PFunctionPerf by respect to the number of thread which call the function.

Parameters
nbThread: number of threads which call the function

Definition at line 48 of file PFunctionPerf.cpp.

48 {
49 p_timeBegin.resize(nbThread);
50 p_nbCall.resize(nbThread);
51 p_fullTime.resize(nbThread);
52 p_fullSqrTime.resize(nbThread);
53 p_minTime.resize(nbThread);
54 p_maxTime.resize(nbThread);
55 reset();
56}

References p_fullSqrTime, p_fullTime, p_maxTime, p_minTime, p_nbCall, p_timeBegin, and reset().

Referenced by PProfiler::addFunction(), and initialisationPFunctionPerf().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setName()

void PFunctionPerf::setName ( const std::string & name)

Set the name of the function profiled by the current PFunctionPerf.

Parameters
name: name of the function to profile

Definition at line 41 of file PFunctionPerf.cpp.

41 {
42 p_name = name;
43}

References p_name.

◆ start()

void PFunctionPerf::start ( size_t threadIndex = 0lu)

Start the timing for one function.

Parameters
threadIndex: index of the current thread to be measured

Definition at line 61 of file PFunctionPerf.cpp.

61 {
62 p_timeBegin[threadIndex] = phoenix_hardware_rdtsc();
63}

References p_timeBegin.

◆ stop()

void PFunctionPerf::stop ( size_t threadIndex = 0lu)

Stop the timing of one function.

Parameters
threadIndex: index of the current thread to be measured

Definition at line 68 of file PFunctionPerf.cpp.

68 {
69 size_t elapsedTime = phoenix_hardware_rdtsc() - p_timeBegin[threadIndex];
70 double dTime = elapsedTime;
71 p_fullTime[threadIndex] += dTime;
72 p_fullSqrTime[threadIndex] += dTime*dTime;
73 if(elapsedTime > p_maxTime[threadIndex]){p_maxTime[threadIndex] = elapsedTime;}
74 if(elapsedTime < p_minTime[threadIndex]){p_minTime[threadIndex] = elapsedTime;}
75 ++(p_nbCall[threadIndex]);
76}

References p_fullSqrTime, p_fullTime, p_maxTime, p_minTime, p_nbCall, and p_timeBegin.

Member Data Documentation

◆ p_fullSqrTime

std::vector<double> PFunctionPerf::p_fullSqrTime
private

Sum of all square times (used to compute standard deviation)

Definition at line 53 of file PFunctionPerf.h.

Referenced by copyPFunctionPerf(), getPerf(), reset(), resize(), and stop().

◆ p_fullTime

std::vector<double> PFunctionPerf::p_fullTime
private

Full time of execution for the current function (compute the averaged time with nbCall)

Definition at line 51 of file PFunctionPerf.h.

Referenced by copyPFunctionPerf(), getPerf(), reset(), resize(), and stop().

◆ p_maxTime

std::vector<size_t> PFunctionPerf::p_maxTime
private

Maximum execution time.

Definition at line 57 of file PFunctionPerf.h.

Referenced by copyPFunctionPerf(), getPerf(), reset(), resize(), and stop().

◆ p_minTime

std::vector<size_t> PFunctionPerf::p_minTime
private

Minimum execution time.

Definition at line 55 of file PFunctionPerf.h.

Referenced by copyPFunctionPerf(), getPerf(), reset(), resize(), and stop().

◆ p_name

std::string PFunctionPerf::p_name
private

Name of the function to profile.

Definition at line 45 of file PFunctionPerf.h.

Referenced by copyPFunctionPerf(), getName(), initialisationPFunctionPerf(), print(), printCsv(), and setName().

◆ p_nbCall

std::vector<size_t> PFunctionPerf::p_nbCall
private

Number of calls of the current function.

Definition at line 49 of file PFunctionPerf.h.

Referenced by copyPFunctionPerf(), getPerf(), reset(), resize(), and stop().

◆ p_timeBegin

std::vector<size_t> PFunctionPerf::p_timeBegin
private

Begin time of the current performance evaluation.

Definition at line 47 of file PFunctionPerf.h.

Referenced by copyPFunctionPerf(), reset(), reset(), resize(), start(), and stop().


The documentation for this class was generated from the following files: