58 std::vector<GpuSample>
gpus;
169 [[nodiscard]] std::optional<SystemSample>
latest()
const;
172 [[nodiscard]] std::vector<SystemSample>
history()
const;
196 std::unique_ptr<Impl> impl_;
Samples CPU/GPU utilization, memory use and temperatures on a background thread, keeps a bounded in-m...
Definition system_monitor.hpp:113
bool running() const
True between start() and stop().
void start()
Opens the log (if any) and starts the background sampling thread. No-op if running.
~SystemMonitor()
Stops the background thread (if running) and closes the log.
void stop()
Stops and joins the background thread, then closes the log. No-op if not running.
void mark(std::string label)
Sets the label carried by subsequent samples (e.g. "epoch 3", "explain:lrp"), and if the log is open ...
std::vector< SystemSample > history() const
Background samples, oldest first, at most Options::history_capacity of them.
const Options & options() const noexcept
The options this monitor was constructed with.
SystemMonitor(Options options)
void on_sample(std::function< void(const SystemSample &)> callback)
Registers a callback run on the monitor thread after each background sample (after it is logged and s...
std::vector< MetricCapability > capabilities() const
Per-metric availability on this machine, with the source or the reason it is missing.
SystemMonitor & operator=(const SystemMonitor &)=delete
std::optional< SystemSample > latest() const
The most recent background sample, or std::nullopt before the first one.
SystemSample sample_now()
Takes one synchronous measurement on the calling thread. Works without start().
SystemMonitor(const SystemMonitor &)=delete
SystemMonitor()
Default options: 1 s interval, no log.
SystemMonitor(Options options, std::unique_ptr< detail::PlatformSources > sources)
Testing hook: reads from sources instead of the host (see system_monitor_detail.hpp).
LogFormat
Log record encoding.
Definition system_monitor.hpp:73
@ JsonLines
One JSON object per line; missing values are JSON null.
@ Csv
Header row then one row per record; missing values are empty cells.
Definition acquisition_functions.hpp:16
std::string format_iso8601_utc(std::chrono::system_clock::time_point tp)
Formats tp as ISO-8601 UTC with milliseconds, e.g. "2026-10-02T12:34:56.789Z".
std::string sample_to_json(const SystemSample &sample)
Encodes sample as one JSON object (no trailing newline), the JSON Lines log record.
One GPU's readings within a SystemSample.
Definition system_monitor.hpp:27
std::optional< double > power_watts
Board/package power draw, watts.
Definition system_monitor.hpp:37
std::string name
Driver-reported name (NVML), or "AMD GPU <pci id> (<card>)" for sysfs devices.
Definition system_monitor.hpp:29
std::string vendor
"AMD" or "NVIDIA".
Definition system_monitor.hpp:30
int index
Position in SystemSample::gpus (AMD sysfs devices first, then NVML devices).
Definition system_monitor.hpp:28
std::optional< double > memory_total_bytes
Definition system_monitor.hpp:33
std::optional< double > memory_gtt_used_bytes
AMD only: GTT (system memory mapped for the GPU). On APUs this is where most allocations live.
Definition system_monitor.hpp:35
std::optional< double > temperature_c
Die/edge temperature, degrees Celsius.
Definition system_monitor.hpp:36
std::optional< double > utilization_percent
0-100, busy fraction of the GPU since the driver's last window.
Definition system_monitor.hpp:31
std::optional< double > memory_used_bytes
Dedicated memory (VRAM / APU carve-out) in use.
Definition system_monitor.hpp:32
Whether one metric can be read on this machine, and from where – or why not.
Definition system_monitor.hpp:66
std::string metric
e.g. "cpu_temperature_c", "gpu0.power_watts", "gpus".
Definition system_monitor.hpp:67
std::string detail
Source when available (e.g. "/proc/stat"); the reason when not.
Definition system_monitor.hpp:69
bool available
Definition system_monitor.hpp:68
Construction options.
Definition system_monitor.hpp:116
LogFormat format
Definition system_monitor.hpp:119
bool append
Definition system_monitor.hpp:122
std::string log_path
Log file; empty = no log.
Definition system_monitor.hpp:118
std::chrono::milliseconds interval
Sampling period of the background thread (> 0).
Definition system_monitor.hpp:117
std::size_t history_capacity
Ring-buffer size for history(); 0 keeps none.
Definition system_monitor.hpp:123
One point-in-time measurement of the host.
Definition system_monitor.hpp:48
std::optional< double > memory_used_bytes
System RAM in use (total - available).
Definition system_monitor.hpp:54
std::optional< double > cpu_utilization_percent
Definition system_monitor.hpp:51
double elapsed_seconds
Seconds since SystemMonitor::start() (or construction, before start()).
Definition system_monitor.hpp:50
std::optional< double > memory_total_bytes
System RAM capacity.
Definition system_monitor.hpp:55
std::optional< double > cpu_temperature_c
CPU package/die temperature, degrees Celsius.
Definition system_monitor.hpp:57
std::string label
Label set by the most recent SystemMonitor::mark().
Definition system_monitor.hpp:59
std::optional< double > process_cpu_percent
This process's CPU use, in percent of ONE logical CPU: a process saturating 8 cores reads ~800.
Definition system_monitor.hpp:53
std::optional< double > process_rss_bytes
This process's resident set / working set.
Definition system_monitor.hpp:56
std::vector< GpuSample > gpus
Every GPU detected (possibly empty).
Definition system_monitor.hpp:58
std::chrono::system_clock::time_point timestamp
Wall-clock time of the reading.
Definition system_monitor.hpp:49