preCICE v3.2.0
Loading...
Searching...
No Matches
Event.cpp
Go to the documentation of this file.
1#include "profiling/Event.hpp"
3#include "utils/IntraComm.hpp"
4#include "utils/assertion.hpp"
5
6namespace precice::profiling {
7
9 : _fundamental(options.fundamental), _synchronize(options.synchronized)
10{
11 auto &er = EventRegistry::instance();
12 auto name = std::string(eventName);
13 PRECICE_ASSERT(eventName.find('/') == std::string_view::npos);
14 _eid = er.nameToID(name);
15 if (_synchronize && er.parallel()) {
16 _sid = er.nameToID(name + ".sync");
17 }
18 start();
19}
20
22{
23 if (_state == State::RUNNING) {
24 stop();
25 }
26}
27
29{
32 auto &registry = EventRegistry::instance();
33 if (!registry.accepting(toEventClass(_fundamental))) {
34 return;
35 }
36
37 if (_synchronize && registry.parallel() && ::precice::utils::IntraComm::willSynchronize()) {
38 // We need to synchronize, so we record a sync event
39 PRECICE_ASSERT(_sid != -1);
40 registry.putCritical(StartEntry{_sid, Clock::now()});
42 // end of sync
43 auto timestamp = Clock::now();
44 registry.putCritical(StopEntry{_sid, timestamp});
45 registry.put(StartEntry{_eid, timestamp});
46 } else {
47 registry.put(StartEntry{_eid, Clock::now()});
48 }
49}
50
52{
53 auto timestamp = Clock::now();
56
59 }
60}
61
62void Event::addData(std::string_view key, int value)
63{
64 auto timestamp = Clock::now();
66
67 auto &er = EventRegistry::instance();
68 if (er.accepting(toEventClass(_fundamental))) {
69 auto did = er.nameToID(key);
70 er.put(DataEntry{_eid, timestamp, did, value});
71 }
72}
73
74} // namespace precice::profiling
#define PRECICE_ASSERT(...)
Definition assertion.hpp:85
static EventRegistry & instance()
Returns the only instance (singleton) of the EventRegistry class.
void put(PendingEntry pe)
Records an event.
void start()
Starts or restarts a stopped event.
Definition Event.cpp:28
void stop()
Stops a running event.
Definition Event.cpp:51
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:21
void addData(std::string_view key, int value)
Adds named integer data, associated to an event.
Definition Event.cpp:62
static bool willSynchronize()
T find(T... args)
contains profiling utilities.
EventClass toEventClass(bool isFundamental)