preCICE v3.3.0
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_API) {
25 } else if (mode == MODE_ALL) {
27 } else {
28 PRECICE_UNREACHABLE("Unknown mode \"{}\"", mode);
29 }
30}
31} // namespace
32
34{
35 using namespace xml;
36
37 XMLTag tag(*this, "profiling", XMLTag::OCCUR_NOT_OR_ONCE);
38 tag.setDocumentation("Allows configuring the profiling functionality of preCICE.");
39
40 auto attrMode = makeXMLAttribute<std::string>("mode", DEFAULT_MODE)
42 .setDocumentation("Operational modes of the profiling. "
43 "\"fundamental\" will only write fundamental steering events. "
44 "\"api\" will write events of the complete API. "
45 "\"all\" writes all events.");
46 tag.addAttribute(attrMode);
47
48 auto attrFlush = makeXMLAttribute<int>("flush-every", DEFAULT_SYNC_EVERY)
49 .setDocumentation("Set the amount of event records that should be kept in memory before flushing them to file. "
50 "One event consists out of multiple records. "
51 "0 keeps all records in memory and writes them at the end of the program, useful for slower network filesystems. "
52 "1 writes records directly to the file, useful to get profiling data despite program crashes. "
53 "Settings greater than 1 keep records in memory and write them to file in blocks, which is recommended.");
54 tag.addAttribute(attrFlush);
55
56 auto attrDirectory = makeXMLAttribute<std::string>("directory", DEFAULT_DIRECTORY)
57 .setDocumentation("Directory to use as a root directory to write the events to. "
58 "Events will be written to `<directory>/precice-profiling/`");
59 tag.addAttribute(attrDirectory);
60
61 auto attrSynchronize = xml::makeXMLAttribute("synchronize", false)
62 .setDocumentation("Enables additional inter- and intra-participant synchronization points. "
63 "This avoids measuring blocking time for communication and other collective operations.");
64 tag.addAttribute(attrSynchronize);
65
66 parent.addSubtag(tag);
67}
68
70 const xml::ConfigurationContext &context,
71 xml::XMLTag &tag)
72{
74 auto mode = tag.getStringAttributeValue("mode");
75 auto flushEvery = tag.getIntAttributeValue("flush-every");
76 auto directory = std::filesystem::path(tag.getStringAttributeValue("directory"));
77 PRECICE_CHECK(flushEvery >= 0, "You configured the profiling to flush-every=\"{}\", which is invalid. "
78 "Please choose a number >= 0.");
79
80 using namespace precice;
82
83 er.setWriteQueueMax(flushEvery);
84
85 directory /= "precice-profiling";
86 er.setDirectory(directory.string());
87
88 er.setMode(fromString(mode));
89}
90
92{
93 precice::syncMode = false;
95
96 er.setWriteQueueMax(DEFAULT_SYNC_EVERY);
97
99 directory /= "precice-profiling";
100 er.setDirectory(directory.string());
101
102 er.setMode(fromString(DEFAULT_MODE));
103}
104
105} // namespace precice::profiling
#define PRECICE_CHECK(check,...)
Definition LogMacros.hpp:32
#define PRECICE_UNREACHABLE(...)
Definition assertion.hpp:93
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.
Represents an XML tag to be configured automatically.
Definition XMLTag.hpp:28
std::string getStringAttributeValue(const std::string &name, std::optional< std::string > default_value=std::nullopt) const
Definition XMLTag.cpp:145
bool getBooleanAttributeValue(const std::string &name, std::optional< bool > default_value=std::nullopt) const
Definition XMLTag.cpp:159
int getIntAttributeValue(const std::string &name, std::optional< int > default_value=std::nullopt) const
Definition XMLTag.cpp:131
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 * MODE_API
constexpr const char * DEFAULT_MODE
contains the XML configuration parser.
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:21