From 539f016c1b1a706da2c113435ec60bb39c868f4b Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Tue, 13 Aug 2019 19:56:55 +0200 Subject: Better F6 profiler (#8750) Update the profiler names to make more sense of what they actually represent Move the profiler code from header to its source file Use monospace font to align lines Format the statistics line to align better with surrounding values Refresh the profiler each 3 seconds (roughly) --- src/profiler.h | 112 +++++++-------------------------------------------------- 1 file changed, 12 insertions(+), 100 deletions(-) (limited to 'src/profiler.h') 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::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 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::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) { @@ -175,6 +86,7 @@ private: std::map m_data; std::map m_avgcounts; std::map m_graphvalues; + u64 m_start_time; }; enum ScopeProfilerType{ -- cgit v1.2.3