X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fprofiler.h;h=b4a0657f980f154aabbca6e83aaa4fb73e000344;hb=68f9263a24a345435d2310ab559ce8a811ef0427;hp=cade887e8465a94e3ef85d09fd90c1573431e8a4;hpb=4faaadc8d50d6ab7a19d22bd5a760c4b8321a51f;p=dragonfireclient.git diff --git a/src/profiler.h b/src/profiler.h index cade887e8..b4a0657f9 100644 --- a/src/profiler.h +++ b/src/profiler.h @@ -17,19 +17,17 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#ifndef PROFILER_HEADER -#define PROFILER_HEADER +#pragma once #include "irrlichttypes.h" +#include #include #include +#include #include "threading/mutex_auto_lock.h" #include "util/timetaker.h" #include "util/numeric.h" // paging() -#include "debug.h" // assert() - -#define MAX_PROFILER_TEXT_ROWS 20 // Global profiler class Profiler; @@ -42,112 +40,22 @@ extern Profiler *g_profiler; class Profiler { public: - Profiler() {} - - void add(const std::string &name, float value) - { - MutexAutoLock lock(m_mutex); - { - /* No average shall have been used; mark add used as -2 */ - std::map::iterator n = m_avgcounts.find(name); - if(n == m_avgcounts.end()) - m_avgcounts[name] = -2; - else{ - if(n->second == -1) - n->second = -2; - assert(n->second == -2); - } - } - { - std::map::iterator n = m_data.find(name); - if(n == m_data.end()) - m_data[name] = value; - else - n->second += value; - } - } - - void avg(const std::string &name, float value) - { - MutexAutoLock lock(m_mutex); - int &count = m_avgcounts[name]; + Profiler(); - assert(count != -2); - count = MYMAX(count, 0) + 1; - m_data[name] += value; - } + void add(const std::string &name, float value); + void avg(const std::string &name, float value); + void clear(); - void clear() - { - MutexAutoLock lock(m_mutex); - for(std::map::iterator - i = m_data.begin(); - i != m_data.end(); ++i) - { - i->second = 0; - } - m_avgcounts.clear(); - } + float getValue(const std::string &name) const; + int getAvgCount(const std::string &name) const; + u64 getElapsedMs() const; - void print(std::ostream &o) - { - 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) - { - MutexAutoLock lock(m_mutex); + typedef std::map GraphValues; - u32 minindex, maxindex; - paging(m_data.size(), page, pagecount, minindex, maxindex); - - for (std::map::const_iterator i = m_data.begin(); - i != m_data.end(); ++i) { - if (maxindex == 0) - break; - maxindex--; - - if (minindex != 0) { - minindex--; - continue; - } - - int avgcount = 1; - std::map::const_iterator n = m_avgcounts.find(i->first); - if (n != m_avgcounts.end()) { - if(n->second >= 1) - avgcount = n->second; - } - o << " " << i->first << ": "; - s32 clampsize = 40; - s32 space = clampsize - i->first.size(); - for(s32 j = 0; j < space; j++) { - if (j % 2 == 0 && j < space - 1) - o << "-"; - else - o << " "; - } - o << (i->second / avgcount); - o << std::endl; - } - } + // Returns the line count + int print(std::ostream &o, u32 page = 1, u32 pagecount = 1); + void getPage(GraphValues &o, u32 page, u32 pagecount); - typedef std::map GraphValues; void graphAdd(const std::string &id, float value) { @@ -178,6 +86,7 @@ class Profiler std::map m_data; std::map m_avgcounts; std::map m_graphvalues; + u64 m_start_time; }; enum ScopeProfilerType{ @@ -198,6 +107,3 @@ class ScopeProfiler TimeTaker *m_timer = nullptr; enum ScopeProfilerType m_type; }; - -#endif -