Support adding externally-measured profiling data to util::profiler
This commit is contained in:
parent
375732609b
commit
31c27ccfd3
2 changed files with 26 additions and 0 deletions
|
|
@ -14,6 +14,13 @@ namespace psemek::util
|
||||||
~ profiler();
|
~ profiler();
|
||||||
|
|
||||||
static void dump();
|
static void dump();
|
||||||
|
static void push(std::string const & name, std::chrono::duration<double> duration);
|
||||||
|
|
||||||
|
template <typename Duration>
|
||||||
|
static void push(std::string const & name, Duration duration)
|
||||||
|
{
|
||||||
|
push(name, std::chrono::duration_cast<std::chrono::duration<double>>(duration));
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
util::clock<std::chrono::duration<double>, std::chrono::high_resolution_clock> clock_;
|
util::clock<std::chrono::duration<double>, std::chrono::high_resolution_clock> clock_;
|
||||||
|
|
|
||||||
|
|
@ -165,6 +165,25 @@ namespace psemek::util
|
||||||
current = current->parent;
|
current = current->parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void profiler::push(std::string const & name, std::chrono::duration<double> duration)
|
||||||
|
{
|
||||||
|
auto const id = std::this_thread::get_id();
|
||||||
|
|
||||||
|
if (!current)
|
||||||
|
{
|
||||||
|
std::lock_guard lock{roots_mutex};
|
||||||
|
current = &roots[id];
|
||||||
|
current->mutex = &thread_mutex[id];
|
||||||
|
}
|
||||||
|
|
||||||
|
std::lock_guard lock{*(current->mutex)};
|
||||||
|
|
||||||
|
auto child = ¤t->children[name];
|
||||||
|
child->parent = current;
|
||||||
|
child->mutex = current->mutex;
|
||||||
|
child->execution_time.push(duration.count());
|
||||||
|
}
|
||||||
|
|
||||||
void profiler::dump()
|
void profiler::dump()
|
||||||
{
|
{
|
||||||
dump_impl(merged_tree(), 0);
|
dump_impl(merged_tree(), 0);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue