Skip to content

Commit

Permalink
Fix #5369
Browse files Browse the repository at this point in the history
ScopedOnceTimer doesn't need no stinkin' hash
  • Loading branch information
ashdnazg committed Oct 21, 2016
1 parent d2c19e9 commit 3328bdf
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
21 changes: 20 additions & 1 deletion rts/System/TimeProfiler.cpp
Expand Up @@ -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);
}


Expand Down
12 changes: 9 additions & 3 deletions rts/System/TimeProfiler.h
Expand Up @@ -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;
};


Expand Down

0 comments on commit 3328bdf

Please sign in to comment.