diff options
| author | Dan Engelbrecht <[email protected]> | 2026-03-22 19:01:36 +0100 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2026-03-22 19:01:36 +0100 |
| commit | 1bf5d5a48c0ac762b483fd0867b838a312da47e1 (patch) | |
| tree | b0f527bd532437ce831114fcf665c5f2614f6d7d /src/zencore/system.cpp | |
| parent | S3 hydration backend for hub mode (#873) (diff) | |
| download | zen-1bf5d5a48c0ac762b483fd0867b838a312da47e1.tar.xz zen-1bf5d5a48c0ac762b483fd0867b838a312da47e1.zip | |
improve zenserver startup time (#879)
- Improvement: Lazy initialize CpuSampler - reduces startup time by ~600 ms
- Bugfix: Don't try to wipe .sentry-native folder at missing manifest - sentry is already running. Reduces startup time by ~450 ms when data folder is empty
Diffstat (limited to 'src/zencore/system.cpp')
| -rw-r--r-- | src/zencore/system.cpp | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/src/zencore/system.cpp b/src/zencore/system.cpp index 8985a8a76..23178814c 100644 --- a/src/zencore/system.cpp +++ b/src/zencore/system.cpp @@ -445,23 +445,15 @@ struct CpuSampler PDH_HQUERY QueryHandle = nullptr; PDH_HCOUNTER CounterHandle = nullptr; bool HasPreviousSample = false; + bool IsInitialized = false; bool IsWine = false; ProcStatCpuSampler ProcStat{"Z:\\proc\\stat"}; CpuSampler() { IsWine = zen::windows::IsRunningOnWine(); - - if (!IsWine) - { - if (PdhOpenQueryW(nullptr, 0, &QueryHandle) == ERROR_SUCCESS) - { - if (PdhAddEnglishCounterW(QueryHandle, L"\\Processor(_Total)\\% Processor Time", 0, &CounterHandle) != ERROR_SUCCESS) - { - CounterHandle = nullptr; - } - } - } + // PDH initialization is deferred to the first Sample() call because + // PdhAddEnglishCounterW can take hundreds of milliseconds on first invocation. } ~CpuSampler() @@ -472,6 +464,22 @@ struct CpuSampler } } + void InitializePdh() + { + if (IsInitialized) + { + return; + } + IsInitialized = true; + if (PdhOpenQueryW(nullptr, 0, &QueryHandle) == ERROR_SUCCESS) + { + if (PdhAddEnglishCounterW(QueryHandle, L"\\Processor(_Total)\\% Processor Time", 0, &CounterHandle) != ERROR_SUCCESS) + { + CounterHandle = nullptr; + } + } + } + float Sample() { if (IsWine) @@ -479,6 +487,8 @@ struct CpuSampler return ProcStat.Sample(); } + InitializePdh(); + if (!QueryHandle || !CounterHandle) { return 0.0f; |