Pass string_view instead of string in profiler scopes
This commit is contained in:
parent
3bb8bd36f3
commit
3b89037c25
2 changed files with 11 additions and 11 deletions
|
|
@ -3,7 +3,7 @@
|
||||||
#include <psemek/util/clock.hpp>
|
#include <psemek/util/clock.hpp>
|
||||||
#include <psemek/log/level.hpp>
|
#include <psemek/log/level.hpp>
|
||||||
|
|
||||||
#include <string>
|
#include <string_view>
|
||||||
|
|
||||||
namespace psemek::prof
|
namespace psemek::prof
|
||||||
{
|
{
|
||||||
|
|
@ -12,7 +12,7 @@ namespace psemek::prof
|
||||||
|
|
||||||
struct profiler
|
struct profiler
|
||||||
{
|
{
|
||||||
profiler(std::string const & name);
|
profiler(std::string_view name);
|
||||||
profiler(profiler && other);
|
profiler(profiler && other);
|
||||||
profiler(profiler const & other) = delete;
|
profiler(profiler const & other) = delete;
|
||||||
|
|
||||||
|
|
@ -21,12 +21,12 @@ namespace psemek::prof
|
||||||
|
|
||||||
~profiler();
|
~profiler();
|
||||||
|
|
||||||
static void start_frame(std::string const & name);
|
static void start_frame(std::string_view name);
|
||||||
static void push(std::string const & name, std::chrono::duration<double> duration, std::size_t count = 1);
|
static void push(std::string_view name, std::chrono::duration<double> duration, std::size_t count = 1);
|
||||||
static void end_frame(std::chrono::duration<double> duration);
|
static void end_frame(std::chrono::duration<double> duration);
|
||||||
|
|
||||||
template <typename Duration>
|
template <typename Duration>
|
||||||
static void push(std::string const & name, Duration duration, std::size_t count = 1)
|
static void push(std::string_view name, Duration duration, std::size_t count = 1)
|
||||||
{
|
{
|
||||||
push(name, std::chrono::duration_cast<std::chrono::duration<double>>(duration), count);
|
push(name, std::chrono::duration_cast<std::chrono::duration<double>>(duration), count);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,15 +23,15 @@ namespace psemek::prof
|
||||||
|
|
||||||
util::statistics_log_bucket<double> execution_time{0.05};
|
util::statistics_log_bucket<double> execution_time{0.05};
|
||||||
|
|
||||||
std::map<std::string, profiler_tree> children;
|
std::map<std::string, profiler_tree, std::less<>> children;
|
||||||
std::vector<std::map<std::string, profiler_tree>::iterator> children_list;
|
std::vector<std::map<std::string, profiler_tree>::iterator> children_list;
|
||||||
|
|
||||||
profiler_tree * child(std::string const & name)
|
profiler_tree * child(std::string_view const & name)
|
||||||
{
|
{
|
||||||
auto it = children.find(name);
|
auto it = children.find(name);
|
||||||
if (it == children.end())
|
if (it == children.end())
|
||||||
{
|
{
|
||||||
it = children.insert({name, profiler_tree{}}).first;
|
it = children.insert({std::string(name), profiler_tree{}}).first;
|
||||||
it->second.parent = this;
|
it->second.parent = this;
|
||||||
it->second.mutex = mutex;
|
it->second.mutex = mutex;
|
||||||
children_list.push_back(it);
|
children_list.push_back(it);
|
||||||
|
|
@ -174,7 +174,7 @@ namespace psemek::prof
|
||||||
dump_impl(merged_tree(), 0, level);
|
dump_impl(merged_tree(), 0, level);
|
||||||
}
|
}
|
||||||
|
|
||||||
profiler::profiler(std::string const & name)
|
profiler::profiler(std::string_view name)
|
||||||
{
|
{
|
||||||
get_current();
|
get_current();
|
||||||
|
|
||||||
|
|
@ -204,7 +204,7 @@ namespace psemek::prof
|
||||||
report();
|
report();
|
||||||
}
|
}
|
||||||
|
|
||||||
void profiler::start_frame(std::string const & name)
|
void profiler::start_frame(std::string_view name)
|
||||||
{
|
{
|
||||||
get_current();
|
get_current();
|
||||||
|
|
||||||
|
|
@ -212,7 +212,7 @@ namespace psemek::prof
|
||||||
current = current->child(name);
|
current = current->child(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void profiler::push(std::string const & name, std::chrono::duration<double> duration, std::size_t count)
|
void profiler::push(std::string_view name, std::chrono::duration<double> duration, std::size_t count)
|
||||||
{
|
{
|
||||||
get_current();
|
get_current();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue