Support move operations in prof::profiler
This commit is contained in:
parent
6a8563cce9
commit
c75809aa75
2 changed files with 38 additions and 6 deletions
|
|
@ -3,7 +3,7 @@
|
|||
#include <psemek/util/clock.hpp>
|
||||
#include <psemek/log/level.hpp>
|
||||
|
||||
#include <string_view>
|
||||
#include <string>
|
||||
|
||||
namespace psemek::prof
|
||||
{
|
||||
|
|
@ -13,8 +13,13 @@ namespace psemek::prof
|
|||
struct profiler
|
||||
{
|
||||
profiler(std::string const & name);
|
||||
profiler(profiler && other);
|
||||
profiler(profiler const & other) = delete;
|
||||
|
||||
~ profiler();
|
||||
profiler & operator = (profiler && other);
|
||||
profiler & operator = (profiler const & other) = delete;
|
||||
|
||||
~profiler();
|
||||
|
||||
static void start_frame(std::string const & name);
|
||||
static void push(std::string const & name, std::chrono::duration<double> duration, std::size_t count = 1);
|
||||
|
|
@ -33,6 +38,9 @@ namespace psemek::prof
|
|||
|
||||
private:
|
||||
util::clock<std::chrono::duration<double>, std::chrono::high_resolution_clock> clock_;
|
||||
bool moved_out_ = false;
|
||||
|
||||
void report();
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -183,12 +183,25 @@ namespace psemek::prof
|
|||
clock_.restart();
|
||||
}
|
||||
|
||||
profiler::profiler(profiler && other)
|
||||
: clock_(other.clock_)
|
||||
, moved_out_(other.moved_out_)
|
||||
{
|
||||
other.moved_out_ = true;
|
||||
}
|
||||
|
||||
profiler & profiler::operator = (profiler && other)
|
||||
{
|
||||
report();
|
||||
clock_ = other.clock_;
|
||||
moved_out_ = other.moved_out_;
|
||||
other.moved_out_ = true;
|
||||
return *this;
|
||||
}
|
||||
|
||||
profiler::~profiler()
|
||||
{
|
||||
auto count = clock_.count();
|
||||
std::lock_guard lock{*(current->mutex)};
|
||||
current->execution_time.push(count);
|
||||
current = current->parent;
|
||||
report();
|
||||
}
|
||||
|
||||
void profiler::start_frame(std::string const & name)
|
||||
|
|
@ -214,4 +227,15 @@ namespace psemek::prof
|
|||
current = current->parent;
|
||||
}
|
||||
|
||||
void profiler::report()
|
||||
{
|
||||
if (moved_out_)
|
||||
return;
|
||||
|
||||
auto count = clock_.count();
|
||||
std::lock_guard lock{*(current->mutex)};
|
||||
current->execution_time.push(count);
|
||||
current = current->parent;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue