16 const std::string& parent_name )
19 "TimingBlock with name \"" + name +
22 auto block_ptr = std::make_unique<TimingBlock>(name);
23 auto saved_pointer = &(*block_ptr);
26 if (parent_name.empty())
28 if (name !=
"ChiTech")
33 "Bad error, could not fine the \"ChiTech\" timing block");
35 iter->second->AddChild(*saved_pointer);
38 return *saved_pointer;
44 "Parent name \"" + parent_name +
"\" does not exist.");
46 auto& parent = iter->second;
47 parent->AddChild(*saved_pointer);
49 return *saved_pointer;
54 const std::string& parent_name )
68 "Timing block with name \"" + name +
69 "\" does not exist.");
116 std::vector<std::vector<std::string>> string_matrix;
121 const size_t I = string_matrix.size();
123 std::vector<size_t> max_col_widths(J, 0);
124 for (
size_t i = 0; i < I; ++i)
125 for (
size_t j = 0; j < J; ++j)
127 std::max(max_col_widths[j], string_matrix[i][j].size());
129 std::vector<std::string> headers = {
"Section Name",
135 for (
size_t j = 0; j < J; ++j)
136 max_col_widths[j] = std::max(max_col_widths[j], headers[j].size());
139 auto LeftPad = [](std::string& entry,
size_t width)
141 const size_t pad_size = width - entry.size();
142 entry = std::string(pad_size,
' ').append(entry);
145 auto RightPad = [](std::string& entry,
size_t width)
147 const size_t pad_size = width - entry.size();
148 entry.append(std::string(pad_size,
' '));
151 std::stringstream outstr;
153 auto HDIV = [&outstr, &max_col_widths]()
156 for (
size_t j = 0; j < J; ++j)
158 outstr << std::string(max_col_widths[j] + 1,
'-');
159 if (j < (J - 1)) outstr <<
"*-";
167 for (
size_t j = 0; j < J; ++j)
169 if (j == 0) RightPad(headers[j], max_col_widths[j]);
171 LeftPad(headers[j], max_col_widths[j] + 1);
172 outstr << headers[j] <<
" |";
178 for (
size_t i = 0; i < I; ++i)
181 for (
size_t j = 0; j < J; ++j)
183 if (j == 0) RightPad(string_matrix[i][j], max_col_widths[j]);
185 LeftPad(string_matrix[i][j], max_col_widths[j] + 1);
186 outstr << string_matrix[i][j] <<
" |";
198 std::vector<std::vector<std::string>>& string_matrix,
200 const std::string& indent)
const
202 std::vector<std::string> entry;
204 const double parent_total_time = parent ? parent->
TotalTime() : 0.0;
205 const double relative_time =
206 parent_total_time > 1.0e-12 ?
total_time_ * 100.0 / parent_total_time : 0.0;
208 entry.push_back(indent +
name_);
214 "Failed to convert total_time = " +
216 entry.push_back(buffer);
222 "Failed to convert AverageTime = " +
224 entry.push_back(buffer);
230 "Failed to convert relative_time = " +
231 std::to_string(relative_time));
232 entry.push_back(parent ? buffer :
"--");
235 string_matrix.push_back(std::move(entry));
238 child_ptr->AppendGraphEntry(string_matrix,
this, indent +
" ");
#define ChiLogicalErrorIf(condition, message)
#define ChiInvalidArgumentIf(condition, message)
static chi::Timer program_timer
void AppendGraphEntry(std::vector< std::vector< std::string > > &string_matrix, const TimingBlock *parent, const std::string &indent) const
TimingBlock(const std::string &name)
void AddChild(const TimingBlock &child_block)
double AverageTime() const
size_t NumberOfOccurences() const
std::vector< const TimingBlock * > children_
std::string MakeGraphString()
std::map< std::string, std::unique_ptr< TimingBlock > > timing_blocks_
TimingBlock & CreateTimingBlock(const std::string &name, const std::string &parent_name="")
TimingBlock & CreateOrGetTimingBlock(const std::string &name, const std::string &parent_name="")
TimingBlock & GetTimingBlock(const std::string &name)