From 3328bdfc1c0cae4dc6524b9bd03509f446a4fb9f Mon Sep 17 00:00:00 2001 From: Eshed Date: Sat, 22 Oct 2016 00:05:13 +0300 Subject: [PATCH] Fix #5369 ScopedOnceTimer doesn't need no stinkin' hash --- rts/System/TimeProfiler.cpp | 21 ++++++++++++++++++++- rts/System/TimeProfiler.h | 12 +++++++++--- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/rts/System/TimeProfiler.cpp b/rts/System/TimeProfiler.cpp index e09b6c7980b..e10226c0c36 100644 --- a/rts/System/TimeProfiler.cpp +++ b/rts/System/TimeProfiler.cpp @@ -127,10 +127,29 @@ ScopedTimer::~ScopedTimer() profiler.AddTime(GetName(), GetDuration(), autoShowGraph); } +ScopedOnceTimer::ScopedOnceTimer(const char* name_) + : starttime(spring_gettime()) + , name(name_) +{ } + +ScopedOnceTimer::ScopedOnceTimer(const std::string& name_) + : starttime(spring_gettime()) + , name(name_) +{ } + +const std::string& ScopedOnceTimer::GetName() const +{ + return name; +} + +spring_time ScopedOnceTimer::GetDuration() const +{ + return spring_difftime(spring_gettime(), starttime); +} + ScopedOnceTimer::~ScopedOnceTimer() { LOG("%s: %i ms", GetName().c_str(), int(GetDuration().toMilliSecsi())); - hashToName.erase(nameIterator); } diff --git a/rts/System/TimeProfiler.h b/rts/System/TimeProfiler.h index ca20f4322fe..d246b8ae265 100644 --- a/rts/System/TimeProfiler.h +++ b/rts/System/TimeProfiler.h @@ -71,12 +71,18 @@ class ScopedMtTimer : public BasicTimer /** * @brief print passed time to infolog */ -class ScopedOnceTimer : public BasicTimer +class ScopedOnceTimer { public: - ScopedOnceTimer(const std::string& name): BasicTimer(name) {} - ScopedOnceTimer(const char* name): BasicTimer(name) {} + ScopedOnceTimer(const std::string& name); + ScopedOnceTimer(const char* name); ~ScopedOnceTimer(); + const std::string& GetName() const; + spring_time GetDuration() const; + +protected: + const spring_time starttime; + std::string name; };