23 std::string memory_usage_event(
"Maximum Memory Usage");
24 repeating_events.emplace_back(memory_usage_event);
29 EventType::EVENT_CREATED,
30 std::make_shared<EventInfo>());
44 std::string header =
"[" + std::to_string(
Chi::mpi.location_id) +
"] ";
45 return {&std::cout, header};
49 std::string header =
" ";
50 return {&dummy_stream_, header,
true};
57 std::string header =
"[" + std::to_string(
Chi::mpi.location_id) +
"] ";
59 return {&std::cout, header};
63 std::string header =
" ";
64 return {&dummy_stream_, header,
true};
71 std::string header =
"[" + std::to_string(
Chi::mpi.location_id) +
"] ";
73 return {&std::cerr, header};
77 std::string header =
" ";
78 return {&dummy_stream_, header,
true};
84 if ((
Chi::mpi.location_id == 0) && (verbosity_ >= 1))
86 std::string header =
"[" + std::to_string(
Chi::mpi.location_id) +
"] ";
88 return {&std::cout, header};
92 std::string header =
" ";
93 return {&dummy_stream_, header,
true};
96 case ChiLog::LOG_LVL::LOG_0VERBOSE_2:
98 if ((
Chi::mpi.location_id == 0) && (verbosity_ >= 2))
100 std::string header =
"[" + std::to_string(
Chi::mpi.location_id) +
"] ";
102 return {&std::cout, header};
106 std::string header =
" ";
107 return {&dummy_stream_, header,
true};
110 case LOG_ALLVERBOSE_0:
113 std::string header =
"[" + std::to_string(
Chi::mpi.location_id) +
"] ";
114 return {&std::cout, header};
118 std::string header =
"[" + std::to_string(
Chi::mpi.location_id) +
"] ";
120 return {&std::cout, header};
124 std::string header =
"[" + std::to_string(
Chi::mpi.location_id) +
"] ";
126 return {&std::cerr, header};
129 case LOG_ALLVERBOSE_1:
133 std::string header =
"[" + std::to_string(
Chi::mpi.location_id) +
"] ";
135 return {&std::cout, header};
139 std::string header =
" ";
140 return {&dummy_stream_, header,
true};
143 case LOG_ALLVERBOSE_2:
147 std::string header =
"[" + std::to_string(
Chi::mpi.location_id) +
"] ";
149 return {&std::cout, header};
153 std::string header =
" ";
154 return {&dummy_stream_, header,
true};
158 std::string header =
" ";
159 return {&dummy_stream_, header};
167 verbosity_ = std::min(int_level, 2);
178 repeating_events.emplace_back(event_name);
183 EventType::EVENT_CREATED,
184 std::make_shared<EventInfo>());
186 return repeating_events.size() - 1;
193 const size_t num_rep_events = repeating_events.size();
194 for (
size_t k=num_rep_events-1; k!=0; --k)
195 if (repeating_events[k].Name() == event_name)
206 const std::shared_ptr<EventInfo>& ev_info)
208 if (ev_tag >= repeating_events.size())
return;
212 ref_rep_event.
Events().emplace_back(
220 if (ev_tag >= repeating_events.size())
return;
224 ref_rep_event.
Events().emplace_back(
236 std::stringstream outstr;
237 if (ev_tag >= repeating_events.size())
return outstr.str();
241 for (
auto& event : ref_rep_event.
Events())
246 snprintf(buf, 100,
"%16.9f", event.ev_time / 1000.0);
247 outstr << buf <<
" ";
249 switch (event.ev_type)
251 case EventType::EVENT_CREATED:
252 outstr <<
"EVENT_CREATED ";
254 case EventType::SINGLE_OCCURRENCE:
255 outstr <<
"SINGLE_OCCURRENCE ";
257 case EventType::EVENT_BEGIN:
258 outstr <<
"EVENT_BEGIN ";
260 case EventType::EVENT_END:
261 outstr <<
"EVENT_END ";
265 if (event.ev_info !=
nullptr) outstr <<
event.ev_info->GetString();
278 if (ev_tag >= repeating_events.size())
return 0.0;
282 double ret_val = 0.0;
283 switch (ev_operation)
285 case EventOperation::NUMBER_OF_OCCURRENCES:
287 for (
auto& event : ref_rep_event.
Events())
289 if ((event.ev_type == EventType::EVENT_CREATED) or
290 (event.ev_type == EventType::SINGLE_OCCURRENCE) or
291 (event.ev_type == EventType::EVENT_BEGIN))
296 case EventOperation::TOTAL_DURATION:
298 double start_time = 0.0;
299 for (
auto& event : ref_rep_event.
Events())
301 if (event.ev_type == EventType::EVENT_BEGIN) start_time =
event.ev_time;
302 if (event.ev_type == EventType::EVENT_END)
303 ret_val +=
event.ev_time - start_time;
308 case EventOperation::AVERAGE_DURATION:
310 double start_time = 0.0;
312 for (
auto& event : ref_rep_event.
Events())
314 if (event.ev_type == EventType::EVENT_BEGIN) start_time =
event.ev_time;
316 if (event.ev_type == EventType::EVENT_END)
318 ret_val +=
event.ev_time - start_time;
322 ret_val /= (1000.0 * counter);
325 case EventOperation::MAX_VALUE:
328 for (
auto& event : ref_rep_event.
Events())
330 if ((event.ev_type == EventType::SINGLE_OCCURRENCE) or
331 (event.ev_type == EventType::EVENT_BEGIN) or
332 (event.ev_type == EventType::EVENT_END))
334 if (event.ev_info !=
nullptr)
335 ret_val = std::max(event.ev_info->arb_value, ret_val);
340 case EventOperation::AVERAGE_VALUE:
344 for (
auto& event : ref_rep_event.
Events())
346 if ((event.ev_type == EventType::SINGLE_OCCURRENCE) or
347 (event.ev_type == EventType::EVENT_BEGIN) or
348 (event.ev_type == EventType::EVENT_END))
350 if (event.ev_info !=
nullptr)
352 ret_val +=
event.ev_info->arb_value;
357 if (count == 0) count = 1;
#define ChiLogicalError(message)
static chi::Timer program_timer
static chi::MPI_Info & mpi
std::vector< Event > & Events()
double ProcessEvent(size_t ev_tag, EventOperation ev_operation)
void SetVerbosity(int int_level)
size_t GetExistingRepeatingEventTag(std::string event_name)
static ChiLog & GetInstance() noexcept
std::string PrintEventHistory(size_t ev_tag)
LogStream Log(LOG_LVL level=LOG_0)
size_t GetRepeatingEventTag(std::string event_name)
void LogEvent(size_t ev_tag, EventType ev_type, const std::shared_ptr< EventInfo > &ev_info)
const int & location_id
Current process rank.
std::string StringStreamColor(StringSteamColorCode code)