SolverMonitor class
#include <gtopt/solver_monitor.hpp>
Background thread that samples workpool statistics and writes JSON.
Start by calling start(pool, thread_name). Stop by calling stop() or letting the object go out of scope (RAII — the std::jthread destructor automatically requests a stop and joins).
The history is collected in m_history_ under m_mutex_. Call append_history_json(json) to emit the "realtime" JSON block, and write_status(content, path) for atomic file writes.
Public types
- using Interval = std::chrono::milliseconds
- Update interval for the background sampling thread.
Public static variables
- static constexpr std::size_t max_history_size
Public static functions
- static auto write_status(const std::string& content, const std::string& path) -> void noexcept
- Write content atomically to path (write tmp, rename).
Constructors, destructors, conversion operators
- SolverMonitor(const SolverMonitor&) deleted
- SolverMonitor(Interval update_interval = Interval {500}) explicit noexcept
- SolverMonitor(SolverMonitor&&) deleted
- ~SolverMonitor() defaulted
Public functions
- auto append_history_json(std::string& json) const -> void
- Append the
"realtime"JSON block tojsonusing collected history. - auto history() const -> std::vector<MonitorPoint>
- Access the collected history (caller must hold no other locks).
- auto operator=(const SolverMonitor&) -> SolverMonitor& deleted
- auto operator=(SolverMonitor&&) -> SolverMonitor& deleted
- auto start(Pool& pool, std::chrono::steady_clock::time_point start_time, const char* thread_name = "SolverMonitor") -> void
- auto stop() -> void noexcept
- Request the background thread to stop (non-blocking).
Function documentation
void gtopt:: SolverMonitor:: start(Pool& pool,
std::chrono::steady_clock::time_point start_time,
const char* thread_name = "SolverMonitor")
| Parameters | |
|---|---|
| pool | The work pool to sample statistics from. |
| start_time | Reference time-point for timestamp computation. |
| thread_name | Name to assign the background thread (Linux only). |
Start the background sampling thread.
Variable documentation
static constexpr std::size_t gtopt:: SolverMonitor:: max_history_size
Maximum number of monitor points to retain. At 500ms intervals, 7200 points ≈ 1 hour of data.