X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fprofiler.h;h=78d3b08e06493052362b3d443d946e72d7832a23;hb=0c792db05c9e53a2e5dd7f6462f8aaa561fde858;hp=5816f05ca66652960034708e4bc60c58fcdcb0ef;hpb=5c55738276bb6875c3f2d4702b7fd08c45e8a29c;p=dragonfireclient.git diff --git a/src/profiler.h b/src/profiler.h index 5816f05ca..78d3b08e0 100644 --- a/src/profiler.h +++ b/src/profiler.h @@ -27,11 +27,15 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "jthread/jmutex.h" #include "jthread/jmutexautolock.h" #include "util/timetaker.h" -#include "util/numeric.h" // paging() -#include "debug.h" // assert() +#include "util/numeric.h" // paging() +#include "debug.h" // assert() #define MAX_PROFILER_TEXT_ROWS 20 +// Global profiler +class Profiler; +extern Profiler *g_profiler; + /* Time profiler */ @@ -69,23 +73,11 @@ class Profiler void avg(const std::string &name, float value) { JMutexAutoLock lock(m_mutex); - { - std::map::iterator n = m_avgcounts.find(name); - if(n == m_avgcounts.end()) - m_avgcounts[name] = 1; - else{ - /* No add shall have been used */ - assert(n->second != -2); - n->second = MYMAX(n->second, 0) + 1; - } - } - { - std::map::iterator n = m_data.find(name); - if(n == m_data.end()) - m_data[name] = value; - else - n->second += value; - } + int &count = m_avgcounts[name]; + + assert(count != -2); + count = MYMAX(count, 0) + 1; + m_data[name] += value; } void clear() @@ -105,6 +97,21 @@ class Profiler printPage(o, 1, 1); } + float getValue(const std::string &name) const + { + std::map::const_iterator numerator = m_data.find(name); + if (numerator == m_data.end()) + return 0.f; + + std::map::const_iterator denominator = m_avgcounts.find(name); + if (denominator != m_avgcounts.end()){ + if (denominator->second >= 1) + return numerator->second / denominator->second; + } + + return numerator->second; + } + void printPage(std::ostream &o, u32 page, u32 pagecount) { JMutexAutoLock lock(m_mutex);