CPUMonitor class
#include <gtopt/cpu_monitor.hpp>
Public static functions
- static auto get_system_cpu_usage(double fallback_value = 50.0) -> double noexcept
Constructors, destructors, conversion operators
- CPUMonitor() defaulted
- CPUMonitor(const CPUMonitor&) deleted
- CPUMonitor(CPUMonitor&&) deleted
- ~CPUMonitor()
Public functions
- auto get_interval() const -> auto noexcept
- auto get_load() const -> double noexcept
- Gets current CPU load percentage (all logical cores).
- auto get_physical_load() const -> double noexcept
- Gets CPU load scaled to physical cores.
- void notify_stop() noexcept
- auto operator=(const CPUMonitor&) -> CPUMonitor& deleted
- auto operator=(CPUMonitor&&) -> CPUMonitor& deleted
- void request_stop() noexcept
- Signal the monitor thread to wind down without joining.
- void set_interval(std::chrono::milliseconds interval) noexcept
- void start()
- void stop() noexcept
Function documentation
double gtopt:: CPUMonitor:: get_load() const noexcept
Gets current CPU load percentage (all logical cores).
| Returns | Value between 0.0 and 100.0, or negative if invalid |
|---|
double gtopt:: CPUMonitor:: get_physical_load() const noexcept
Gets CPU load scaled to physical cores.
| Returns | Value between 0.0 and 100.0 |
|---|
On HT machines, aggregate CPU load under-reports physical core saturation. This method scales the raw load by the SMT ratio (capped at 100%) so scheduling decisions reflect physical core pressure. E.g. 50% raw on a 2x-HT machine → 100% physical.
void gtopt:: CPUMonitor:: request_stop() noexcept
Signal the monitor thread to wind down without joining.
Phase-1 helper used by BasicWorkPool::shutdown(): setting running_=false + flipping the jthread's stop_token + notifying stop_cv_ lets the monitor thread observe the stop request immediately, so that by the time stop() is later called its subsequent join() is near-instant rather than blocking up to monitor_interval_. Idempotent — safe to call multiple times.