diff options
Diffstat (limited to 'src/profiler.h')
-rw-r--r-- | src/profiler.h | 112 |
1 files changed, 12 insertions, 100 deletions
diff --git a/src/profiler.h b/src/profiler.h index 6704afd51..b4a0657f9 100644 --- a/src/profiler.h +++ b/src/profiler.h @@ -29,8 +29,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "util/timetaker.h" #include "util/numeric.h" // paging() -#define MAX_PROFILER_TEXT_ROWS 20 - // Global profiler class Profiler; extern Profiler *g_profiler; @@ -42,109 +40,22 @@ extern Profiler *g_profiler; class Profiler { public: - Profiler() = default; + 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<std::string, int>::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<std::string, float>::iterator n = m_data.find(name); - if(n == m_data.end()) - m_data[name] = value; - else - n->second += value; - } - } + void add(const std::string &name, float value); + void avg(const std::string &name, float value); + void clear(); - void avg(const std::string &name, float value) - { - MutexAutoLock lock(m_mutex); - int &count = m_avgcounts[name]; + float getValue(const std::string &name) const; + int getAvgCount(const std::string &name) const; + u64 getElapsedMs() const; - assert(count != -2); - count = MYMAX(count, 0) + 1; - m_data[name] += value; - } - - void clear() - { - MutexAutoLock lock(m_mutex); - for (auto &it : m_data) { - it.second = 0; - } - m_avgcounts.clear(); - } - - void print(std::ostream &o) - { - printPage(o, 1, 1); - } - - float getValue(const std::string &name) const - { - std::map<std::string, float>::const_iterator numerator = m_data.find(name); - if (numerator == m_data.end()) - return 0.f; - - std::map<std::string, int>::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<std::string, float> GraphValues; - u32 minindex, maxindex; - paging(m_data.size(), page, pagecount, minindex, maxindex); - - for (std::map<std::string, float>::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<std::string, int>::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<std::string, float> GraphValues; void graphAdd(const std::string &id, float value) { @@ -175,6 +86,7 @@ private: std::map<std::string, float> m_data; std::map<std::string, int> m_avgcounts; std::map<std::string, float> m_graphvalues; + u64 m_start_time; }; enum ScopeProfilerType{ |