summaryrefslogtreecommitdiff
path: root/Source/Core
diff options
context:
space:
mode:
authorRyan Houdek <Sonicadvance1@gmail.com>2015-08-22 17:52:54 -0500
committerRyan Houdek <Sonicadvance1@gmail.com>2015-08-22 17:52:54 -0500
commitcc3fb7e7b45672ccb13b3be0faeed522edfef806 (patch)
tree1441eabe74a79c1c8835cf7385a33323300230dc /Source/Core
parent8b881a6c3457dc792b368cf44ec36cd1677d57d3 (diff)
parent17932935d9fad77ce5703d29ec145084a08bb2ab (diff)
Merge pull request #2883 from degasus/master
Profiler: Sort output by total time
Diffstat (limited to 'Source/Core')
-rw-r--r--Source/Core/Common/Profiler.cpp16
-rw-r--r--Source/Core/Common/Profiler.h11
-rw-r--r--Source/Core/VideoCommon/RenderBase.cpp2
3 files changed, 27 insertions, 2 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();
}
+
+}
diff --git a/Source/Core/Common/Profiler.h b/Source/Core/Common/Profiler.h
index 0b1a41dde3..c3643d4945 100644
--- a/Source/Core/Common/Profiler.h
+++ b/Source/Core/Common/Profiler.h
@@ -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);
diff --git a/Source/Core/VideoCommon/RenderBase.cpp b/Source/Core/VideoCommon/RenderBase.cpp
index e116a38443..55a6cb8760 100644
--- a/Source/Core/VideoCommon/RenderBase.cpp
+++ b/Source/Core/VideoCommon/RenderBase.cpp
@@ -402,7 +402,7 @@ void Renderer::DrawDebugText()
}
}
- final_cyan += Profiler::ToString();
+ final_cyan += Common::Profiler::ToString();
if (g_ActiveConfig.bOverlayStats)
final_cyan += Statistics::ToString();