MCPcopy Create free account
hub / github.com/NatLabRockies/OpenStudio / timeReport

Method timeReport

src/workflow/Timer.cpp:82–116  ·  view source on GitHub ↗

line_length is the maximum terminal width, fit = true will cause the table to be resized down as much as possible, fit = false means the table will take exactly line_length

Source from the content-addressed store, hash-verified

80
81// line_length is the maximum terminal width, fit = true will cause the table to be resized down as much as possible, fit = false means the table will take exactly line_length
82std::string TimerCollection::timeReport(int line_length, bool fit) const {
83 // Timer | start | end | duration
84 std::string result;
85
86 constexpr size_t timepoint_len = 8; // 19 if not specifying %T
87 constexpr size_t duration_len = 10;
88 constexpr size_t ncols = 4;
89 constexpr size_t extra_chars = 3 * (ncols - 1) + 2 * (ncols - 2);
90 size_t message_len = line_length - (2 * timepoint_len + duration_len + extra_chars);
91 if (fit) {
92 size_t max_message_len = 0;
93 for (const auto& timer : m_timers) {
94 max_message_len = std::max(max_message_len, timer.message().size());
95 }
96 message_len = std::min(message_len, max_message_len + 4);
97 // fmt::print("line_length={}, message_len={}, max_message_len={}\n", line_length, message_len, max_message_len);
98 }
99
100 // Use │ or | ?
101 // result += fmt::format("┌{0:─^{1}}┐\n", "", total_len - 2);
102 result +=
103 fmt::format("| {3:^{0}} | {4:^{1}} | {5:^{1}} | {6:^{2}} |\n", message_len, timepoint_len, duration_len, "Timer", "start", "end", "duration");
104 // result += fmt::format("|{0:─^{1}}|\n", "", total_len - 2);
105 result += fmt::format("|:{3:-^{0}}|:{3:-^{1}}:|:{3:-^{1}}:|:{3:-^{2}}:|\n", message_len + 1, timepoint_len, duration_len, "");
106
107 for (const auto& timer : m_timers) {
108 result += timer.formatRow(message_len, timepoint_len, duration_len);
109 }
110
111 m_totalTimer.tock();
112 result += fmt::format(fmt::fg(fmt::color::red), "| {3:^{0}.{0}s} | {4:%T} | {5:%T} | {6:^{2}} |\n", message_len, timepoint_len, duration_len,
113 m_totalTimer.message(), m_totalTimer.start(), m_totalTimer.end(), m_totalTimer.duration());
114
115 return result;
116};
117
118} // namespace openstudio::workflow::util

Callers 1

runMethod · 0.80

Calls 7

messageMethod · 0.80
formatRowMethod · 0.80
tockMethod · 0.80
sizeMethod · 0.45
startMethod · 0.45
endMethod · 0.45
durationMethod · 0.45

Tested by

no test coverage detected