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;