From 2f1eec92315ba063792880828e3d3a4cd753d294 Mon Sep 17 00:00:00 2001 From: Dentomologist Date: Wed, 11 Feb 2026 16:38:40 -0800 Subject: [PATCH 1/3] DolphinAnalytics: Use std::chrono for timekeeping --- Source/Core/Core/DolphinAnalytics.cpp | 37 +++++++++++++++++++-------- Source/Core/Core/DolphinAnalytics.h | 13 ++-------- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/Source/Core/Core/DolphinAnalytics.cpp b/Source/Core/Core/DolphinAnalytics.cpp index 8b207c658c..192bb7ce97 100644 --- a/Source/Core/Core/DolphinAnalytics.cpp +++ b/Source/Core/Core/DolphinAnalytics.cpp @@ -4,8 +4,10 @@ #include "Core/DolphinAnalytics.h" #include +#include #include #include +#include #include #include #include @@ -29,7 +31,6 @@ #include "Common/Config/Config.h" #include "Common/Crypto/SHA1.h" #include "Common/Random.h" -#include "Common/Timer.h" #include "Common/Version.h" #include "Core/Config/GraphicsSettings.h" #include "Core/Config/MainSettings.h" @@ -46,6 +47,25 @@ namespace { constexpr char ANALYTICS_ENDPOINT[] = "https://analytics.dolphin-emu.org/report"; + +using namespace std::chrono_literals; + +// Performance sampling configuration constants. +// +// 5min after startup + rand(0, 3min) jitter time, sample performance for 100 frames in a row. +// Each sampling thereafter happens 30min + rand(0, 3min) after the previous one. +static constexpr int NUM_PERFORMANCE_SAMPLES_PER_REPORT = 100; +static constexpr auto PERFORMANCE_SAMPLING_BASE_INITIAL_WAIT = 5min; +static constexpr auto PERFORMANCE_SAMPLING_BASE_INTERVAL_WAIT = 30min; +static constexpr std::chrono::microseconds PERFORMANCE_SAMPLING_WAIT_MAX_JITTER = 3min; + +std::chrono::microseconds GetWaitJitter() +{ + std::random_device device; + std::uniform_int_distribution<> distribution(0, PERFORMANCE_SAMPLING_WAIT_MAX_JITTER.count()); + + return std::chrono::microseconds(distribution(device)); +} } // namespace #if defined(ANDROID) @@ -250,21 +270,18 @@ void DolphinAnalytics::InitializePerformanceSampling() m_performance_samples.clear(); m_sampling_performance_info = false; - u64 wait_us = - PERFORMANCE_SAMPLING_INITIAL_WAIT_TIME_SECS * 1000000 + - Common::Random::GenerateValue() % (PERFORMANCE_SAMPLING_WAIT_TIME_JITTER_SECS * 1000000); - m_sampling_next_start_us = Common::Timer::NowUs() + wait_us; + m_sampling_next_start_time = + std::chrono::steady_clock::now() + PERFORMANCE_SAMPLING_BASE_INITIAL_WAIT + GetWaitJitter(); } bool DolphinAnalytics::ShouldStartPerformanceSampling() { - if (Common::Timer::NowUs() < m_sampling_next_start_us) + const auto now = std::chrono::steady_clock::now(); + if (now < m_sampling_next_start_time) return false; - u64 wait_us = - PERFORMANCE_SAMPLING_INTERVAL_SECS * 1000000 + - Common::Random::GenerateValue() % (PERFORMANCE_SAMPLING_WAIT_TIME_JITTER_SECS * 1000000); - m_sampling_next_start_us = Common::Timer::NowUs() + wait_us; + m_sampling_next_start_time = now + PERFORMANCE_SAMPLING_BASE_INTERVAL_WAIT + GetWaitJitter(); + return true; } diff --git a/Source/Core/Core/DolphinAnalytics.h b/Source/Core/Core/DolphinAnalytics.h index 595736e821..e4a3b15241 100644 --- a/Source/Core/Core/DolphinAnalytics.h +++ b/Source/Core/Core/DolphinAnalytics.h @@ -4,13 +4,13 @@ #pragma once #include +#include #include #include #include #include #include "Common/Analytics.h" -#include "Common/CommonTypes.h" #include "Common/Config/Config.h" #if defined(ANDROID) @@ -173,19 +173,10 @@ private: // values created by MakeUniqueId. std::string m_unique_id; - // Performance sampling configuration constants. - // - // 5min after startup + rand(0, 3min) jitter time, collect performance for 100 frames in a row. - // Repeat collection after 30min + rand(0, 3min). - static constexpr int NUM_PERFORMANCE_SAMPLES_PER_REPORT = 100; - static constexpr int PERFORMANCE_SAMPLING_INITIAL_WAIT_TIME_SECS = 300; - static constexpr int PERFORMANCE_SAMPLING_WAIT_TIME_JITTER_SECS = 180; - static constexpr int PERFORMANCE_SAMPLING_INTERVAL_SECS = 1800; - // Performance sampling state & internal helpers. void InitializePerformanceSampling(); // Called on game start / title switch. bool ShouldStartPerformanceSampling(); - u64 m_sampling_next_start_us; // Next timestamp (in us) at which to trigger sampling. + std::chrono::steady_clock::time_point m_sampling_next_start_time; bool m_sampling_performance_info = false; // Whether we are currently collecting samples. std::vector m_performance_samples; From 3a6e99f2aeed9a1a51cd3c78c1c5ef126344f7b3 Mon Sep 17 00:00:00 2001 From: Dentomologist Date: Mon, 25 Jan 2021 09:25:02 -0800 Subject: [PATCH 2/3] DolphinAnalytics: Move variable declaration Move endpoint declaration from anonymous namespace to the only function it's used in. --- Source/Core/Core/DolphinAnalytics.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Source/Core/Core/DolphinAnalytics.cpp b/Source/Core/Core/DolphinAnalytics.cpp index 192bb7ce97..70ab626517 100644 --- a/Source/Core/Core/DolphinAnalytics.cpp +++ b/Source/Core/Core/DolphinAnalytics.cpp @@ -46,8 +46,6 @@ namespace { -constexpr char ANALYTICS_ENDPOINT[] = "https://analytics.dolphin-emu.org/report"; - using namespace std::chrono_literals; // Performance sampling configuration constants. @@ -112,7 +110,8 @@ void DolphinAnalytics::ReloadConfig() std::unique_ptr new_backend; if (m_last_analytics_enabled) { - new_backend = std::make_unique(ANALYTICS_ENDPOINT); + constexpr char analytics_endpoint[] = "https://analytics.dolphin-emu.org/report"; + new_backend = std::make_unique(analytics_endpoint); } m_reporter.SetBackend(std::move(new_backend)); From aefc6bfe2fc49ab8faf0cd9dc3193a1f8e9a5d6f Mon Sep 17 00:00:00 2001 From: Dentomologist Date: Wed, 11 Feb 2026 16:47:04 -0800 Subject: [PATCH 3/3] DolphinAnalytics: Make variable const --- Source/Core/Core/DolphinAnalytics.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Core/Core/DolphinAnalytics.cpp b/Source/Core/Core/DolphinAnalytics.cpp index 70ab626517..282a39d418 100644 --- a/Source/Core/Core/DolphinAnalytics.cpp +++ b/Source/Core/Core/DolphinAnalytics.cpp @@ -211,7 +211,7 @@ static_assert(GAME_QUIRKS_NAMES.size() == static_cast(GameQuirk::Count), void DolphinAnalytics::ReportGameQuirk(GameQuirk quirk) { - u32 quirk_idx = static_cast(quirk); + const u32 quirk_idx = static_cast(quirk); // Only report once per run. if (m_reported_quirks[quirk_idx])