Profiler: Sort output by total time
This commit is contained in:
parent
cb264df64c
commit
17932935d9
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,10 +5,14 @@
|
|||
#pragma once
|
||||
|
||||
#include <list>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
|
||||
#include "CommonTypes.h"
|
||||
|
||||
namespace Common
|
||||
{
|
||||
|
||||
class Profiler
|
||||
{
|
||||
public:
|
||||
|
@ -21,8 +25,11 @@ public:
|
|||
void Stop();
|
||||
std::string Read();
|
||||
|
||||
bool operator<(const Profiler& b) const;
|
||||
|
||||
private:
|
||||
static std::list<Profiler*> s_all_profilers;
|
||||
static std::mutex s_mutex;
|
||||
static u32 s_max_length;
|
||||
static u64 s_frame_time;
|
||||
static u64 s_usecs_frame;
|
||||
|
@ -55,5 +62,7 @@ private:
|
|||
Profiler* m_p;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
// Warning: This profiler isn't thread safe. Only profile functions which doesn't run simultaneously
|
||||
#define PROFILE(name) static Profiler prof_gen(name); ProfilerExecuter prof_e(&prof_gen);
|
||||
#define PROFILE(name) static Common::Profiler prof_gen(name); Common::ProfilerExecuter prof_e(&prof_gen);
|
||||
|
|
|
@ -402,7 +402,7 @@ void Renderer::DrawDebugText()
|
|||
}
|
||||
}
|
||||
|
||||
final_cyan += Profiler::ToString();
|
||||
final_cyan += Common::Profiler::ToString();
|
||||
|
||||
if (g_ActiveConfig.bOverlayStats)
|
||||
final_cyan += Statistics::ToString();
|
||||
|
|
Loading…
Reference in New Issue