26 _globalWatch(
"tarch::logging::Statistics",
"Statistics", false) {
32 _watch(
"tarch::logging::Statistics",
"Statistics", false),
38 _watch(
"tarch::logging::Statistics",
"Statistics", false),
40 _data.push_back( std::make_tuple(time,0.0,0.0,0.0,0) );
45 std::ostringstream msg;
46 msg <<
"(#" <<
_data.size() <<
", ("
47 << std::get<0>(
_data.back() ) <<
", "
48 << std::get<1>(
_data.back() ) <<
", "
49 << std::get<2>(
_data.back() ) <<
", "
50 << std::get<3>(
_data.back() ) <<
", "
51 << std::get<4>(
_data.back() ) <<
"))";
57 double lastValueFromPreviousSnapshot = clearAfterDatabaseDump ? 0.0 : std::get<1>(
_data.back() );
58 _data.push_back( std::make_tuple(
60 lastValueFromPreviousSnapshot,
61 lastValueFromPreviousSnapshot,
62 lastValueFromPreviousSnapshot,
123 std::get<4>(
_dataSetMap[identifier]._data.back() ) = 1 + std::get<4>(
_dataSetMap[identifier]._data.back() );
127#ifdef TrackStatistics
131 _logMessageMap.insert( std::pair< std::string, LogMessage >( identifier, LogMessage() ) );
148 logDebug(
"log(string,double)", identifier <<
"=" <<
value );
149 _dataSetMap[identifier].createNewSnapshot(t,
false);
158 double newValue = std::get<1>(
_dataSetMap[identifier]._data.back() ) +
value;
164 _dataSetMap[identifier].createNewSnapshot(t, clearAfterDatabaseDump);
171#ifdef TrackStatistics
172 logDebug(
"writeToCSV(string)",
"start to dump statistics into file " << filename );
181 int totalNumberOfEntries = 0;
183 totalNumberOfEntries += p.second._data.size();
186 totalNumberOfEntries += p.second._data.size();
188 logInfo(
"writeToCSV(string)",
"write statistics to file " << filename <<
" (total no of entries=" << totalNumberOfEntries <<
")" );
190 std::ofstream file( filename );
193 file <<
", " << p.first;
196 file <<
", " << p.first;
201 while (t<std::numeric_limits<double>::max()) {
203 t = std::numeric_limits<double>::max();
205 auto computeT = [&](
double currentT) {
206 t = std::min( t, currentT );
210 if (not p.second._data.empty()) {
211 computeT( std::get<0>(p.second._data.front()) );
215 if (not p.second._data.empty()) {
216 computeT( std::get<0>(p.second._data.front()) );
221 if (t<std::numeric_limits<double>::max()) {
225 not p.second._data.empty()
227 tarch::la::smallerEquals( std::get<0>(p.second._data.front()), t )
229 file <<
", (" << std::get<1>(p.second._data.front())
230 <<
"/" << std::get<2>(p.second._data.front())
231 <<
"/" << std::get<3>(p.second._data.front())
232 <<
"/#" << std::get<4>(p.second._data.front())
234 p.second._data.erase(p.second._data.begin());
242 not pp.second._data.empty()
244 tarch::la::smallerEquals( std::get<0>(pp.second._data.front()), t )
246 file <<
", \"" << std::get<1>(pp.second._data.front()) <<
"\" ";
247 pp.second._data.erase(pp.second._data.begin());
265 logWarning(
"writeToCSV(string)",
"no statistics available. Recompile with -DTrackStatistics for runtime sampling" );
#define logDebug(methodName, logMacroMessageStream)
#define logWarning(methodName, logMacroMessageStream)
Wrapper macro around tarch::tarch::logging::Log to improve logging.
#define logInfo(methodName, logMacroMessageStream)
Wrapper macro around tarch::tarch::logging::Log to improve logging.
Global statistics interface.
tarch::timing::Watch _globalWatch
void log(const std::string &identifier, double value, bool disableSampling=false)
std::map< std::string, LogMessage > _logMessageMap
void updateDataSnapshot(const std::string &identifier, double value)
Updates snapshot.
void initData(const std::string &identifier)
Ensures that dataset is there.
void writeToCSV(std::string filename="statistics")
Write data to csv file.
double _maxTimeInBetweenTwoMeasurements
void inc(const std::string &identifier, double value=1.0, bool disableSampling=false, bool clearAfterDatabaseDump=false)
int _maxCountInBetweenTwoMeasurements
std::map< std::string, DataSet > _dataSetMap
Mapping from identifier who wrote stats (key) onto DataSet.
static tarch::multicore::BooleanSemaphore _semaphore
static Statistics _singleton
bool acceptNewData(const std::string &identifier, bool disableSampling)
Not const, as it also updates the internal counters.
static Statistics & getInstance()
This is not the canonical realisation of singletons as I use it usually for stats in Peano.
static Rank & getInstance()
This operation returns the singleton instance.
Create a lock around a boolean semaphore region.
double getCalendarTime()
This method returns the elapsed calendar time between the start and stop command of the timer,...
One data set for one type (identifier) of statistics.
DataSet()
As we hold data sets within a map, we need a default constructor.
void createNewSnapshot(double t, bool clearAfterDatabaseDump)
std::string toString() const
tarch::timing::Watch _watch
Not used for time stamps but only for sampling.
std::vector< std::tuple< double, double, double, double, int > > _data