preCICE v3.1.2
Loading...
Searching...
No Matches
Event.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <chrono>
4#include <string>
5#include <string_view>
6#include <type_traits>
7
8namespace precice::profiling {
9
12};
13
16};
17
19static constexpr FundamentalTag Fundamental{};
21static constexpr SynchronizeTag Synchronize{};
22
23// Is the type a valid options tag?
24template <typename T>
25static constexpr bool isOptionsTag = std::is_same_v<T, FundamentalTag> || std::is_same_v<T, SynchronizeTag>;
26
33class Event {
34public:
35 enum class State : bool {
36 STOPPED = false,
37 RUNNING = true
38 };
39
42
45
46 struct Options {
47 bool synchronized = false;
48 bool fundamental = false;
49
51 {
52 fundamental = true;
53 }
55 {
56 synchronized = true;
57 }
58 };
59
60 template <typename... Args>
61 constexpr Options optionsFromTags(Args... args)
62 {
63 static_assert((isOptionsTag<Args> && ...), "The Event only accepts tags as arguments.");
64 Options options;
65 (options.handle(args), ...);
66 return options;
67 }
68
69 template <typename... Args>
70 Event(std::string_view eventName, Args... args)
71 : Event(eventName, optionsFromTags(args...))
72 {
73 }
74
75 Event(std::string_view eventName, Options options);
76
77 Event(Event &&) = default;
78 Event &operator=(Event &&) = default;
79
80 // Copies would lead to duplicate entries
81 Event(const Event &other) = delete;
82 Event &operator=(const Event &) = delete;
83
85 ~Event();
86
88 void start();
89
91 void stop();
92
94 void addData(std::string_view key, int value);
95
96private:
97 int _eid;
99 bool _fundamental{false};
100 bool _synchronize{false};
101};
102
105public:
107
109
110 void pop();
111
112private:
114};
115
116} // namespace precice::profiling
std::string name
void start()
Starts or restarts a stopped event.
Definition Event.cpp:23
void stop()
Stops a running event.
Definition Event.cpp:37
Event & operator=(const Event &)=delete
constexpr Options optionsFromTags(Args... args)
Definition Event.hpp:61
Event & operator=(Event &&)=default
Event(Event &&)=default
std::string name
Name used to identify the timer. Events of the same name are accumulated to.
Definition Event.hpp:44
Event(std::string_view eventName, Args... args)
Definition Event.hpp:70
~Event()
Stops the event if it's running and report its times to the EventRegistry.
Definition Event.cpp:16
Event(const Event &other)=delete
void addData(std::string_view key, int value)
Adds named integer data, associated to an event.
Definition Event.cpp:48
Class that changes the prefix in its scope.
Definition Event.hpp:104
ScopedEventPrefix(std::string_view name)
Definition Event.cpp:62
contains profiling utilities.
static constexpr FundamentalTag Fundamental
Convenience instance of the FundamentalTag.
Definition Event.hpp:19
static constexpr bool isOptionsTag
Definition Event.hpp:25
static constexpr SynchronizeTag Synchronize
Convenience instance of the SynchronizeTag.
Definition Event.hpp:21
void handle(SynchronizeTag)
Definition Event.hpp:54
void handle(FundamentalTag)
Definition Event.hpp:50
Tag to annotate fundamental events.
Definition Event.hpp:11
Tag to annotate synchronized events.
Definition Event.hpp:15