preCICE v3.1.2
Loading...
Searching...
No Matches
ProfilingConfiguration.cpp
Go to the documentation of this file.
2#include <cstdlib>
3#include <filesystem>
4#include <string_view>
7#include "utils/assertion.hpp"
10#include "xml/XMLTag.hpp"
11
12bool precice::syncMode = false;
13
14namespace precice::profiling {
15
16namespace {
17profiling::Mode fromString(std::string_view mode)
18{
19 if (mode == MODE_OFF) {
21 } else if (mode == MODE_FUNDAMENTAL) {
23 } else if (mode == MODE_ALL) {
25 } else {
26 PRECICE_UNREACHABLE("Unknown mode \"{}\"", mode);
27 }
28}
29} // namespace
30
32{
33 using namespace xml;
34
35 XMLTag tag(*this, "profiling", XMLTag::OCCUR_NOT_OR_ONCE);
36 tag.setDocumentation("Allows configuring the profiling functionality of preCICE.");
37
38 auto attrMode = makeXMLAttribute<std::string>("mode", DEFAULT_MODE)
39 .setOptions({MODE_ALL, MODE_FUNDAMENTAL, MODE_OFF})
40 .setDocumentation("Operational modes of the profiling. "
41 "\"fundamental\" will only write fundamental events. "
42 "\"all\" writes all events.");
43 tag.addAttribute(attrMode);
44
45 auto attrFlush = makeXMLAttribute<int>("flush-every", DEFAULT_SYNC_EVERY)
46 .setDocumentation("Set the amount of event records that should be kept in memory before flushing them to file. "
47 "One event consists out of multiple records."
48 "0 keeps all records in memory and writes them at the end of the program, useful for slower network filesystems. "
49 "1 writes records directly to the file, useful to get profiling data despite program crashes. "
50 "Settings greater than 1 keep records in memory and write them to file in blocks, which is recommended.");
51 tag.addAttribute(attrFlush);
52
53 auto attrDirectory = makeXMLAttribute<std::string>("directory", DEFAULT_DIRECTORY)
54 .setDocumentation("Directory to use as a root directory to write the events to. "
55 "Events will be written to `<directory>/precice-profiling/`");
56 tag.addAttribute(attrDirectory);
57
58 auto attrSynchronize = xml::makeXMLAttribute("synchronize", false)
59 .setDocumentation("Enables additional inter- and intra-participant synchronization points. "
60 "This avoids measuring blocking time for communication and other collective operations.");
61 tag.addAttribute(attrSynchronize);
62
63 parent.addSubtag(tag);
64}
65
67 const xml::ConfigurationContext &context,
68 xml::XMLTag & tag)
69{
71 auto mode = tag.getStringAttributeValue("mode");
72 auto flushEvery = tag.getIntAttributeValue("flush-every");
73 auto directory = std::filesystem::path(tag.getStringAttributeValue("directory"));
74 PRECICE_CHECK(flushEvery >= 0, "You configured the profiling to flush-every=\"{}\", which is invalid. "
75 "Please choose a number >= 0.");
76
77 using namespace precice;
79
80 er.setWriteQueueMax(flushEvery);
81
82 directory /= "precice-profiling";
83 er.setDirectory(directory.string());
84
85 er.setMode(fromString(mode));
86}
87
89{
90 precice::syncMode = false;
92
93 er.setWriteQueueMax(DEFAULT_SYNC_EVERY);
94
96 directory /= "precice-profiling";
97 er.setDirectory(directory.string());
98
99 er.setMode(fromString(DEFAULT_MODE));
100}
101
102} // namespace precice::profiling
#define PRECICE_CHECK(check,...)
Definition LogMacros.hpp:35
#define PRECICE_UNREACHABLE(...)
Definition assertion.hpp:95
static EventRegistry & instance()
Returns the only instance (singleton) of the EventRegistry class.
void xmlTagCallback(const xml::ConfigurationContext &context, xml::XMLTag &callingTag) override
Callback at begin of XML tag.
XMLAttribute & setDocumentation(std::string documentation)
Sets a documentation string for the attribute.
Represents an XML tag to be configured automatically.
Definition XMLTag.hpp:31
std::string getStringAttributeValue(const std::string &name, std::optional< std::string > default_value=std::nullopt) const
Definition XMLTag.cpp:142
bool getBooleanAttributeValue(const std::string &name, std::optional< bool > default_value=std::nullopt) const
Definition XMLTag.cpp:155
int getIntAttributeValue(const std::string &name, std::optional< int > default_value=std::nullopt) const
Definition XMLTag.cpp:129
XMLTag & addSubtag(const XMLTag &tag)
Adds an XML tag as subtag by making a copy of the given tag.
Definition XMLTag.cpp:41
contains profiling utilities.
constexpr const char * DEFAULT_DIRECTORY
constexpr const char * MODE_ALL
constexpr const char * MODE_OFF
Mode
The Mode of the Event utility.
constexpr const char * MODE_FUNDAMENTAL
constexpr const char * DEFAULT_MODE
XMLAttribute< std::string > makeXMLAttribute(std::string name, const char *defaultValue)
Main namespace of the precice library.
bool syncMode
Enabled further inter- and intra-solver synchronisation.
Tightly coupled to the parameters of Participant()
Definition XMLTag.hpp:24