Support selecting log level for profiler

This commit is contained in:
Nikita Lisitsa 2022-08-14 23:15:21 +03:00
parent d1960312e6
commit 005ae42d53
2 changed files with 9 additions and 8 deletions

View file

@ -1,13 +1,14 @@
#pragma once
#include <psemek/util/clock.hpp>
#include <psemek/log/level.hpp>
#include <string_view>
namespace psemek::prof
{
void dump();
void dump(log::level level = log::level::info);
struct profiler
{

View file

@ -95,7 +95,7 @@ namespace psemek::prof
return os;
}
void dump_impl(profiler_tree const & node, std::size_t depth)
void dump_impl(profiler_tree const & node, std::size_t depth, log::level level)
{
std::size_t max_name_length = 0;
@ -107,11 +107,11 @@ namespace psemek::prof
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
log::log(level) << std::string(depth * 2, ' ') << std::setw(max_name_length + 3) << std::left << std::setfill(' ') << c.first
<< " " << pretty(stat.mean())
<< " (" << stat.count() << " call)";
else if (node.execution_time.count() > 0)
log::info() << std::string(depth * 2, ' ') << std::setw(max_name_length + 3) << std::left << std::setfill(' ') << c.first
log::log(level) << std::string(depth * 2, ' ') << std::setw(max_name_length + 3) << std::left << std::setfill(' ') << c.first
<< " avg " << pretty(stat.mean())
<< " 25% " << pretty(stat.percentile(0.25))
<< " 50% " << pretty(stat.percentile(0.50))
@ -119,13 +119,13 @@ namespace psemek::prof
<< " (" << stat.count() << " calls, " << std::setprecision(3) << (stat.count() * 1.f / node.execution_time.count() * 1.f) << "x, "
<< std::setprecision(2) << (100.f * stat.count() * stat.mean() / node.execution_time.mean() / node.execution_time.count()) << "%)";
else
log::info() << std::string(depth * 2, ' ') << std::setw(max_name_length + 3) << std::left << std::setfill(' ') << c.first
log::log(level) << std::string(depth * 2, ' ') << std::setw(max_name_length + 3) << std::left << std::setfill(' ') << c.first
<< " avg " << pretty(stat.mean())
<< " 25% " << pretty(stat.percentile(0.25))
<< " 50% " << pretty(stat.percentile(0.50))
<< " 75% " << pretty(stat.percentile(0.75))
<< " (" << stat.count() << " calls)";
dump_impl(c.second, depth + 1);
dump_impl(c.second, depth + 1, level);
}
}
@ -170,9 +170,9 @@ namespace psemek::prof
}
void dump()
void dump(log::level level)
{
dump_impl(merged_tree(), 0);
dump_impl(merged_tree(), 0, level);
}
profiler::profiler(std::string const & name)