Report profiler children in order of first call

This commit is contained in:
Nikita Lisitsa 2021-06-04 18:10:43 +03:00
parent 31c27ccfd3
commit 17722a1990

View file

@ -25,6 +25,18 @@ namespace psemek::util
statistics<double> execution_time;
std::map<std::string, profiler_tree> children;
std::vector<std::map<std::string, profiler_tree>::iterator> children_list;
profiler_tree * child(std::string const & name)
{
auto it = children.find(name);
if (it == children.end())
{
it = children.insert({name, profiler_tree{}}).first;
children_list.push_back(it);
}
return &(it->second);
}
};
static std::map<std::thread::id, profiler_tree> roots;
@ -73,11 +85,12 @@ namespace psemek::util
{
std::size_t max_name_length = 0;
for (auto const & c : node.children)
max_name_length = std::max(max_name_length, c.first.size());
for (auto it : node.children_list)
max_name_length = std::max(max_name_length, it->first.size());
for (auto const & c : node.children)
for (auto it : node.children_list)
{
auto const & c = *it;
auto const & stat = c.second.execution_time;
if (stat.count() == 1)
log::info() << std::string(depth * 2, ' ') << std::setw(max_name_length + 3) << std::left << std::setfill(' ') << c.first
@ -98,16 +111,17 @@ namespace psemek::util
{
t1.execution_time = merge(t1.execution_time, t2.execution_time);
for (auto const & p : t2.children)
for (auto it2 : t2.children_list)
{
auto it = t1.children.find(p.first);
if (it == t1.children.end())
auto it1 = t1.children.find(it2->first);
if (it1 == t1.children.end())
{
t1.children.insert(p);
it1 = t1.children.insert(*it2).first;
t1.children_list.push_back(it1);
}
else
{
it->second = merge(std::move(it->second), p.second);
it1->second = merge(std::move(it1->second), it2->second);
}
}
@ -150,7 +164,7 @@ namespace psemek::util
std::lock_guard lock{*(current->mutex)};
auto next = &current->children[name];
auto next = current->child(name);
next->parent = current;
next->mutex = current->mutex;
current = next;
@ -178,7 +192,7 @@ namespace psemek::util
std::lock_guard lock{*(current->mutex)};
auto child = &current->children[name];
auto child = current->child(name);
child->parent = current;
child->mutex = current->mutex;
child->execution_time.push(duration.count());