preCICE v3.1.2
Loading...
Searching...
No Matches
EventUtils.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <chrono>
4#include <cstddef>
5#include <fstream>
6#include <iosfwd>
7#include <optional>
8#include <string>
9#include <string_view>
10#include <utility>
11#include <variant>
12#include <vector>
13
14#include "logging/Logger.hpp"
15#include "profiling/Event.hpp"
16#include "utils/assertion.hpp"
17
18namespace precice::profiling {
19
21enum struct Mode {
22 All,
24 Off
25};
26
27enum struct EventClass : bool {
28 Normal = false,
29 Fundamental = true
30};
31
32inline EventClass toEventClass(bool isFundamental)
33{
34 return static_cast<EventClass>(isFundamental);
35}
36
38struct TimedEntry {
39 TimedEntry(int eid, Event::Clock::time_point c)
40 : eid(eid), clock(c) {}
41
42 int eid;
43 Event::Clock::time_point clock;
44};
45
48 static constexpr char type = 'b';
49};
50
53 static constexpr char type = 'e';
54};
55
57 DataEntry(int eid, Event::Clock::time_point c, int did, int dv)
58 : TimedEntry(eid, c), did(did), dvalue(dv) {}
59
60 static constexpr char type = 'd';
61 int did;
62 int dvalue;
63};
64
65struct NameEntry {
66 static constexpr char type = 'n';
68 int id;
69};
70
72
81public:
83
85 EventRegistry(EventRegistry const &) = delete;
89
91 static EventRegistry &instance();
92
94
99 void initialize(std::string_view applicationName, int rank = 0, int size = 1);
100
102 void setWriteQueueMax(std::size_t size);
103
105 void setDirectory(std::string_view directory);
106
108 void setMode(Mode mode);
109
111 void startBackend();
112
114 void finalize();
115
117 void clear();
118
120 void put(PendingEntry pe);
121
123 void flush();
124
126 inline bool accepting(EventClass ec) const
127 {
129 }
130
132
135
136private:
139
141
144
146 int _rank = 0;
147
149 int _size = 1;
150
152 bool _firstwrite = true;
153
156
158 EventRegistry() = default;
159
161
164
166
167 bool _initialized = false;
168
169 bool _finalized = false;
170
171 bool _isBackendRunning = false;
172
174 Event::Clock::time_point _initClock;
175
177 std::chrono::system_clock::time_point _initTime;
178
180 void stopBackend();
181
183};
184
185} // namespace precice::profiling
std::string name
This class provides a lightweight logger.
Definition Logger.hpp:16
static EventRegistry & instance()
Returns the only instance (singleton) of the EventRegistry class.
void startBackend()
Create the file and starts the filestream if profiling is turned on.
void initialize(std::string_view applicationName, int rank=0, int size=1)
Sets the global start time.
EventRegistry & operator=(EventRegistry const &)=delete
std::string prefix
Currently active prefix. Changing that applies only to newly created events.
void clear()
Clears the registry.
void setWriteQueueMax(std::size_t size)
Sets the maximum size of the writequeue before calling flush(). Use 0 to flush on destruction.
void setDirectory(std::string_view directory)
Sets the directory where to write the event files to.
int nameToID(std::string_view name)
int _size
The amount of parallel instances of the current program.
void finalize()
Sets the global end time and flushes buffers.
void setMode(Mode mode)
Sets the operational mode of the registry.
void stopBackend()
Stops the global event, flushes the buffers and closes the filestream.
Mode _mode
The operational mode of the registry.
std::vector< PendingEntry > _writeQueue
bool _firstwrite
Indicator for the first record to be written.
void put(PendingEntry pe)
Records an event.
std::map< std::string, int, std::less<> > _nameDict
EventRegistry(EventRegistry &&)=delete
EventRegistry & operator=(EventRegistry &&)=delete
bool accepting(EventClass ec) const
Should an event of this class be forwarded to the registry?
Event::Clock::time_point _initClock
The initial time clock, used to take runtime measurements.
std::optional< int > _globalId
The id of the global event.
EventRegistry()=default
Private, empty constructor for singleton pattern.
std::string _applicationName
The name of the current participant.
EventRegistry(EventRegistry const &)=delete
Deleted copy and move SMFs for singleton pattern.
void flush()
Writes all recorded events to file and flushes the buffer.
std::chrono::system_clock::time_point _initTime
The initial time, used to describe when the run started.
contains profiling utilities.
static constexpr FundamentalTag Fundamental
Convenience instance of the FundamentalTag.
Definition Event.hpp:19
EventClass toEventClass(bool isFundamental)
Mode
The Mode of the Event utility.
DataEntry(int eid, Event::Clock::time_point c, int did, int dv)
static constexpr char type
static constexpr char type
static constexpr char type
static constexpr char type
An event that has been recorded and it waiting to be written to file.
TimedEntry(int eid, Event::Clock::time_point c)
Event::Clock::time_point clock