preCICE v3.3.0
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
20
23
25static constexpr Group API = Group::API;
26
28static constexpr SynchronizeTag Synchronize{};
29
30// Is the type a valid options tag?
31template <typename T>
33
40class Event {
41public:
42 enum class State : bool {
43 STOPPED = false,
44 RUNNING = true
45 };
46
49
52
53 struct Options {
54 bool synchronized = false;
55 bool fundamental = false;
57
58 void handle(Group g)
59 {
60 group = g;
61 }
63 {
64 synchronized = true;
65 }
66 };
67
68 template <typename... Args>
69 constexpr Options optionsFromTags(Args... args)
70 {
71 static_assert((isOptionsTag<Args> && ...), "The Event only accepts tags as arguments.");
72 Options options;
73 (options.handle(args), ...);
74 return options;
75 }
76
77 template <typename... Args>
78 Event(std::string_view eventName, Args... args)
79 : Event(eventName, optionsFromTags(args...))
80 {
81 }
82
83 Event(std::string_view eventName, Options options);
84
85 Event(Event &&) = default;
86 Event &operator=(Event &&) = default;
87
88 // Copies would lead to duplicate entries
89 Event(const Event &other) = delete;
90 Event &operator=(const Event &) = delete;
91
93 ~Event();
94
96 void start();
97
99 void stop();
100
102 void addData(std::string_view key, int value);
103
104private:
105 int _eid;
106 int _sid{-1};
109 bool _synchronize{false};
110};
111
112} // namespace precice::profiling
Event(std::string_view eventName, Args... args)
Definition Event.hpp:78
void start()
Starts or restarts a stopped event.
Definition Event.cpp:28
void stop()
Stops a running event.
Definition Event.cpp:51
Event & operator=(const Event &)=delete
constexpr Options optionsFromTags(Args... args)
Definition Event.hpp:69
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:51
Event(std::string_view eventName, Args... args)
Definition Event.hpp:78
std::chrono::steady_clock Clock
Default clock type. All other chrono types are derived from it.
Definition Event.hpp:48
~Event()
Stops the event if it's running and report its times to the EventRegistry.
Definition Event.cpp:21
Event(const Event &other)=delete
void addData(std::string_view key, int value)
Adds named integer data, associated to an event.
Definition Event.cpp:63
T is_same_v
contains profiling utilities.
static constexpr Group API
Convenience instance of the Cat::API.
Definition Event.hpp:25
static constexpr bool isOptionsTag
Definition Event.hpp:32
Group
Tag to annotate event group.
Definition Event.hpp:15
static constexpr SynchronizeTag Synchronize
Convenience instance of the SynchronizeTag.
Definition Event.hpp:28
static constexpr Group Fundamental
Convenience instance of the Cat::Fundamental.
Definition Event.hpp:22
void handle(SynchronizeTag)
Definition Event.hpp:62
Tag to annotate synchronized events.
Definition Event.hpp:11