summaryrefslogtreecommitdiff
path: root/Source/Core
diff options
context:
space:
mode:
authorJMC47 <JMC4789@gmail.com>2023-01-06 17:03:35 -0500
committerGitHub <noreply@github.com>2023-01-06 17:03:35 -0500
commit2da39f7e00d01fbfc7ea2728231a6e52395f5b1e (patch)
tree028fa07caf14086db76995921903b418cff640c9 /Source/Core
parentcc14d60bbb9fd069e831bd3d84b8dc4fa1b3ddee (diff)
parent588a72a4fc7eb46f161687d0828afd9703e618ee (diff)
Merge pull request #11409 from AdmiralCurtiss/performance-tracker-refactorings
Performance tracker refactorings extracted from PR #11348.
Diffstat (limited to 'Source/Core')
-rw-r--r--Source/Core/VideoCommon/PerformanceMetrics.cpp2
-rw-r--r--Source/Core/VideoCommon/PerformanceMetrics.h2
-rw-r--r--Source/Core/VideoCommon/PerformanceTracker.cpp31
-rw-r--r--Source/Core/VideoCommon/PerformanceTracker.h10
4 files changed, 25 insertions, 20 deletions
diff --git a/Source/Core/VideoCommon/PerformanceMetrics.cpp b/Source/Core/VideoCommon/PerformanceMetrics.cpp
index 3b9cc81791..23e35623cb 100644
--- a/Source/Core/VideoCommon/PerformanceMetrics.cpp
+++ b/Source/Core/VideoCommon/PerformanceMetrics.cpp
@@ -134,7 +134,7 @@ void PerformanceMetrics::DrawImGuiStats(const float backbuffer_scale) const
ImPlot::PushStyleColor(ImPlotCol_PlotBg, {0, 0, 0, 0});
ImPlot::PushStyleColor(ImPlotCol_LegendBg, {0, 0, 0, 0.2f});
ImPlot::PushStyleVar(ImPlotStyleVar_FitPadding, ImVec2(0.f, 0.f));
- ImPlot::PushStyleVar(ImPlotStyleVar_LineWeight, 3.f);
+ ImPlot::PushStyleVar(ImPlotStyleVar_LineWeight, 1.5f * backbuffer_scale);
ImPlot::SetupAxes(nullptr, nullptr,
ImPlotAxisFlags_Lock | ImPlotAxisFlags_Invert |
ImPlotAxisFlags_NoDecorations | ImPlotAxisFlags_NoHighlight,
diff --git a/Source/Core/VideoCommon/PerformanceMetrics.h b/Source/Core/VideoCommon/PerformanceMetrics.h
index b01c0782ab..eb6f8ecb00 100644
--- a/Source/Core/VideoCommon/PerformanceMetrics.h
+++ b/Source/Core/VideoCommon/PerformanceMetrics.h
@@ -34,7 +34,7 @@ public:
private:
PerformanceTracker m_fps_counter{"render_times.txt"};
PerformanceTracker m_vps_counter{"vblank_times.txt"};
- PerformanceTracker m_speed_counter{nullptr, 500000};
+ PerformanceTracker m_speed_counter{std::nullopt, 500000};
};
extern PerformanceMetrics g_perf_metrics;
diff --git a/Source/Core/VideoCommon/PerformanceTracker.cpp b/Source/Core/VideoCommon/PerformanceTracker.cpp
index ffde157883..93b33cff9a 100644
--- a/Source/Core/VideoCommon/PerformanceTracker.cpp
+++ b/Source/Core/VideoCommon/PerformanceTracker.cpp
@@ -5,8 +5,10 @@
#include <algorithm>
#include <cmath>
-#include <implot.h>
#include <iomanip>
+#include <mutex>
+
+#include <implot.h>
#include "Common/CommonTypes.h"
#include "Common/FileUtil.h"
@@ -16,7 +18,7 @@
static constexpr double SAMPLE_RC_RATIO = 0.25;
-PerformanceTracker::PerformanceTracker(const char* log_name,
+PerformanceTracker::PerformanceTracker(const std::optional<std::string> log_name,
const std::optional<s64> sample_window_us)
: m_on_state_changed_handle{Core::AddOnStateChangedCallback([this](Core::State state) {
if (state == Core::State::Paused)
@@ -36,7 +38,7 @@ PerformanceTracker::~PerformanceTracker()
void PerformanceTracker::Reset()
{
- std::lock_guard lock{m_mutex};
+ std::unique_lock lock{m_mutex};
QueueClear();
m_last_time = Clock::now();
@@ -47,7 +49,7 @@ void PerformanceTracker::Reset()
void PerformanceTracker::Count()
{
- std::lock_guard lock{m_mutex};
+ std::unique_lock lock{m_mutex};
if (m_paused)
return;
@@ -84,8 +86,7 @@ void PerformanceTracker::Count()
m_dt_std = std::nullopt;
- if (m_log_name && g_ActiveConfig.bLogRenderTimeToFile)
- LogRenderTimeToFile(diff);
+ LogRenderTimeToFile(diff);
}
DT PerformanceTracker::GetSampleWindow() const
@@ -97,19 +98,19 @@ DT PerformanceTracker::GetSampleWindow() const
double PerformanceTracker::GetHzAvg() const
{
- std::lock_guard lock{m_mutex};
+ std::shared_lock lock{m_mutex};
return m_hz_avg;
}
DT PerformanceTracker::GetDtAvg() const
{
- std::lock_guard lock{m_mutex};
+ std::shared_lock lock{m_mutex};
return m_dt_avg;
}
DT PerformanceTracker::GetDtStd() const
{
- std::lock_guard lock{m_mutex};
+ std::unique_lock lock{m_mutex};
if (m_dt_std)
return *m_dt_std;
@@ -130,7 +131,7 @@ DT PerformanceTracker::GetDtStd() const
DT PerformanceTracker::GetLastRawDt() const
{
- std::lock_guard lock{m_mutex};
+ std::shared_lock lock{m_mutex};
if (QueueEmpty())
return DT::zero();
@@ -142,7 +143,7 @@ void PerformanceTracker::ImPlotPlotLines(const char* label) const
{
static std::array<float, MAX_DT_QUEUE_SIZE + 2> x, y;
- std::lock_guard lock{m_mutex};
+ std::shared_lock lock{m_mutex};
if (QueueEmpty())
return;
@@ -228,9 +229,13 @@ bool PerformanceTracker::QueueEmpty() const
void PerformanceTracker::LogRenderTimeToFile(DT val)
{
+ if (!m_log_name || !g_ActiveConfig.bLogRenderTimeToFile)
+ return;
+
if (!m_bench_file.is_open())
{
- File::OpenFStream(m_bench_file, File::GetUserPath(D_LOGS_IDX) + m_log_name, std::ios_base::out);
+ File::OpenFStream(m_bench_file, File::GetUserPath(D_LOGS_IDX) + *m_log_name,
+ std::ios_base::out);
}
m_bench_file << std::fixed << std::setprecision(8) << DT_ms(val).count() << std::endl;
@@ -238,7 +243,7 @@ void PerformanceTracker::LogRenderTimeToFile(DT val)
void PerformanceTracker::SetPaused(bool paused)
{
- std::lock_guard lock{m_mutex};
+ std::unique_lock lock{m_mutex};
m_paused = paused;
if (m_paused)
diff --git a/Source/Core/VideoCommon/PerformanceTracker.h b/Source/Core/VideoCommon/PerformanceTracker.h
index e253f83352..f24601c845 100644
--- a/Source/Core/VideoCommon/PerformanceTracker.h
+++ b/Source/Core/VideoCommon/PerformanceTracker.h
@@ -6,8 +6,8 @@
#include <array>
#include <chrono>
#include <fstream>
-#include <mutex>
#include <optional>
+#include <shared_mutex>
#include "Common/CommonTypes.h"
@@ -34,8 +34,8 @@ private:
}
public:
- PerformanceTracker(const char* log_name = nullptr,
- const std::optional<s64> sample_window_us = {});
+ PerformanceTracker(const std::optional<std::string> log_name = std::nullopt,
+ const std::optional<s64> sample_window_us = std::nullopt);
~PerformanceTracker();
PerformanceTracker(const PerformanceTracker&) = delete;
@@ -77,7 +77,7 @@ private: // Functions for managing dt queue
int m_on_state_changed_handle;
// Name of log file and file stream
- const char* m_log_name;
+ std::optional<std::string> m_log_name;
std::ofstream m_bench_file;
// Last time Count() was called
@@ -100,5 +100,5 @@ private: // Functions for managing dt queue
mutable std::optional<DT> m_dt_std = std::nullopt;
// Used to enable thread safety with the performance tracker
- mutable std::mutex m_mutex;
+ mutable std::shared_mutex m_mutex;
};