Peano
Loading...
Searching...
No Matches
Statistics.h
Go to the documentation of this file.
1// This file is part of the Peano project. For conditions of distribution and
2// use, please see the copyright notice at www.peano-framework.org
3#pragma once
4
5#include <string>
6#include <map>
7#include <vector>
8#include <tuple>
9
10#include "Log.h"
11#include "tarch/timing/Watch.h"
13
14namespace tarch {
15 namespace logging {
16 class Statistics;
17 }
18}
19
73 public:
78 static Statistics& getInstance();
79
80 #ifdef TrackStatistics
91 void log( const std::string& identifier, double value, bool disableSampling = false );
92
96 void log( const std::string& identifier, const std::string& value );
97
103 void inc( const std::string& identifier, double value = 1.0, bool disableSampling = false, bool clearAfterDatabaseDump = false );
104 #else
105 inline void log( [[maybe_unused]] const std::string& identifier, [[maybe_unused]] double value, [[maybe_unused]] bool disableSampling = false ) {}
106 inline void log( [[maybe_unused]] const std::string& identifier, [[maybe_unused]] const std::string& value ) {}
107 inline void inc( [[maybe_unused]] const std::string& identifier, [[maybe_unused]] double value = 1.0, [[maybe_unused]] bool disableSampling = false, [[maybe_unused]] bool clearAfterDatabaseDump = false ) {}
108 #endif
109
142 void writeToCSV( std::string filename = "statistics" );
143
144 void clear();
145
146 private:
148
149 static Log _log;
150
152
155
157
168 struct DataSet {
174 std::vector< std::tuple<double,double,double,double,int> > _data;
179 DataSet();
180 DataSet(double time);
181 void createNewSnapshot(double t, bool clearAfterDatabaseDump);
182
183 std::string toString() const;
184 };
185
186 struct LogMessage {
187 std::vector< std::tuple<double,std::string> > _data;
188 LogMessage() = default;
189 };
190
194 std::map< std::string, DataSet > _dataSetMap;
195 std::map< std::string, LogMessage > _logMessageMap;
196
197 Statistics();
198
214 bool acceptNewData(const std::string& identifier, bool disableSampling);
215
221 void initData(const std::string& identifier);
222
226 void updateDataSnapshot(const std::string& identifier, double value);
227};
Log Device.
Definition Log.h:516
Global statistics interface.
Definition Statistics.h:72
tarch::timing::Watch _globalWatch
Definition Statistics.h:156
void log(const std::string &identifier, double value, bool disableSampling=false)
Definition Statistics.h:105
std::map< std::string, LogMessage > _logMessageMap
Definition Statistics.h:195
void updateDataSnapshot(const std::string &identifier, double value)
Updates snapshot.
void initData(const std::string &identifier)
Ensures that dataset is there.
void log(const std::string &identifier, const std::string &value)
Definition Statistics.h:106
void writeToCSV(std::string filename="statistics")
Write data to csv file.
void inc(const std::string &identifier, double value=1.0, bool disableSampling=false, bool clearAfterDatabaseDump=false)
Definition Statistics.h:107
std::map< std::string, DataSet > _dataSetMap
Mapping from identifier who wrote stats (key) onto DataSet.
Definition Statistics.h:194
static tarch::multicore::BooleanSemaphore _semaphore
Definition Statistics.h:151
static Statistics _singleton
Definition Statistics.h:147
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.
A simple class that has to be included to measure the clock ticks required for an operation.
Definition Watch.h:45
Have to include this header, as I need access to the SYCL_EXTERNAL keyword.
Definition accelerator.h:19
One data set for one type (identifier) of statistics.
Definition Statistics.h:168
DataSet()
As we hold data sets within a map, we need a default constructor.
void createNewSnapshot(double t, bool clearAfterDatabaseDump)
tarch::timing::Watch _watch
Not used for time stamps but only for sampling.
Definition Statistics.h:172
std::vector< std::tuple< double, double, double, double, int > > _data
Definition Statistics.h:174
std::vector< std::tuple< double, std::string > > _data
Definition Statistics.h:187