Peano 4
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
85 #ifdef TrackStatistics
86 void log( const std::string& identifier, double value, bool disableSampling = false );
87 void log( const std::string& identifier, const std::string& value );
88 void inc( const std::string& identifier, double value = 1.0, bool disableSampling = false );
89 #else
90 inline void log( [[maybe_unused]] const std::string& identifier, [[maybe_unused]] double value, [[maybe_unused]] bool disableSampling = false ) {}
91 inline void log( [[maybe_unused]] const std::string& identifier, [[maybe_unused]] const std::string& value ) {}
92 inline void inc( [[maybe_unused]] const std::string& identifier, [[maybe_unused]] double value = 1.0, [[maybe_unused]] bool disableSampling = false ) {}
93 #endif
94
127 void writeToCSV( std::string filename = "statistics" );
128
129 void clear();
130
131 private:
133
134 static Log _log;
135
137
140
142
153 struct DataSet {
159 std::vector< std::tuple<double,double,double,double,int> > _data;
164 DataSet();
165 DataSet(double time);
166 void createNewSnapshot(double t);
167 };
168
169 struct LogMessage {
170 std::vector< std::tuple<double,std::string> > _data;
171 LogMessage() = default;
172 };
173
177 std::map< std::string, DataSet > _dataSetMap;
178 std::map< std::string, LogMessage > _logMessageMap;
179
180 Statistics();
181
197 bool acceptNewData(const std::string& identifier, bool disableSampling);
198
204 void initData(const std::string& identifier);
205
209 void updateDataSnapshot(const std::string& identifier, double value);
210};
Log Device.
Definition Log.h:516
Global statistics interface.
Definition Statistics.h:72
void inc(const std::string &identifier, double value=1.0, bool disableSampling=false)
Definition Statistics.h:92
tarch::timing::Watch _globalWatch
Definition Statistics.h:141
void log(const std::string &identifier, double value, bool disableSampling=false)
Log one particular value.
Definition Statistics.h:90
std::map< std::string, LogMessage > _logMessageMap
Definition Statistics.h:178
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:91
void writeToCSV(std::string filename="statistics")
Write data to csv file.
std::map< std::string, DataSet > _dataSetMap
Mapping from identifier who wrote stats (key) onto DataSet.
Definition Statistics.h:177
static tarch::multicore::BooleanSemaphore _semaphore
Definition Statistics.h:136
static Statistics _singleton
Definition Statistics.h:132
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:17
One data set for one type (identifier) of statistics.
Definition Statistics.h:153
DataSet()
As we hold data sets within a map, we need a default constructor.
tarch::timing::Watch _watch
Not used for time stamps but only for sampling.
Definition Statistics.h:157
std::vector< std::tuple< double, double, double, double, int > > _data
Definition Statistics.h:159
std::vector< std::tuple< double, std::string > > _data
Definition Statistics.h:170