diff options
| author | degasus <wickmarkus@web.de> | 2015-08-20 11:41:49 +0200 |
|---|---|---|
| committer | degasus <wickmarkus@web.de> | 2015-08-20 11:50:43 +0200 |
| commit | 17932935d9fad77ce5703d29ec145084a08bb2ab (patch) | |
| tree | 5941d905c687f90efe7510380ed30c963a417ae5 /Source/Core/Common/Profiler.cpp | |
| parent | cb264df64c1af2f6d92ccfb15383168cbd5560f1 (diff) | |
Profiler: Sort output by total time
Diffstat (limited to 'Source/Core/Common/Profiler.cpp')
| -rw-r--r-- | Source/Core/Common/Profiler.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/Source/Core/Common/Profiler.cpp b/Source/Core/Common/Profiler.cpp index 8d347afb89..7a195dd02d 100644 --- a/Source/Core/Common/Profiler.cpp +++ b/Source/Core/Common/Profiler.cpp @@ -12,11 +12,15 @@ #include "Common/Profiler.h" #include "Common/Timer.h" +namespace Common +{ + static const u32 PROFILER_FIELD_LENGTH = 8; static const u32 PROFILER_FIELD_LENGTH_FP = PROFILER_FIELD_LENGTH + 3; static const int PROFILER_LAZY_DELAY = 60; // in frames std::list<Profiler*> Profiler::s_all_profilers; +std::mutex Profiler::s_mutex; u32 Profiler::s_max_length = 0; u64 Profiler::s_frame_time; u64 Profiler::s_usecs_frame; @@ -30,14 +34,21 @@ Profiler::Profiler(const std::string& name) m_time = Common::Timer::GetTimeUs(); s_max_length = std::max<u32>(s_max_length, u32(m_name.length())); + std::lock_guard<std::mutex> lk(s_mutex); s_all_profilers.push_back(this); } Profiler::~Profiler() { + std::lock_guard<std::mutex> lk(s_mutex); s_all_profilers.remove(this); } +bool Profiler::operator<(const Profiler& b) const +{ + return m_usecs < b.m_usecs; +} + std::string Profiler::ToString() { if (s_lazy_delay > 0) @@ -48,6 +59,7 @@ std::string Profiler::ToString() s_lazy_delay = PROFILER_LAZY_DELAY - 1; // don't write anything if no profilation is enabled + std::lock_guard<std::mutex> lk(s_mutex); if (s_all_profilers.empty()) return ""; @@ -66,6 +78,8 @@ std::string Profiler::ToString() buffer << std::setw(PROFILER_FIELD_LENGTH) << std::right << "max" << " "; buffer << "/ usec" << std::endl; + s_all_profilers.sort([](Profiler* a, Profiler* b) { return *b < *a; }); + for (auto profiler : s_all_profilers) { buffer << profiler->Read() << std::endl; @@ -136,3 +150,5 @@ std::string Profiler::Read() return buffer.str(); } + +} |
