Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new statistical profiling feature
- Loading branch information
1 parent
a48c2f9
commit 7b43f2b
Showing
2 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
SimulationRuntime/cpp/Core/Utils/extension/measure_time_statistic.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#include <Core/Utils/extension/measure_time_statistic.hpp> | ||
#include <limits> | ||
#include <cmath> | ||
#include <algorithm> | ||
|
||
MeasureTimeValuesStatistic::MeasureTimeValuesStatistic(unsigned long long time) : MeasureTimeValuesRDTSC(time), _quad_sum(time), | ||
_min_time(std::numeric_limits<unsigned long long>::max()), _count(10), _kill_time(0) {} | ||
|
||
|
||
MeasureTimeValuesStatistic::~MeasureTimeValuesStatistic() {} | ||
|
||
std::string MeasureTimeValuesStatistic::serializeToJson() | ||
{ | ||
unsigned long long act_time = (_count < _numCalcs ? _time - _kill_time : _time); | ||
unsigned actNumCalcs = (_count < _numCalcs ? _numCalcs-_count : _numCalcs); | ||
long double average = (long double)act_time/actNumCalcs, stdDev = sqrt(((long double)_quad_sum/actNumCalcs) -(average*average));// V(x) = E(x*x) - E(x)*E(x) | ||
std::stringstream ss; | ||
|
||
ss << "\"ncall\":" << _numCalcs << "," << "\"time\":" << _time << ",\"maxTime\":" << _max_time << ",\"minTime\":" << (_numCalcs == 0 ? 0 : _min_time) << ",\"meanTime\":" << (_numCalcs == 0 ? 0 : average) | ||
<< ",\"std.deviation\":" << (_numCalcs == 0 ? 0 : stdDev ) << ",\"std.rel.deviation\":" << (_numCalcs == 0 ? 0 : stdDev/average); | ||
return ss.str(); | ||
} | ||
|
||
void MeasureTimeValuesStatistic::add(MeasureTimeValues *values) | ||
{ | ||
MeasureTimeValuesRDTSC::add(values); | ||
|
||
MeasureTimeValuesStatistic *val = static_cast<MeasureTimeValuesStatistic*>(values); | ||
if( val->_time < _min_time ) | ||
_min_time = val->_time; | ||
|
||
if(_numCalcs<_count) | ||
{ | ||
_kill_time +=val->_time; | ||
} | ||
else | ||
_quad_sum += val->_time*val->_time; | ||
} | ||
|
||
void MeasureTimeValuesStatistic::filter(unsigned long long val) | ||
{ | ||
|
||
} | ||
|
||
void MeasureTimeValuesStatistic::sub(MeasureTimeValues *values) | ||
{ | ||
MeasureTimeValuesRDTSC::sub(values); | ||
MeasureTimeValuesStatistic *val = static_cast<MeasureTimeValuesStatistic*>(values); | ||
if(_quad_sum > val->_time*val->_time) | ||
_quad_sum -= val->_time * val->_time; | ||
else | ||
_quad_sum = 0ull; | ||
} | ||
|
||
MeasureTimeStatistic::MeasureTimeStatistic() : MeasureTimeRDTSC() | ||
{ | ||
} | ||
|
||
MeasureTimeStatistic::~MeasureTimeStatistic() | ||
{ | ||
} | ||
|
||
MeasureTimeValues* MeasureTimeStatistic::getZeroValuesP() | ||
{ | ||
return new MeasureTimeValuesStatistic(0ull); | ||
} | ||
|
46 changes: 46 additions & 0 deletions
46
SimulationRuntime/cpp/Include/Core/Utils/extension/measure_time_statistic.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#ifndef MEASURE_TIME_STATISTIC_HPP_ | ||
#define MEASURE_TIME_STATISTIC_HPP_ | ||
|
||
#include <Core/Utils/extension/measure_time_rdtsc.hpp> | ||
|
||
class BOOST_EXTENSION_EXPORT_DECL MeasureTimeValuesStatistic : public MeasureTimeValuesRDTSC | ||
{ | ||
public: | ||
unsigned long long _min_time; | ||
unsigned long long _kill_time; | ||
|
||
MeasureTimeValuesStatistic(unsigned long long time); | ||
|
||
virtual ~MeasureTimeValuesStatistic(); | ||
|
||
virtual std::string serializeToJson(); | ||
|
||
virtual void add(MeasureTimeValues *values); | ||
virtual void sub(MeasureTimeValues *values); | ||
|
||
private: | ||
long double _quad_sum; // used to calculate standard variation sqrt(sum_i(xi-xaverage)) | ||
unsigned _count; | ||
|
||
void filter(unsigned long long val); | ||
|
||
}; | ||
|
||
class BOOST_EXTENSION_EXPORT_DECL MeasureTimeStatistic : public MeasureTimeRDTSC | ||
{ | ||
protected: | ||
MeasureTimeStatistic(); | ||
|
||
MeasureTimeValues* getZeroValuesP(); | ||
|
||
public: | ||
virtual ~MeasureTimeStatistic(); | ||
|
||
static void initialize() | ||
{ | ||
instance = new MeasureTimeStatistic(); | ||
instance->setOverheadToZero(); | ||
} | ||
}; | ||
|
||
#endif /* MEASURE_TIME_STATISTIC_HPP_ */ |