From 17932935d9fad77ce5703d29ec145084a08bb2ab Mon Sep 17 00:00:00 2001 From: degasus Date: Thu, 20 Aug 2015 11:41:49 +0200 Subject: Profiler: Sort output by total time --- Source/Core/Common/Profiler.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'Source/Core/Common/Profiler.cpp') 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::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(s_max_length, u32(m_name.length())); + std::lock_guard lk(s_mutex); s_all_profilers.push_back(this); } Profiler::~Profiler() { + std::lock_guard 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 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(); } + +} -- cgit v1.2.3