From 005ae42d53755b0dd8c33885dad19d99bdae22a6 Mon Sep 17 00:00:00 2001 From: lisyarus Date: Sun, 14 Aug 2022 23:15:21 +0300 Subject: [PATCH] Support selecting log level for profiler --- libs/prof/include/psemek/prof/profiler.hpp | 3 ++- libs/prof/source/profiler.cpp | 14 +++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/libs/prof/include/psemek/prof/profiler.hpp b/libs/prof/include/psemek/prof/profiler.hpp index 9df2db4f..46381a78 100644 --- a/libs/prof/include/psemek/prof/profiler.hpp +++ b/libs/prof/include/psemek/prof/profiler.hpp @@ -1,13 +1,14 @@ #pragma once #include +#include #include namespace psemek::prof { - void dump(); + void dump(log::level level = log::level::info); struct profiler { diff --git a/libs/prof/source/profiler.cpp b/libs/prof/source/profiler.cpp index bef78992..f7e87742 100644 --- a/libs/prof/source/profiler.cpp +++ b/libs/prof/source/profiler.cpp @@ -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)