MySQL 26.10.0
Source Code Documentation
system_info.h
Go to the documentation of this file.
1/* Copyright (c) 2026, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#pragma once
25
26#include <cassert>
27#include <chrono>
28#include <cstdint>
29#include <optional>
30#include <string>
31#include <string_view>
32#include <system_error>
33#include <utility>
34#include <vector>
35
36namespace mysql::system_info {
37
38/** State of one system information capability. */
40
41/**
42 Result of collecting one system information capability.
43
44 An available result contains one complete value. An unavailable result means
45 that the platform has no supported equivalent. A failed result means that
46 collection was attempted but failed.
47
48 @tparam T Collected capability type
49*/
50template <typename T>
52 public:
53 /** Construct an unavailable result. */
54 System_result() = default;
55
56 /**
57 Construct an available result.
58
59 @param value Complete capability value
60 @return Available result containing value
61 */
62 [[nodiscard]] static System_result success(T value) {
65 result.m_value.emplace(std::move(value));
66 return result;
67 }
68
69 /** @return An unavailable result. */
70 [[nodiscard]] static System_result unavailable() { return System_result{}; }
71
72 /**
73 Construct a failed result.
74
75 @param error Collection error
76 @return Failed result containing error
77 */
78 [[nodiscard]] static System_result failure(std::error_code error) {
81 result.m_error = error;
82 return result;
83 }
84
85 /** @return Current capability state. */
86 [[nodiscard]] Result_state state() const noexcept { return m_state; }
87
88 /** @return true if this result contains an available value. */
89 [[nodiscard]] bool has_value() const noexcept {
91 }
92
93 /**
94 Access the available value.
95
96 @pre has_value() is true.
97 */
98 [[nodiscard]] const T &value() const & {
99 assert(has_value());
100 return *m_value;
101 }
102
103 /**
104 Access the available value.
105
106 @pre has_value() is true.
107 */
108 [[nodiscard]] T &value() & {
109 assert(has_value());
110 return *m_value;
111 }
112
113 /**
114 Move the value out of an available temporary result.
115
116 @pre has_value() is true.
117 */
118 [[nodiscard]] T value() && {
119 assert(has_value());
120 return std::move(*m_value);
121 }
122
123 /**
124 Copy the value out of an available const temporary result.
125
126 @pre has_value() is true.
127 */
128 [[nodiscard]] T value() const && {
129 assert(has_value());
130 return *m_value;
131 }
132
133 /**
134 Access the collection error.
135
136 @pre state() is Result_state::failed.
137 */
138 [[nodiscard]] const std::error_code &error() const &noexcept {
139 assert(m_state == Result_state::failed);
140 return m_error;
141 }
142
143 /**
144 Move the error out of a failed temporary result.
145
146 @pre state() is Result_state::failed.
147 */
148 [[nodiscard]] std::error_code error() &&noexcept {
149 assert(m_state == Result_state::failed);
150 return std::move(m_error);
151 }
152
153 /**
154 Copy the error out of a failed const temporary result.
155
156 @pre state() is Result_state::failed.
157 */
158 [[nodiscard]] std::error_code error() const &&noexcept {
159 assert(m_state == Result_state::failed);
160 return m_error;
161 }
162
163 private:
164 std::optional<T> m_value;
165 std::error_code m_error;
167};
168
169/** Stable identity of the filesystem that contains a monitored path. */
171 std::string filesystem_id;
172 std::string mount_point;
173 std::string mount_source;
174 std::string filesystem_type;
175};
176
177/** Capacity and space available to unprivileged processes, in bytes. */
179 uint64_t capacity_bytes{0};
180 uint64_t available_bytes{0};
181};
182
183/** Filesystem identity and usage collected for one monitored path. */
187};
188
189/** Kind of storage device represented by an inventory entry. */
191 disk,
192 partition,
193 volume,
195 unknown
196};
197
198/** Identity and kind of one storage device. */
200 std::string name;
202};
203
204/** Storage devices visible at one collection point. */
206 std::vector<Storage_device> devices;
207};
208
209/** Capacity and hardware sector size of one storage device, in bytes. */
211 std::string device;
212 uint64_t capacity_bytes{0};
213 uint64_t sector_size_bytes{0};
214};
215
216/** Storage device capacities collected at one collection point. */
218 std::vector<Storage_device_capacity> devices;
219};
220
221/** Child and parent relationship between two storage devices. */
223 std::string device;
224 std::string parent_device;
225};
226
227/** Storage device relationships collected at one collection point. */
229 std::vector<Storage_device_relationship> relationships;
230};
231
232/** Cumulative read and write counters for one storage device. */
234 std::string device;
235 uint64_t read_count{0};
236 uint64_t read_bytes{0};
238 uint64_t write_count{0};
239 uint64_t write_bytes{0};
241};
242
243/** Storage read and write counters collected at one collection point. */
245 std::vector<Storage_read_write_counters> devices;
246};
247
248/** Cumulative flush counters for one storage device. */
250 std::string device;
251 uint64_t flush_count{0};
253};
254
255/** Storage flush counters collected at one collection point. */
257 std::vector<Storage_flush_counters> devices;
258};
259
260/** Storage capabilities collected at one collection point. */
267};
268
269/** Portable host physical memory values, in bytes. */
271 uint64_t total_bytes{0};
272 uint64_t free_bytes{0};
273 uint64_t available_bytes{0};
274};
275
276/** Optional host memory breakdown values, in bytes. */
278 uint64_t buffer_bytes{0};
279 uint64_t cache_bytes{0};
280 uint64_t slab_bytes{0};
281};
282
283/** Host swap capacity values, in bytes. */
285 uint64_t total_bytes{0};
286 uint64_t free_bytes{0};
287};
288
289/** Cumulative host swap activity, in bytes. */
291 uint64_t bytes_in{0};
292 uint64_t bytes_out{0};
293};
294
295/** Host memory capabilities collected at one collection point. */
301};
302
303/** Portable cumulative CPU times for one aggregate or logical CPU. */
304struct Cpu_times {
305 std::string cpu;
310};
311
312/** Portable CPU times collected at one collection point. */
314 std::vector<Cpu_times> cpus;
315};
316
317/** Optional cumulative CPU times without portable equivalents. */
319 std::string cpu;
326};
327
328/** Extended CPU times collected at one collection point. */
330 std::vector<Cpu_extended_times> cpus;
331};
332
333/** Host CPU capabilities collected at one collection point. */
337};
338
339/** Identity of the current process. */
341 uint64_t pid{0};
342 std::string name;
343};
344
345/** Resident memory of the current process, in bytes. */
347 uint64_t resident_bytes{0};
348};
349
350/** Optional memory details of the current process, in bytes. */
352 uint64_t data_bytes{0};
353 uint64_t swap_bytes{0};
354};
355
356/** Cumulative major page faults of the current process. */
358 uint64_t major_faults{0};
359};
360
361/** Process memory capabilities collected at one collection point. */
367};
368
369/** Portable execution state of a process thread. */
370enum class Thread_state {
371 running,
372 sleeping,
373 waiting,
374 stopped,
375 zombie,
376 unknown
377};
378
379/** Identity, name and state of one process thread. */
381 uint64_t tid{0};
382 std::string name;
384};
385
386/** Process threads visible at one collection point. */
388 std::vector<Thread_identity> threads;
389};
390
391/** Process-wide runtime values for the current process. */
393 uint32_t thread_count{0};
394 uint64_t virtual_bytes{0};
395 uint64_t resident_bytes{0};
397};
398
399/** Portable cumulative CPU times for one process thread. */
401 uint64_t tid{0};
404};
405
406/** Portable thread CPU times collected at one collection point. */
408 std::vector<Thread_cpu_times> threads;
409};
410
411/** Optional cumulative CPU times for one process thread. */
413 uint64_t tid{0};
418};
419
420/** Extended thread CPU times collected at one collection point. */
422 std::vector<Thread_extended_cpu_times> threads;
423};
424
425/** Optional scheduler values for one process thread. */
427 uint64_t tid{0};
428 uint32_t last_cpu{0};
430};
431
432/** Thread scheduler values collected at one collection point. */
434 std::vector<Thread_scheduler_info> threads;
435};
436
437/** Cumulative I/O byte counters for one process thread. */
439 uint64_t tid{0};
440 uint64_t read_bytes{0};
441 uint64_t write_bytes{0};
442};
443
444/** Thread I/O counters collected at one collection point. */
446 std::vector<Thread_io_counters> threads;
447};
448
449/** Process thread capabilities collected at one collection point. */
458};
459
460/**
461 Collect identity and usage for the filesystem containing a path.
462
463 @param path Path whose filesystem is queried
464 @return Filesystem capability results
465*/
466[[nodiscard]] Filesystem_snapshot query_filesystem(std::string_view path);
467
468/** @return Storage capabilities collected at one collection point. */
470
471/** @return Host memory capabilities collected at one collection point. */
473
474/** @return Host CPU capabilities collected at one collection point. */
475[[nodiscard]] Host_cpu_snapshot query_host_cpu();
476
477/** @return Current process memory capabilities. */
479
480/** @return Current process thread capabilities. */
482
483} // namespace mysql::system_info
Result of collecting one system information capability.
Definition: system_info.h:51
static System_result unavailable()
Definition: system_info.h:70
const T & value() const &
Access the available value.
Definition: system_info.h:98
std::optional< T > m_value
Definition: system_info.h:164
System_result()=default
Construct an unavailable result.
bool has_value() const noexcept
Definition: system_info.h:89
T value() &&
Move the value out of an available temporary result.
Definition: system_info.h:118
Result_state m_state
Definition: system_info.h:166
Result_state state() const noexcept
Definition: system_info.h:86
T & value() &
Access the available value.
Definition: system_info.h:108
std::error_code m_error
Definition: system_info.h:165
std::error_code error() &&noexcept
Move the error out of a failed temporary result.
Definition: system_info.h:148
const std::error_code & error() const &noexcept
Access the collection error.
Definition: system_info.h:138
std::error_code error() const &&noexcept
Copy the error out of a failed const temporary result.
Definition: system_info.h:158
static System_result success(T value)
Construct an available result.
Definition: system_info.h:62
T value() const &&
Copy the value out of an available const temporary result.
Definition: system_info.h:128
static System_result failure(std::error_code error)
Construct a failed result.
Definition: system_info.h:78
#define T
Definition: jit_executor_value.cc:373
static char * path
Definition: mysqldump.cc:153
std::chrono::milliseconds milliseconds
Definition: authorize_manager.cc:70
Definition: system_info_linux.cc:46
Host_cpu_snapshot query_host_cpu()
Definition: system_info.cc:306
Thread_state
Portable execution state of a process thread.
Definition: system_info.h:370
Filesystem_snapshot query_filesystem(std::string_view path)
Collect identity and usage for the filesystem containing a path.
Definition: system_info.cc:141
Process_threads_snapshot query_process_threads()
Definition: system_info.cc:388
Result_state
State of one system information capability.
Definition: system_info.h:39
Storage_device_kind
Kind of storage device represented by an inventory entry.
Definition: system_info.h:190
Storage_snapshot query_storage_devices()
Definition: system_info.cc:247
Host_memory_snapshot query_host_memory()
Definition: system_info.cc:272
Process_memory_snapshot query_process_memory()
Definition: system_info.cc:323
noexcept
The return type for any call_and_catch(f, args...) call where f(args...) returns Type.
Definition: call_and_catch.h:76
struct result result
Definition: result.h:34
Extended CPU times collected at one collection point.
Definition: system_info.h:329
std::vector< Cpu_extended_times > cpus
Definition: system_info.h:330
Optional cumulative CPU times without portable equivalents.
Definition: system_info.h:318
std::chrono::milliseconds guest_nice
Definition: system_info.h:325
std::chrono::milliseconds irq
Definition: system_info.h:321
std::chrono::milliseconds soft_irq
Definition: system_info.h:322
std::chrono::milliseconds io_wait
Definition: system_info.h:320
std::chrono::milliseconds guest
Definition: system_info.h:324
std::chrono::milliseconds steal
Definition: system_info.h:323
std::string cpu
Definition: system_info.h:319
Portable CPU times collected at one collection point.
Definition: system_info.h:313
std::vector< Cpu_times > cpus
Definition: system_info.h:314
Portable cumulative CPU times for one aggregate or logical CPU.
Definition: system_info.h:304
std::chrono::milliseconds nice
Definition: system_info.h:307
std::chrono::milliseconds idle
Definition: system_info.h:309
std::chrono::milliseconds user
Definition: system_info.h:306
std::chrono::milliseconds system
Definition: system_info.h:308
std::string cpu
Definition: system_info.h:305
Stable identity of the filesystem that contains a monitored path.
Definition: system_info.h:170
std::string mount_point
Definition: system_info.h:172
std::string filesystem_id
Definition: system_info.h:171
std::string mount_source
Definition: system_info.h:173
std::string filesystem_type
Definition: system_info.h:174
Filesystem identity and usage collected for one monitored path.
Definition: system_info.h:184
System_result< Filesystem_usage > usage
Definition: system_info.h:186
System_result< Filesystem_identity > identity
Definition: system_info.h:185
Capacity and space available to unprivileged processes, in bytes.
Definition: system_info.h:178
uint64_t capacity_bytes
Definition: system_info.h:179
uint64_t available_bytes
Definition: system_info.h:180
Host CPU capabilities collected at one collection point.
Definition: system_info.h:334
System_result< Cpu_extended_snapshot > extended_times
Definition: system_info.h:336
System_result< Cpu_times_snapshot > times
Definition: system_info.h:335
Optional host memory breakdown values, in bytes.
Definition: system_info.h:277
uint64_t cache_bytes
Definition: system_info.h:279
uint64_t slab_bytes
Definition: system_info.h:280
uint64_t buffer_bytes
Definition: system_info.h:278
Portable host physical memory values, in bytes.
Definition: system_info.h:270
uint64_t free_bytes
Definition: system_info.h:272
uint64_t total_bytes
Definition: system_info.h:271
uint64_t available_bytes
Definition: system_info.h:273
Host memory capabilities collected at one collection point.
Definition: system_info.h:296
System_result< Swap_capacity_info > swap_capacity
Definition: system_info.h:299
System_result< Host_memory_breakdown > breakdown
Definition: system_info.h:298
System_result< Swap_activity_info > swap_activity
Definition: system_info.h:300
System_result< Host_memory_info > memory
Definition: system_info.h:297
Identity of the current process.
Definition: system_info.h:340
uint64_t pid
Definition: system_info.h:341
std::string name
Definition: system_info.h:342
Optional memory details of the current process, in bytes.
Definition: system_info.h:351
uint64_t swap_bytes
Definition: system_info.h:353
uint64_t data_bytes
Definition: system_info.h:352
Resident memory of the current process, in bytes.
Definition: system_info.h:346
uint64_t resident_bytes
Definition: system_info.h:347
Process memory capabilities collected at one collection point.
Definition: system_info.h:362
System_result< Process_memory_residency > residency
Definition: system_info.h:364
System_result< Process_identity > identity
Definition: system_info.h:363
System_result< Process_memory_details > details
Definition: system_info.h:365
System_result< Process_page_faults > page_faults
Definition: system_info.h:366
Cumulative major page faults of the current process.
Definition: system_info.h:357
uint64_t major_faults
Definition: system_info.h:358
Process-wide runtime values for the current process.
Definition: system_info.h:392
uint64_t resident_bytes
Definition: system_info.h:395
uint32_t thread_count
Definition: system_info.h:393
uint64_t virtual_bytes
Definition: system_info.h:394
uint64_t resident_limit_bytes
Definition: system_info.h:396
Process thread capabilities collected at one collection point.
Definition: system_info.h:450
System_result< Thread_scheduler_snapshot > scheduler
Definition: system_info.h:456
System_result< Thread_extended_cpu_snapshot > extended_cpu
Definition: system_info.h:455
System_result< Thread_io_snapshot > io
Definition: system_info.h:457
System_result< Process_identity > identity
Definition: system_info.h:451
System_result< Thread_cpu_snapshot > cpu
Definition: system_info.h:454
System_result< Process_runtime_info > runtime
Definition: system_info.h:453
System_result< Thread_inventory > threads
Definition: system_info.h:452
Storage device capacities collected at one collection point.
Definition: system_info.h:217
std::vector< Storage_device_capacity > devices
Definition: system_info.h:218
Capacity and hardware sector size of one storage device, in bytes.
Definition: system_info.h:210
std::string device
Definition: system_info.h:211
uint64_t capacity_bytes
Definition: system_info.h:212
uint64_t sector_size_bytes
Definition: system_info.h:213
Child and parent relationship between two storage devices.
Definition: system_info.h:222
std::string parent_device
Definition: system_info.h:224
std::string device
Definition: system_info.h:223
Identity and kind of one storage device.
Definition: system_info.h:199
std::string name
Definition: system_info.h:200
Storage_device_kind kind
Definition: system_info.h:201
Cumulative flush counters for one storage device.
Definition: system_info.h:249
uint64_t flush_count
Definition: system_info.h:251
std::chrono::milliseconds flush_time
Definition: system_info.h:252
std::string device
Definition: system_info.h:250
Storage flush counters collected at one collection point.
Definition: system_info.h:256
std::vector< Storage_flush_counters > devices
Definition: system_info.h:257
Storage device relationships collected at one collection point.
Definition: system_info.h:228
std::vector< Storage_device_relationship > relationships
Definition: system_info.h:229
Storage devices visible at one collection point.
Definition: system_info.h:205
std::vector< Storage_device > devices
Definition: system_info.h:206
Cumulative read and write counters for one storage device.
Definition: system_info.h:233
uint64_t read_count
Definition: system_info.h:235
uint64_t write_bytes
Definition: system_info.h:239
std::chrono::milliseconds write_time
Definition: system_info.h:240
uint64_t write_count
Definition: system_info.h:238
uint64_t read_bytes
Definition: system_info.h:236
std::string device
Definition: system_info.h:234
std::chrono::milliseconds read_time
Definition: system_info.h:237
Storage read and write counters collected at one collection point.
Definition: system_info.h:244
std::vector< Storage_read_write_counters > devices
Definition: system_info.h:245
Storage capabilities collected at one collection point.
Definition: system_info.h:261
System_result< Storage_read_write_snapshot > read_write
Definition: system_info.h:265
System_result< Storage_hierarchy > hierarchy
Definition: system_info.h:264
System_result< Storage_inventory > inventory
Definition: system_info.h:262
System_result< Storage_capacities > capacities
Definition: system_info.h:263
System_result< Storage_flush_snapshot > flush
Definition: system_info.h:266
Cumulative host swap activity, in bytes.
Definition: system_info.h:290
uint64_t bytes_out
Definition: system_info.h:292
uint64_t bytes_in
Definition: system_info.h:291
Host swap capacity values, in bytes.
Definition: system_info.h:284
uint64_t total_bytes
Definition: system_info.h:285
uint64_t free_bytes
Definition: system_info.h:286
Portable thread CPU times collected at one collection point.
Definition: system_info.h:407
std::vector< Thread_cpu_times > threads
Definition: system_info.h:408
Portable cumulative CPU times for one process thread.
Definition: system_info.h:400
uint64_t tid
Definition: system_info.h:401
std::chrono::milliseconds system
Definition: system_info.h:403
std::chrono::milliseconds user
Definition: system_info.h:402
Extended thread CPU times collected at one collection point.
Definition: system_info.h:421
std::vector< Thread_extended_cpu_times > threads
Definition: system_info.h:422
Optional cumulative CPU times for one process thread.
Definition: system_info.h:412
std::chrono::milliseconds guest
Definition: system_info.h:416
std::chrono::milliseconds child_guest
Definition: system_info.h:417
std::chrono::milliseconds child_user
Definition: system_info.h:414
std::chrono::milliseconds child_system
Definition: system_info.h:415
uint64_t tid
Definition: system_info.h:413
Identity, name and state of one process thread.
Definition: system_info.h:380
uint64_t tid
Definition: system_info.h:381
std::string name
Definition: system_info.h:382
Thread_state state
Definition: system_info.h:383
Process threads visible at one collection point.
Definition: system_info.h:387
std::vector< Thread_identity > threads
Definition: system_info.h:388
Cumulative I/O byte counters for one process thread.
Definition: system_info.h:438
uint64_t tid
Definition: system_info.h:439
uint64_t read_bytes
Definition: system_info.h:440
uint64_t write_bytes
Definition: system_info.h:441
Thread I/O counters collected at one collection point.
Definition: system_info.h:445
std::vector< Thread_io_counters > threads
Definition: system_info.h:446
Optional scheduler values for one process thread.
Definition: system_info.h:426
std::chrono::milliseconds block_io_delay
Definition: system_info.h:429
uint32_t last_cpu
Definition: system_info.h:428
uint64_t tid
Definition: system_info.h:427
Thread scheduler values collected at one collection point.
Definition: system_info.h:433
std::vector< Thread_scheduler_info > threads
Definition: system_info.h:434
Definition: result.h:30