Support selecting log level for profiler
This commit is contained in:
parent
d1960312e6
commit
005ae42d53
2 changed files with 9 additions and 8 deletions
|
|
@ -1,13 +1,14 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <psemek/util/clock.hpp>
|
#include <psemek/util/clock.hpp>
|
||||||
|
#include <psemek/log/level.hpp>
|
||||||
|
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
|
||||||
namespace psemek::prof
|
namespace psemek::prof
|
||||||
{
|
{
|
||||||
|
|
||||||
void dump();
|
void dump(log::level level = log::level::info);
|
||||||
|
|
||||||
struct profiler
|
struct profiler
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,7 @@ namespace psemek::prof
|
||||||
return os;
|
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;
|
std::size_t max_name_length = 0;
|
||||||
|
|
||||||
|
|
@ -107,11 +107,11 @@ namespace psemek::prof
|
||||||
auto const & c = *it;
|
auto const & c = *it;
|
||||||
auto const & stat = c.second.execution_time;
|
auto const & stat = c.second.execution_time;
|
||||||
if (stat.count() == 1)
|
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())
|
<< " " << pretty(stat.mean())
|
||||||
<< " (" << stat.count() << " call)";
|
<< " (" << stat.count() << " call)";
|
||||||
else if (node.execution_time.count() > 0)
|
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())
|
<< " avg " << pretty(stat.mean())
|
||||||
<< " 25% " << pretty(stat.percentile(0.25))
|
<< " 25% " << pretty(stat.percentile(0.25))
|
||||||
<< " 50% " << pretty(stat.percentile(0.50))
|
<< " 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, "
|
<< " (" << 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()) << "%)";
|
<< std::setprecision(2) << (100.f * stat.count() * stat.mean() / node.execution_time.mean() / node.execution_time.count()) << "%)";
|
||||||
else
|
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())
|
<< " avg " << pretty(stat.mean())
|
||||||
<< " 25% " << pretty(stat.percentile(0.25))
|
<< " 25% " << pretty(stat.percentile(0.25))
|
||||||
<< " 50% " << pretty(stat.percentile(0.50))
|
<< " 50% " << pretty(stat.percentile(0.50))
|
||||||
<< " 75% " << pretty(stat.percentile(0.75))
|
<< " 75% " << pretty(stat.percentile(0.75))
|
||||||
<< " (" << stat.count() << " calls)";
|
<< " (" << 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)
|
profiler::profiler(std::string const & name)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue