Profiler: Sort output by total time

This commit is contained in:
degasus
2015-08-20 11:41:49 +02:00
parent cb264df64c
commit 17932935d9
3 changed files with 27 additions and 2 deletions

View File

@ -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();
}
}