From caf8515e9db49aced97b6b8ddedd8a3fce6bc7f8 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Fri, 14 Aug 2026 02:47:56 +1000 Subject: [PATCH] [idd] logging: make periodic statistics opt-in --- idd/LGIdd/capture/CFrameScheduler.cpp | 4 ++ idd/LGIdd/config/CSettings.cpp | 56 ++----------------- idd/LGIdd/config/CSettings.h | 54 +++++++++++++++++- idd/LGIdd/ipc/CInputPipeServer.cpp | 4 ++ .../transport/lgmp/CLGMPInputTransport.cpp | 4 ++ idd/LGInput/CHIDDevice.cpp | 4 ++ idd/LGInput/LGInput.vcxproj | 2 +- idd/LGInput/ipc/CInputPipeClient.cpp | 4 +- 8 files changed, 78 insertions(+), 54 deletions(-) diff --git a/idd/LGIdd/capture/CFrameScheduler.cpp b/idd/LGIdd/capture/CFrameScheduler.cpp index fbc40e2b..3081c390 100644 --- a/idd/LGIdd/capture/CFrameScheduler.cpp +++ b/idd/LGIdd/capture/CFrameScheduler.cpp @@ -20,6 +20,7 @@ #include "capture/CFrameScheduler.h" +#include "config/CSettings.h" #include "CDebug.h" #include "Seq.h" @@ -992,6 +993,9 @@ void CFrameScheduler::LogStatistics(uint64_t now) m_lastLogPublished = m_publishedFrames; lock.Unlock(); + if (!g_settings.ShouldLogStatistics()) + return; + const double acquiredRate = static_cast(acquired) * 1000000000.0 / elapsed; DEBUG_TRACE("Frame schedule owner %u: %.3f Hz client, %.3f Hz acquired, " diff --git a/idd/LGIdd/config/CSettings.cpp b/idd/LGIdd/config/CSettings.cpp index b431bd19..cc5604a7 100644 --- a/idd/LGIdd/config/CSettings.cpp +++ b/idd/LGIdd/config/CSettings.cpp @@ -27,8 +27,6 @@ CSettings g_settings; -#define LGIDD_REGKEY L"SOFTWARE\\LookingGlass\\IDD" - CSettings::CSettings() { } @@ -107,7 +105,7 @@ bool CSettings::SetExtraMode(const DisplayMode& mode) DWORD disp = 0; LONG ec = RegCreateKeyExW( HKEY_LOCAL_MACHINE, - LGIDD_REGKEY, + RegistryKey(), 0, NULL, REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, NULL, &hKey, &disp); @@ -142,7 +140,7 @@ std::wstring CSettings::ReadStringValue(const wchar_t* name, const wchar_t* defa HKEY hKey = nullptr; LONG ec = RegOpenKeyExW( HKEY_LOCAL_MACHINE, - LGIDD_REGKEY, + RegistryKey(), 0, KEY_QUERY_VALUE, &hKey @@ -188,51 +186,6 @@ std::wstring CSettings::ReadStringValue(const wchar_t* name, const wchar_t* defa return std::wstring(buf.data()); } -bool CSettings::ReadBoolValue(const wchar_t* name, bool defaultValue) -{ - HKEY hKey = nullptr; - LONG ec = RegOpenKeyExW( - HKEY_LOCAL_MACHINE, - LGIDD_REGKEY, - 0, - KEY_QUERY_VALUE, - &hKey - ); - - if (ec != ERROR_SUCCESS) - return defaultValue; - - DWORD type = 0; - DWORD cb = 0; - - ec = RegQueryValueExW(hKey, name, nullptr, &type, nullptr, &cb); - if (ec != ERROR_SUCCESS || type != REG_DWORD || cb != sizeof(DWORD)) - { - RegCloseKey(hKey); - return defaultValue; - } - - DWORD value = 0; - DWORD type2 = 0; - DWORD cb2 = sizeof(value); - - ec = RegQueryValueExW( - hKey, - name, - nullptr, - &type2, - reinterpret_cast(&value), - &cb2 - ); - - RegCloseKey(hKey); - - if (ec != ERROR_SUCCESS || type2 != REG_DWORD || cb2 != sizeof(DWORD)) - return defaultValue; - - return value != 0; -} - bool CSettings::GetExtraMode(DisplayMode& mode) { std::wstring extraMode = ReadStringValue(L"ExtraMode", NULL); @@ -250,7 +203,7 @@ unsigned CSettings::GetDefaultRefreshMilliHz() const { HKEY hKey = nullptr; LONG status = RegOpenKeyExW( - HKEY_LOCAL_MACHINE, LGIDD_REGKEY, 0, KEY_QUERY_VALUE, &hKey); + HKEY_LOCAL_MACHINE, RegistryKey(), 0, KEY_QUERY_VALUE, &hKey); if (status != ERROR_SUCCESS) return 60000; @@ -291,7 +244,8 @@ bool CSettings::ReadMultiStringValue(const wchar_t * name, std::vector& out) const { HKEY hKey = nullptr; - LONG st = RegOpenKeyExW(HKEY_LOCAL_MACHINE, LGIDD_REGKEY, 0, KEY_QUERY_VALUE, &hKey); + LONG st = RegOpenKeyExW( + HKEY_LOCAL_MACHINE, RegistryKey(), 0, KEY_QUERY_VALUE, &hKey); if (st != ERROR_SUCCESS) return false; diff --git a/idd/LGIdd/config/CSettings.h b/idd/LGIdd/config/CSettings.h index 82572420..faa4fbee 100644 --- a/idd/LGIdd/config/CSettings.h +++ b/idd/LGIdd/config/CSettings.h @@ -47,9 +47,61 @@ class CSettings unsigned GetDefaultRefreshMilliHz() const; std::wstring ReadStringValue(const wchar_t* name, const wchar_t* defaultValue = nullptr); - bool ReadBoolValue(const wchar_t* name, bool defaultValue = false); + static bool ReadBoolValue( + const wchar_t * name, bool defaultValue = false) + { + HKEY hKey = nullptr; + LONG status = RegOpenKeyExW( + HKEY_LOCAL_MACHINE, + RegistryKey(), + 0, + KEY_QUERY_VALUE, + &hKey); + if (status != ERROR_SUCCESS) + return defaultValue; + + DWORD type = 0; + DWORD size = 0; + status = RegQueryValueExW( + hKey, name, nullptr, &type, nullptr, &size); + if (status != ERROR_SUCCESS || + type != REG_DWORD || + size != sizeof(DWORD)) + { + RegCloseKey(hKey); + return defaultValue; + } + + DWORD value = 0; + DWORD valueType = 0; + DWORD valueSize = sizeof(value); + status = RegQueryValueExW( + hKey, + name, + nullptr, + &valueType, + reinterpret_cast(&value), + &valueSize); + RegCloseKey(hKey); + if (status != ERROR_SUCCESS || + valueType != REG_DWORD || + valueSize != sizeof(value)) + return defaultValue; + + return value != 0; + } + + static bool ShouldLogStatistics() + { + return ReadBoolValue(L"LogStatistics"); + } private: + static const wchar_t * RegistryKey() + { + return L"SOFTWARE\\LookingGlass\\IDD"; + } + bool ReadMultiStringValue(const wchar_t * name, std::vector& out) const; bool ReadModesValue(std::vector &out) const; diff --git a/idd/LGIdd/ipc/CInputPipeServer.cpp b/idd/LGIdd/ipc/CInputPipeServer.cpp index bb16f61b..7ac00909 100644 --- a/idd/LGIdd/ipc/CInputPipeServer.cpp +++ b/idd/LGIdd/ipc/CInputPipeServer.cpp @@ -20,6 +20,7 @@ #include "ipc/CInputPipeServer.h" +#include "config/CSettings.h" #include "CDebug.h" #include "CSRWLock.h" #include "InputPipeProtocol.h" @@ -505,6 +506,9 @@ void CInputPipeServer::LogStatistics() resyncDiscarded || sent || stale || writeFailed || slowWrites)) return; + if (!g_settings.ShouldLogStatistics()) + return; + const double writeMs = m_performanceFrequency.QuadPart ? static_cast(writeTicks) * 1000.0 / m_performanceFrequency.QuadPart : 0.0; diff --git a/idd/LGIdd/transport/lgmp/CLGMPInputTransport.cpp b/idd/LGIdd/transport/lgmp/CLGMPInputTransport.cpp index 94ca89bb..8378bb0c 100644 --- a/idd/LGIdd/transport/lgmp/CLGMPInputTransport.cpp +++ b/idd/LGIdd/transport/lgmp/CLGMPInputTransport.cpp @@ -20,6 +20,7 @@ #include "transport/lgmp/CLGMPInputTransport.h" +#include "config/CSettings.h" #include "transport/lgmp/CLGMPHost.h" #include "Atomic.h" #include "CDebug.h" @@ -644,6 +645,9 @@ void CLGMPInputTransport::LogStatistics(ULONGLONG now) !statistics.releases && !statistics.deliveryFailures) return; + if (!g_settings.ShouldLogStatistics()) + return; + const double elapsed = static_cast(now - statistics.lastLog) / 1000.0; DEBUG_TRACE("LGMP input host: %.1f msg/s, %llu reports, " diff --git a/idd/LGInput/CHIDDevice.cpp b/idd/LGInput/CHIDDevice.cpp index 8b68e705..93ba3d06 100644 --- a/idd/LGInput/CHIDDevice.cpp +++ b/idd/LGInput/CHIDDevice.cpp @@ -21,6 +21,7 @@ #include "CHIDDevice.h" #include "CDebug.h" +#include "config/CSettings.h" #include "CSRWLock.h" #include "HIDReports.h" #include "ipc/CInputPipeClient.h" @@ -671,6 +672,9 @@ void CHIDDevice::LogStatistics() statistics.overflows || statistics.resetDiscarded)) return; + if (!CSettings::ShouldLogStatistics()) + return; + DEBUG_TRACE("HID reports: %llu direct, %llu queued, peak %zu; " "%llu relative and %llu absolute coalesced, %llu stale absolute " "compacted, %llu keyboard and %llu consumer duplicates, " diff --git a/idd/LGInput/LGInput.vcxproj b/idd/LGInput/LGInput.vcxproj index a0bb35ee..74bd4179 100644 --- a/idd/LGInput/LGInput.vcxproj +++ b/idd/LGInput/LGInput.vcxproj @@ -80,7 +80,7 @@ true Trace.h /EHsc /D_ATL_NO_WIN_SUPPORT %(AdditionalOptions) - $(ProjectDir)..\LGCommon;$(ProjectDir)..\..\common\include;$(DDK_INC_PATH);%(AdditionalIncludeDirectories) + $(ProjectDir)..\LGCommon;$(ProjectDir)..\LGIdd;$(ProjectDir)..\..\common\include;$(DDK_INC_PATH);%(AdditionalIncludeDirectories) %(AdditionalDependencies);OneCoreUAP.lib diff --git a/idd/LGInput/ipc/CInputPipeClient.cpp b/idd/LGInput/ipc/CInputPipeClient.cpp index d7228361..038078d0 100644 --- a/idd/LGInput/ipc/CInputPipeClient.cpp +++ b/idd/LGInput/ipc/CInputPipeClient.cpp @@ -21,6 +21,7 @@ #include "CInputPipeClient.h" #include "CDebug.h" +#include "config/CSettings.h" #include "InputPipeProtocol.h" #include "../CHIDDevice.h" #include "../HIDReports.h" @@ -335,7 +336,8 @@ void CInputPipeClient::LogStatistics(bool force) m_statSubmitFailed = 0; m_lastStatistics = now; - if (received || malformed || sequenceResets || submitFailed) + if ((received || malformed || sequenceResets || submitFailed) && + CSettings::ShouldLogStatistics()) { DEBUG_TRACE("LGInput pipe receive: %llu reports, %llu malformed, " "%llu sequence resets, %llu HID submit failures",