diff --git a/Src/Core/GateRelay.cpp b/Src/Core/GateRelay.cpp index 274df43..8c70065 100644 --- a/Src/Core/GateRelay.cpp +++ b/Src/Core/GateRelay.cpp @@ -173,8 +173,7 @@ void MWR::C3::Core::GateRelay::RunApiBrige(std::string_view apiBrigdeIp, std::ui { // Read socket. std::this_thread::sleep_for(300ms); - auto newSnapshot = sp.GetSnapshotIfChanged(); - if (newSnapshot) + if (auto newSnapshot = sp.GetSnapshotIfChanged()) { try { diff --git a/Src/Core/Profiler.cpp b/Src/Core/Profiler.cpp index 55fc09f..d4e16b1 100644 --- a/Src/Core/Profiler.cpp +++ b/Src/Core/Profiler.cpp @@ -1530,3 +1530,21 @@ json MWR::C3::Core::Profiler::Channel::CreateProfileSnapshot() const return profile; } + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +MWR::C3::Core::Profiler::SnapshotProxy::SnapshotProxy(Profiler& profiler) : + m_Profiler(profiler) +{ +} + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +std::optional MWR::C3::Core::Profiler::SnapshotProxy::GetSnapshotIfChanged() +{ + auto currentSnapshot = m_Profiler.Get().m_Gateway.CreateProfileSnapshot(); + auto currentHash = std::hash{}(currentSnapshot); + if (previousHash && currentHash == *previousHash) + return {}; + + previousHash = currentHash; + return currentSnapshot; +} diff --git a/Src/Core/Profiler.h b/Src/Core/Profiler.h index 6c2649c..6332e3a 100644 --- a/Src/Core/Profiler.h +++ b/Src/Core/Profiler.h @@ -542,23 +542,11 @@ namespace MWR::C3::Core public: /// Create a snapshot proxy /// @param profiler to wrap CreateProfileShnapshot calls - SnapshotProxy(Profiler& profiler) : - m_Profiler(profiler) - { - } + SnapshotProxy(Profiler& profiler); /// Create a snapshot /// @return std::nullopt if snaphot hasn't change since the last call - std::optional GetSnapshotIfChanged() - { - auto currentSnapshot = m_Profiler.Get().m_Gateway.CreateProfileSnapshot(); - auto currentHash = std::hash{}(currentSnapshot); - if (previousHash && currentHash == *previousHash) - return {}; - - previousHash = currentHash; - return currentSnapshot; - } + std::optional GetSnapshotIfChanged(); private: /// Proxied profiler