MySQL 26.10.0
Source Code Documentation
mysql::system_info::internal Namespace Reference

Namespaces

namespace  anonymous_namespace{system_info_linux.cc}
 
namespace  anonymous_namespace{system_info_linux_procfs.cc}
 
namespace  anonymous_namespace{system_info_macos.cc}
 

Classes

struct  Linux_block_device
 Linux block device identity parsed from /proc/partitions. More...
 
struct  Linux_diskstats_snapshot
 Linux storage I/O capabilities parsed from /proc/diskstats. More...
 
struct  Linux_storage_paths
 Linux procfs and sysfs roots used by storage collection. More...
 
struct  macOS_thread_deallocator
 Callbacks used to release native macOS thread resources. More...
 
class  macOS_thread_resources
 Own native thread ports and the Mach allocated thread array. More...
 
struct  macOS_thread_sample
 Native macOS values collected for one thread. More...
 

Enumerations

enum class  macOS_thread_sample_state { complete , disappeared }
 Result of collecting one native macOS thread. More...
 

Functions

Storage_snapshot query_storage_devices_platform ()
 Collect Linux storage device metadata from procfs and sysfs. More...
 
Host_memory_snapshot query_host_memory_platform ()
 Collect Linux host memory from procfs. More...
 
Host_cpu_snapshot query_host_cpu_platform ()
 Collect cumulative Linux CPU times from /proc/stat. More...
 
Process_memory_snapshot query_process_memory_platform ()
 Collect Linux process memory metadata. More...
 
Process_threads_snapshot query_process_threads_platform ()
 Collect Linux thread metadata for the current process. More...
 
bool valid_linux_storage_device_name (std::string_view name)
 Check that a Linux device name is one safe path component. More...
 
System_result< std::vector< Linux_block_device > > read_linux_partitions (std::istream &input)
 Read the block device identity table from /proc/partitions. More...
 
System_result< Storage_device_capacity > read_linux_storage_capacity (std::istream &size_input, std::istream &sector_size_input, std::string_view device)
 Read capacity metadata from /sys/class/block/<device>. More...
 
System_result< Storage_device_relationship > linux_partition_relationship (std::string_view canonical_path, std::string_view device)
 Find the parent disk of a Linux partition from its canonical sysfs path. More...
 
System_result< std::string > linux_storage_sector_size_path (std::string_view canonical_path, bool partition)
 Build the sysfs path for a device's hardware sector size. More...
 
Linux_diskstats_snapshot read_linux_diskstats (std::istream &input, const std::unordered_set< std::string > &whole_devices)
 Read cumulative block I/O counters from /proc/diskstats. More...
 
Storage_snapshot query_linux_storage_devices (const Linux_storage_paths &paths, const std::function< void()> &after_metadata)
 Assemble Linux storage metadata from procfs and sysfs. More...
 
System_result< Filesystem_identity > read_linux_mount_info (std::istream &input, std::string_view device_id, std::string_view target_path)
 Find a filesystem in /proc/self/mountinfo. More...
 
Host_memory_snapshot read_linux_meminfo (std::istream &input)
 Read labeled host memory values from /proc/meminfo. More...
 
System_result< Swap_activity_info > read_linux_vmstat (std::istream &input)
 Read cumulative paging activity from /proc/vmstat. More...
 
Host_cpu_snapshot read_linux_cpu_stat (std::istream &input, uint64_t ticks_per_second)
 Read CPU time rows from /proc/stat. More...
 
Process_memory_snapshot read_linux_process_status (std::istream &input)
 Read process identity and memory from /proc/self/status. More...
 
Process_threads_snapshot read_linux_thread_stat (std::istream &input, uint64_t expected_tid, uint64_t process_pid, uint64_t ticks_per_second, uint64_t page_size)
 Read one /proc/self/task/<tid>/stat record. More...
 
System_result< Thread_io_counters > read_linux_thread_io (std::istream &input, uint64_t tid)
 Read /proc/self/task/<tid>/io. More...
 
std::error_code mach_error_code (int error)
 Convert a Mach return code to std::error_code. More...
 
Thread_state macos_thread_state (int run_state)
 Map a native Mach thread state to the portable thread state. More...
 
bool macos_time_value_to_milliseconds (int64_t seconds, int64_t microseconds, std::chrono::milliseconds &milliseconds)
 Convert a Mach time_value_t value to whole milliseconds. More...
 
std::string copy_bounded_macos_thread_name (const char *name, size_t size)
 Copy a thread name from a fixed size native buffer. More...
 
std::error_code map_macos_thread_samples (std::vector< macOS_thread_sample > samples, std::error_code disappearance_error, Thread_inventory &inventory, Thread_cpu_snapshot &cpu)
 Build matching thread inventory and CPU snapshots from native samples. More...
 
void complete_macos_thread_collection (macOS_thread_resources &resources, std::error_code collection_error, Thread_inventory inventory, Thread_cpu_snapshot cpu, Process_threads_snapshot &result)
 Release native thread resources before publishing the collected snapshots. More...
 
bool cpu_ticks_to_milliseconds (uint64_t ticks, uint64_t ticks_per_second, std::chrono::milliseconds &milliseconds)
 Convert cumulative CPU ticks to whole milliseconds. More...
 
Filesystem_snapshot validate_filesystem_snapshot (Filesystem_snapshot snapshot)
 Reject invalid available filesystem usage values. More...
 
Storage_snapshot validate_storage_snapshot (Storage_snapshot snapshot)
 Reject invalid available storage device values. More...
 
Host_memory_snapshot validate_host_memory_snapshot (Host_memory_snapshot snapshot)
 Reject invalid available host memory values. More...
 
Host_cpu_snapshot validate_host_cpu_snapshot (Host_cpu_snapshot snapshot)
 Reject invalid available host CPU values. More...
 
Process_memory_snapshot validate_process_memory_snapshot (Process_memory_snapshot snapshot)
 Reject invalid available process identity values. More...
 
Process_threads_snapshot validate_process_threads_snapshot (Process_threads_snapshot snapshot)
 Reject invalid available process thread values. More...
 
std::error_code errno_code ()
 Return the current errno value in the generic error category. More...
 
bool multiply_overflows (uint64_t lhs, uint64_t rhs)
 Return true if multiplying two unsigned 64-bit values would overflow. More...
 
bool add_overflows (uint64_t lhs, uint64_t rhs)
 Return true if adding two unsigned 64-bit values would overflow. More...
 

Variables

Filesystem_snapshot query_filesystem_platform (std::string_view path)
 Collect Linux filesystem identity and space metadata for one path. More...
 

Enumeration Type Documentation

◆ macOS_thread_sample_state

Result of collecting one native macOS thread.

Enumerator
complete 
disappeared 

Function Documentation

◆ add_overflows()

bool mysql::system_info::internal::add_overflows ( uint64_t  lhs,
uint64_t  rhs 
)
inline

Return true if adding two unsigned 64-bit values would overflow.

◆ complete_macos_thread_collection()

void mysql::system_info::internal::complete_macos_thread_collection ( macOS_thread_resources &  resources,
std::error_code  collection_error,
Thread_inventory  inventory,
Thread_cpu_snapshot  cpu,
Process_threads_snapshot &  result 
)

Release native thread resources before publishing the collected snapshots.

Release native resources and publish only after successful cleanup.

A cleanup error takes precedence over a collection error. The threads and cpu capabilities succeed together only after collection, mapping and cleanup all succeed.

◆ copy_bounded_macos_thread_name()

std::string mysql::system_info::internal::copy_bounded_macos_thread_name ( const char *  name,
size_t  size 
)

Copy a thread name from a fixed size native buffer.

Copy a possibly unterminated native thread name without exceeding size.

Stop at the first null byte. If no null byte is present, copy the complete buffer without reading beyond it.

◆ cpu_ticks_to_milliseconds()

bool mysql::system_info::internal::cpu_ticks_to_milliseconds ( uint64_t  ticks,
uint64_t  ticks_per_second,
std::chrono::milliseconds &  milliseconds 
)

Convert cumulative CPU ticks to whole milliseconds.

Parameters
[in]ticksCumulative CPU ticks
[in]ticks_per_secondNumber of CPU ticks per second
[out]millisecondsConverted whole milliseconds, unchanged on error
Return values
falseSuccess
trueError

◆ errno_code()

std::error_code mysql::system_info::internal::errno_code ( )
inline

Return the current errno value in the generic error category.

◆ linux_partition_relationship()

System_result< Storage_device_relationship > mysql::system_info::internal::linux_partition_relationship ( std::string_view  canonical_path,
std::string_view  device 
)

Find the parent disk of a Linux partition from its canonical sysfs path.

Resolve a partition relationship from its canonical sysfs path.

/sys/class/block/<device> is normally a symbolic link. A canonical path resolves symbolic links and removes . and .. elements.

The resolved path places a partition directly below its parent disk. For example, a path ending in /sda/sda1 identifies sda1 as a partition of sda.

Return a failed result if the device name or path is invalid, or if the path does not identify a different parent device.

◆ linux_storage_sector_size_path()

System_result< std::string > mysql::system_info::internal::linux_storage_sector_size_path ( std::string_view  canonical_path,
bool  partition 
)

Build the sysfs path for a device's hardware sector size.

Select the device queue attribute used for hardware sector size.

A non-partition block device (aka whole device) exposes this value in queue/hw_sector_size below its sysfs directory. A partition has no separate queue directory, so the path uses the parent disk's directory before appending queue/hw_sector_size.

Return a failed result if the canonical path is empty or does not end in a valid device name.

◆ mach_error_code()

std::error_code mysql::system_info::internal::mach_error_code ( int  error)

Convert a Mach return code to std::error_code.

◆ macos_thread_state()

Thread_state mysql::system_info::internal::macos_thread_state ( int  run_state)

Map a native Mach thread state to the portable thread state.

Map a macOS native thread run state to the public thread state.

Mach state Thread_state


TH_STATE_RUNNING running TH_STATE_WAITING sleeping TH_STATE_UNINTERRUPTIBLE waiting TH_STATE_STOPPED stopped TH_STATE_HALTED stopped any other value unknown

◆ macos_time_value_to_milliseconds()

bool mysql::system_info::internal::macos_time_value_to_milliseconds ( int64_t  seconds,
int64_t  microseconds,
std::chrono::milliseconds &  milliseconds 
)

Convert a Mach time_value_t value to whole milliseconds.

Convert a macOS time value to whole milliseconds.

Microseconds must be in the range 0 through 999999. The conversion discards any fraction smaller than one millisecond. The output remains unchanged if a component is negative or the converted value would overflow.

◆ map_macos_thread_samples()

std::error_code mysql::system_info::internal::map_macos_thread_samples ( std::vector< macOS_thread_sample >  samples,
std::error_code  disappearance_error,
Thread_inventory &  inventory,
Thread_cpu_snapshot &  cpu 
)

Build matching thread inventory and CPU snapshots from native samples.

Build aligned thread inventory and CPU snapshots from native samples.

Samples for threads that disappeared during collection are omitted. The remaining samples are sorted by thread ID so both snapshots use the same stable order. Every thread must have a nonzero unique ID and valid user and system CPU times.

The output snapshots remain unchanged on failure. If every enumerated thread disappeared, return the recorded Mach error.

◆ multiply_overflows()

bool mysql::system_info::internal::multiply_overflows ( uint64_t  lhs,
uint64_t  rhs 
)
inline

Return true if multiplying two unsigned 64-bit values would overflow.

◆ query_host_cpu_platform()

Host_cpu_snapshot mysql::system_info::internal::query_host_cpu_platform ( )

Collect cumulative Linux CPU times from /proc/stat.

Collect host CPU information for the active platform.

Collect cumulative CPU times from Mach PROCESSOR_CPU_LOAD_INFO.

Capability Fields


times user, nice, system and idle extended_times iowait, irq, softirq, steal, guest and guest_nice

Linux reports these values in clock ticks for the aggregate cpu row and each logical processor. _SC_CLK_TCK supplies the number of ticks per second so the parser can convert each counter to milliseconds.

The macOS processor record provides the four portable CPU times but no values with the same semantics as the Linux extended fields.

Field Cpu_times value


CPU_STATE_USER Time spent running user code CPU_STATE_NICE Time spent running low priority user code CPU_STATE_SYSTEM Time spent running kernel code CPU_STATE_IDLE Idle time

host_processor_info() returns one processor_cpu_load_info record for each logical processor. Each field is a cumulative clock tick count. The values are converted to milliseconds with _SC_CLK_TCK.

The collector sums each field to produce the leading cpu record, followed by cpu0, cpu1 and the remaining logical processors. Mach allocates the returned array, so it must be released with vm_deallocate() before the snapshot is published.

PROCESSOR_CPU_LOAD_INFO has no counters that match the extended CPU capability, so extended_times remains unavailable.

◆ query_host_memory_platform()

Host_memory_snapshot mysql::system_info::internal::query_host_memory_platform ( )

Collect Linux host memory from procfs.

Collect host memory information for the active platform.

Collect macOS host memory from sysctl and Mach records.

Capability Linux source and fields


memory /proc/meminfo: MemTotal, MemFree and MemAvailable breakdown /proc/meminfo: Buffers, Cached and Slab swap_capacity /proc/meminfo: SwapTotal and SwapFree swap_activity /proc/vmstat: pgpgin and pgpgout

Linux provides the memory breakdown and paging counters that have no direct mapping in the macOS implementation. Values from /proc/meminfo are parsed as independent capabilities, but an error reading the file fails all three. /proc/vmstat is read separately, so its result is independent of the memory and swap capacity results.

Source and field Contents


hw.memsize Physical memory in bytes HOST_VM_INFO64 free_count Free memory pages HOST_VM_INFO64 inactive_count Inactive memory pages host_page_size() Size of one memory page in bytes vm.swapusage xsu_total Total swap space in bytes vm.swapusage xsu_used Used swap space in bytes

Free memory is free_count * page_size. Here, available memory is defined as (free_count + inactive_count) * page_size. Unlike Linux MemAvailable, this is a simple sum of two page counts.

Linux reads the memory breakdown from Buffers, Cached and Slab in /proc/meminfo. It reads paging activity from pgpgin and pgpgout in /proc/vmstat. The macOS records used here do not provide values with matching semantics, so the breakdown and swap_activity capabilities remain unavailable.

The memory and swap_capacity capabilities use independent macOS queries, so the failure of one does not prevent collection of the other.

◆ query_linux_storage_devices()

Storage_snapshot mysql::system_info::internal::query_linux_storage_devices ( const Linux_storage_paths &  paths,
const std::function< void()> &  after_metadata 
)

Assemble Linux storage metadata from procfs and sysfs.

Assemble Linux storage capabilities from the supplied proc and sys roots.

How the snapshot is assembled:

  • Device names and major:minor device numbers come from /proc/partitions.
  • Entries in /sys/class/block are joined by device name.
  • A partition attribute marks a partition, and the sysfs path places it below its parent disk.
  • The size and hw_sector_size attributes provide capacity metadata.
  • /proc/diskstats is joined by device name to add I/O counters.

Devices can disappear while these files are read. An entry that vanishes is omitted. Invalid metadata or an I/O error causes the capability to fail.

◆ query_process_memory_platform()

Process_memory_snapshot mysql::system_info::internal::query_process_memory_platform ( )

Collect Linux process memory metadata.

Collect process memory information for the active platform.

Collect macOS process memory from a libproc task record.

Capability Linux source and fields


identity /proc/self/status: Name and Pid residency /proc/self/status: VmRSS details /proc/self/status: VmData and VmSwap page_faults getrusage(): ru_majflt

Linux provides process data and swap values in /proc/self/status. The macOS process record used by this library provides resident memory but no values with the same semantics for those details.

The status file and getrusage() are independent queries. Failure of one does not prevent collection of the other.

Source and field Contents


proc_name() Process name getpid() Process ID PROC_PIDTASKINFO pti_resident_size Resident memory in bytes

proc_pidinfo(PROC_PIDTASKINFO) fills a proc_taskinfo record. The record contains other memory and fault counters, but they do not provide the public data memory, swapped memory or major page fault values, so the details and page_faults capabilties are unavailable.

Identity and residency are collected independently.

◆ query_process_threads_platform()

Process_threads_snapshot mysql::system_info::internal::query_process_threads_platform ( )

Collect Linux thread metadata for the current process.

Collect process thread information for the active platform.

Collect current process thread metadata from Mach thread records.

Source Contents


/proc/self/status Process identity /proc/self/task/<tid> Candidate thread IDs /proc/self/task/<tid>/stat Name, state, CPU, scheduler and runtime /proc/self/task/<tid>/io Thread I/O counters sysconf(_SC_CLK_TCK) Clock ticks per second sysconf(_SC_PAGESIZE) Memory page size in bytes

Linux exposes thread metadata as procfs records. In contrast, macOS returns thread ports from task_threads() and reads their metadata with thread_info().

A thread can exit after its directory is enumerated and before either file is read. A missing file omits that thread because this is a normal removal race. Other read errors fail the capabilities that depend on the file.

Each capability represents one consistent set of sampled threads. If a required record is invalid for any retained thread, that capability fails rather than returning a partial set.

Source Field used


task_threads() Thread port array and thread count THREAD_IDENTIFIER_INFO 64-bit thread_id THREAD_EXTENDED_INFO Fixed size pth_name buffer THREAD_BASIC_INFO run_state THREAD_BASIC_INFO user_time seconds and microseconds THREAD_BASIC_INFO system_time seconds and microseconds

task_threads() returns a Mach allocated array of thread send rights. Each right is queried with the three thread_info() flavors above.

CPU times are converted to whole milliseconds.

A thread can exit between enumeration and a thread_info() call. Such a thread is omitted when at least one valid thread remains.

For any other Mach errors, the threads and cpu capabilities will fail.

Every thread right and the allocated array must be released before the snapshots are published.

The runtime, extended CPU, scheduler and thread I/O capabilities are not available in this implementation. Process identity is collected independently.

The count supplied for each thread_info() flavor is measured in natural_t elements and must match the complete native record.

Enumerate the threads in the current process.

How it works:

  • task_threads() returns an array of thread ports and the number of entries.
  • Each port gives the caller a 'send right' to use with thread_info().
  • The caller must release each send right with mach_port_deallocate() and release the separately allocated array with vm_deallocate().

Releasing these resources drops only the caller's references. It does not stop or otherwise change the threads.

Enumerate the threads in the current process.

How it works:

  • task_threads() returns an array of thread ports and the number of entries.
  • Each port gives the caller a 'send right' to use with thread_info().
  • The caller must release each send right with mach_port_deallocate() and release the separately allocated array with vm_deallocate().

Releasing these resources drops only the caller's references. It does not stop or otherwise change the threads.

◆ query_storage_devices_platform()

Storage_snapshot mysql::system_info::internal::query_storage_devices_platform ( )

Collect Linux storage device metadata from procfs and sysfs.

Collect storage device information for the active platform.

Report macOS storage device capabilities as unavailable.

Source Capabilities


/proc/partitions inventory /sys/class/block capacities and hierarchy /proc/diskstats read_write and flush

query_linux_storage_devices() joins these records by device name. It also accounts for devices that disappear while the sources are being read.

statfs() provides mounted filesystem data. On Linux, procfs and sysfs also provide a storage device inventory, partition relationships and cumulative block I/O counters.

However, statfs() does not provide equivalent macOS data, so this library does not create storage device records from filesystem metadata.

◆ read_linux_cpu_stat()

Host_cpu_snapshot mysql::system_info::internal::read_linux_cpu_stat ( std::istream &  input,
uint64_t  ticks_per_second 
)

Read CPU time rows from /proc/stat.

Read host CPU capabilities from Linux stat input.

Kernel system statistics, CPU-specific stats. Fields in order. Values converted from clock ticks to milliseconds. 1 user - Time in user mode 2 nice - Time in niced user mode 3 system - Time in system mode 4 idle - Time in the idle task 5 iowait - Time waiting for I/O to complete 6 irq - Time servicing interrupts 7 softirqs - Time servicing softirqs 8 steal - Stolen time 9 guest - Time spent running a virtual CPU 10 guest_nice - Time spent running a niced guest

See https://man7.org/linux/man-pages/man5/proc_stat.5.html

The aggregate row is labeled cpu, per-CPU rows are labeled cpu0, cpu1 and so on. Values after the label are cumulative clock ticks in this order:

user nice system idle iowait irq softirq steal guest guest_nice
  • The first four fields form the portable CPU snapshot. The remaining six form the Linux extended snapshot.
  • All values are converted to milliseconds with the _SC_CLK_TCK value supplied by the caller.
  • Other /proc/stat rows are outside this reader and are ignored.
  • Linux includes guest time in user and guest-nice time in nice, so the reader preserves those kernel counters without subtracting the guest fields.

◆ read_linux_diskstats()

Linux_diskstats_snapshot mysql::system_info::internal::read_linux_diskstats ( std::istream &  input,
const std::unordered_set< std::string > &  whole_devices 
)

Read cumulative block I/O counters from /proc/diskstats.

Read Linux block device I/O capabilities from diskstats input.

Read, write and flush counters for each block device. Fields in order. Sectors converted to bytes. 1 Major number 2 Minor number 3 Device name 4 Reads completed successfully ... 6 Sectors read 7 Time spent reading (ms) 8 Writes completed ... 10 Sectors written 11 Time spent writing (ms) ... 19 Flush requests completed successfully 20 Time spent flushing See https://docs.kernel.org/admin-guide/iostats.html

Each row starts with major, minor and name. The fields used here are:

4  reads completed       8  writes completed
6  sectors read         10  sectors written
7  read time (ms)       11  write time (ms)

19 flushes completed 20 flush time (ms)

  • Fields 5, 9 and 12-18 are are not part of this API.
  • Sector counters use a fixed 512-byte unit and are converted to bytes.
  • Flush fields apply only to whole devices, not partitions.

◆ read_linux_meminfo()

Host_memory_snapshot mysql::system_info::internal::read_linux_meminfo ( std::istream &  input)

Read labeled host memory values from /proc/meminfo.

Read host memory capabilities from Linux meminfo input.

System memory stats. Fields are labeled. MemTotal - Total usable RAM MemFree - Sum of LowFree + High Free MemAvailable - Memory available for starting an application Buffers - Temporary storage for disk blocks Cached - In-memory page cache Slab - In-kernel data structures cache SwapTotal - Swap space available SwapFree - Unused swap space Slab - In-kernel data structures cache See https://man7.org/linux/man-pages/man5/proc_meminfo.5.html

  • The reader uses MemTotal, MemFree, MemAvailable, Buffers, Cached, Slab, SwapTotal and SwapFree.
  • Linux reports these fields in kB which are then converted to bytes.
  • Unknown labels are ignored because the kernel can add fields.

◆ read_linux_mount_info()

System_result< Filesystem_identity > mysql::system_info::internal::read_linux_mount_info ( std::istream &  input,
std::string_view  device_id,
std::string_view  target_path 
)

Find a filesystem in /proc/self/mountinfo.

Read the most specific matching mount from Linux mountinfo input.

Mount point info for each device. Fields in order. 1 mount-id - Mount point ID 2 parent-id - Parent mount point ID 3 device-id - Device ID "major:minor" 4 root - Root path 5 mount-point - Mount point path 6 mount-options - Per-mount options 7 optional - Optional fields tag[:value], can be empty 8 separator - End of the optional fields - 9 fs_type - Filesystem type type[.subtype] 10 mount-source - Filesystem specific or none 11 super-options - Per-superblock options See https://man7.org/linux/man-pages/man5/proc_pid_mountinfo.5.html

Example entries: 19 43 0:19 / /sys rw,nosuid,nodev,noexec,relatime shared:6 - sysfs sysfs rw 21 43 0:6 / /dev rw,nosuid shared:2 - devtmpfs devtmpfs rw,size=263331160k,nr_inodes=65832790,mode=755 129 119 0:54 / /home/arclight rw,relatime shared:105 - nfs4 server:/export/home rw Example from WSL2 with empty 'optional' field: 1076 77 7:0 / /mnt/xfs10 rw,relatime - xfs /dev/loop0 rw,attr2,inode64,logbufs=8,logbsize=32k,noquota

A mountinfo row starts with these fixed fields: mount-id parent-id major:minor root mount-point mount-options

Zero or more tag[:value] fields follow. A - separator introduces filesystem-type, mount-source and super-options. Path fields escape whitespace and backslashes as octal, e.g. \040 and \134.

A device can have more than one mount, so the reader selects the matching major:minor row whose mount point is the longest prefix of the target path.

From that, the mount ID, point, source and filesystem type form the identity.

◆ read_linux_partitions()

System_result< std::vector< Linux_block_device > > mysql::system_info::internal::read_linux_partitions ( std::istream &  input)

Read the block device identity table from /proc/partitions.

Read Linux block device identities from partitions input.

After the optional header, each row has four fields: 1 Major number 2 Minor number 3 Blocks 4 Device name

Major:Minor - kernel device number Device Name - sysfs device name Blocks - capacity in 1024-byte blocks, not used here because /sys/class/block/<name>/size preserves the 512-byte sector count

See https://man7.org/linux/man-pages/man5/proc_partitions.5.html

◆ read_linux_process_status()

Process_memory_snapshot mysql::system_info::internal::read_linux_process_status ( std::istream &  input)

Read process identity and memory from /proc/self/status.

Read process identity and memory from Linux status input.

Process memory stats, subset. Fields are labeled. kB converted to bytes. Name - Process name Pid - Process ID VmRSS - Resident set size, in kB VmData - Size of data segment, in kB VmSwap - Swapped out virtual memory, in kB ... See https://man7.org/linux/man-pages/man5/proc_pid_status.5.html

  • This file contains labeled name: value rows.
  • The reader uses Name, Pid, VmRSS, VmData and VmSwap. Other rows are ignored.
  • The three Vm values have a required kB suffix and are converted to bytes.

◆ read_linux_storage_capacity()

System_result< Storage_device_capacity > mysql::system_info::internal::read_linux_storage_capacity ( std::istream &  size_input,
std::istream &  sector_size_input,
std::string_view  device 
)

Read capacity metadata from /sys/class/block/<device>.

Read one Linux block device capacity and hardware sector size.

Block device size in sectors.

size - contains the decimal count of 512-byte sectors. The 512-byte unit is fixed by the the sysfs ABI and does not change with the physical sector size.

queue/hw_sector_size - contains the hardware sector size in bytes. A partition uses the queue attribute of its parent disk.

See https://www.kernel.org/doc/html/latest/admin-guide/abi-stable.html

◆ read_linux_thread_io()

System_result< Thread_io_counters > mysql::system_info::internal::read_linux_thread_io ( std::istream &  input,
uint64_t  tid 
)

Read /proc/self/task/<tid>/io.

Read process thread I/O counters from one Linux io record.

I/O statistics for the current process, read/write bytes. Fields are labeled. read_bytes - Bytes fetched from the storage layer write_bytes - Bytes written to the storage layer

Both are cumulative. Unrelated counters such as rchar and wchar are ignored.

See https://man7.org/linux/man-pages/man5/proc_pid_io.5.html

◆ read_linux_thread_stat()

Process_threads_snapshot mysql::system_info::internal::read_linux_thread_stat ( std::istream &  input,
uint64_t  expected_tid,
uint64_t  process_pid,
uint64_t  ticks_per_second,
uint64_t  page_size 
)

Read one /proc/self/task/<tid>/stat record.

Read process thread capabilities from one Linux stat record.

This file is not the same as /proc/stat despite sharing the name 'stat'.

  • /proc/stat contains system-wide statistics as labeled rows.
  • /proc/self/task/<tid>/stat contains one record for a single thread.

The first fields are the thread ID, the command name in parentheses and a one-character state.

The command name can contain spaces and ) characters, so parsing resumes after the final ) instead of splitting on whitespace.

States R, S, D, T or t and Z map to running, sleeping, waiting, stopped and zombie. Other kernel state characters map to unknown.

The reader uses these kernel field numbers: 14 utime 15 stime 16 cutime 17 cstime 20 num_threads 23 vsize (bytes) 24 rss (pages) 25 rsslim (bytes) 39 processor 42 delayacct_blkio_ticks 43 guest_time 44 cguest_time

  • Clock tick fields are converted to milliseconds with _SC_CLK_TCK.
  • RSS is converted to bytes with _SC_PAGESIZE.
  • Process-wide runtime fields are read only from the main thread record, whose TID equals the process PID.

See https://man7.org/linux/man-pages/man5/proc_pid_stat.5.html

◆ read_linux_vmstat()

System_result< Swap_activity_info > mysql::system_info::internal::read_linux_vmstat ( std::istream &  input)

Read cumulative paging activity from /proc/vmstat.

Read swap activity from Linux vmstat input.

Virtual memory statistics. Fields used: pgpgin - cumulative KiB paged in from disk pgpgout - cumulative KiB paged out to disk

See https://man7.org/linux/man-pages/man5/proc_vmstat.5.html

These are paging counters, not rates or swap-specific counters. The swap-specific page counters are pswpin and pswpout.

The reader converts them to bytes, so a caller can subtract successive snapshots to calculate interval activity.

◆ valid_linux_storage_device_name()

bool mysql::system_info::internal::valid_linux_storage_device_name ( std::string_view  name)

Check that a Linux device name is one safe path component.

◆ validate_filesystem_snapshot()

Filesystem_snapshot mysql::system_info::internal::validate_filesystem_snapshot ( Filesystem_snapshot  snapshot)

Reject invalid available filesystem usage values.

The function transforms its snapshot argument and returns the transformed value. Passing an lvalue preserves the original. Passing a moved value avoids a copy.

◆ validate_host_cpu_snapshot()

Host_cpu_snapshot mysql::system_info::internal::validate_host_cpu_snapshot ( Host_cpu_snapshot  snapshot)

Reject invalid available host CPU values.

◆ validate_host_memory_snapshot()

Host_memory_snapshot mysql::system_info::internal::validate_host_memory_snapshot ( Host_memory_snapshot  snapshot)

Reject invalid available host memory values.

◆ validate_process_memory_snapshot()

Process_memory_snapshot mysql::system_info::internal::validate_process_memory_snapshot ( Process_memory_snapshot  snapshot)

Reject invalid available process identity values.

◆ validate_process_threads_snapshot()

Process_threads_snapshot mysql::system_info::internal::validate_process_threads_snapshot ( Process_threads_snapshot  snapshot)

Reject invalid available process thread values.

◆ validate_storage_snapshot()

Storage_snapshot mysql::system_info::internal::validate_storage_snapshot ( Storage_snapshot  snapshot)

Reject invalid available storage device values.

Variable Documentation

◆ query_filesystem_platform

Filesystem_snapshot mysql::system_info::internal::query_filesystem_platform ( std::string_view  )

Collect Linux filesystem identity and space metadata for one path.

Collect filesystem information for the active platform.

Collect filesystem metadata from the macOS statfs record.

Source and field Contents


stat() st_dev Filesystem device major and minor numbers /proc/self/mountinfo major:minor Filesystem ID and mount point statvfs() f_blocks Total number of filesystem blocks statvfs() f_bavail Blocks available to this caller statvfs() f_frsize Size of each block in bytes

The device number from stat() joins the path to a mount record in the calling process's mount namespace. The canonical path is used to select the most specific matching mount point.

The identity and usage capabilities use separate queries. Failure of one does not prevent collection of the other.

Field Contents


f_fsid Two-part filesystem ID f_mntonname Directory where the filesystem is mounted f_mntfromname Mounted filesystem or source f_fstypename Filesystem type f_bsize Filesystem block size in bytes f_blocks Total number of filesystem blocks f_bavail Blocks available to a nonprivileged process

f_blocks and f_bavail are multiplied by f_bsize to produce byte values. Identity and usage are separate capabilities, so valid identity data remains available if the numeric usage fields are invalid.