### Live CPU Monitor Example Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/api-reference/Monitoring.md Demonstrates how to set up and run a live CPU monitor that periodically fetches and displays CPU utilization. Includes starting, sleeping, and stopping the monitor. ```cpp #include #include #include int main() { auto monitor = hwinfo::monitoring::cpu::Monitor( []() { return hwinfo::monitoring::cpu::fetch(std::chrono::milliseconds(100)); }, [](const hwinfo::monitoring::cpu::Data& data) { std::cout << "CPU: " << data.utilization * 100.0 << "%" << std::endl; }, std::chrono::milliseconds(500) ); monitor.start(); std::this_thread::sleep_for(std::chrono::seconds(5)); monitor.stop(); return 0; } ``` -------------------------------- ### Example: Iterate and Display CPU Information Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/api-reference/CPU.md Demonstrates how to retrieve and display information for all installed CPUs. Includes vendor, model name, core count, and thread count. ```cpp #include #include int main() { const auto cpus = hwinfo::getAllCPUs(); for (const auto& cpu : cpus) { std::cout << "Socket " << cpu.id() << ": " << cpu.vendor() << " " << cpu.modelName() << " (" << cpu.numPhysicalCores() << " cores / " << cpu.numLogicalCores() << " threads)" << std::endl; } return 0; } ``` -------------------------------- ### Get Comprehensive OS Information Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/api-reference/OS.md A complete example demonstrating how to retrieve and display various OS details including name, version, kernel, architecture, and endianness. ```cpp #include #include int main() { hwinfo::OS os; std::cout << "Operating System Information:\n" << " Name: " << os.name() << "\n" << " Version: " << os.version() << "\n" << " Kernel: " << os.kernel() << "\n" << " Architecture: " << (os.is64bit() ? "64-bit" : "32-bit") << "\n" << " Endianness: " << (os.isLittleEndian() ? "little-endian" : "big-endian") << "\n"; return 0; } ``` -------------------------------- ### Basic RAM Information Example Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/api-reference/Memory.md A comprehensive example demonstrating how to include the hwinfo library and display total, free, and available RAM in GiB. ```cpp #include #include int main() { hwinfo::Memory memory; const double size_gb = memory.size() / (1024.0 * 1024.0 * 1024.0); const double free_gb = memory.free() / (1024.0 * 1024.0 * 1024.0); const double available_gb = memory.available() / (1024.0 * 1024.0 * 1024.0); std::cout << "RAM Size: " << size_gb << " GiB" << std::endl; std::cout << "Free: " << free_gb << " GiB" << std::endl; std::cout << "Available: " << available_gb << " GiB" << std::endl; return 0; } ``` -------------------------------- ### Basic GPU Information Example Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/api-reference/GPU.md Demonstrates how to iterate through all detected GPUs and print their ID, vendor, and name. This example requires the hwinfo/gpu.h header. ```cpp #include #include int main() { const auto gpus = hwinfo::getAllGPUs(); for (const auto& gpu : gpus) { std::cout << "GPU " << gpu.id() << ": " << gpu.vendor() << " " << gpu.name() << std::endl; } return 0; } ``` -------------------------------- ### Monitor CPU and RAM Usage Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/api-reference/Monitoring.md Sets up and starts monitors for CPU utilization and free RAM. The monitors fetch data every second and print the results to the console. The example demonstrates starting and stopping the monitors and letting them run for a specified duration. ```cpp #include #include #include int main() { auto cpu_monitor = hwinfo::monitoring::cpu::Monitor( hwinfo::monitoring::cpu::fetch, [](const hwinfo::monitoring::cpu::Data& data) { std::cout << "CPU: " << data.utilization * 100 << "%" << std::endl; }, std::chrono::milliseconds(1000) ); auto ram_monitor = hwinfo::monitoring::ram::Monitor( hwinfo::monitoring::ram::fetch, [](const hwinfo::monitoring::ram::Data& data) { double free_gb = data.free_bytes / (1024.0 * 1024.0 * 1024.0); std::cout << "RAM Free: " << free_gb << " GiB" << std::endl; }, std::chrono::milliseconds(1000) ); cpu_monitor.start(); ram_monitor.start(); // Let monitors run... std::this_thread::sleep_for(std::chrono::seconds(10)); cpu_monitor.stop(); ram_monitor.stop(); return 0; } ``` -------------------------------- ### Install Main hwinfo Target and Headers Source: https://github.com/lfreist/hwinfo/blob/main/src/CMakeLists.txt Installs the main hwinfo target, along with its associated headers and utility directory. This ensures the core library and its public interfaces are available after installation. ```cmake install(FILES ${HWINFO_INCLUDE_DIR}/hwinfo/platform.h ${HWINFO_INCLUDE_DIR}/hwinfo/hwinfo.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/hwinfo) install(DIRECTORY ${HWINFO_INCLUDE_DIR}/hwinfo/utils DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/hwinfo) install(TARGETS hwinfo EXPORT lfreist-hwinfoTargets LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION lib RUNTIME DESTINATION bin ) ``` -------------------------------- ### Install hwinfo Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/configuration.md Builds and installs hwinfo to the system's include and library paths. This makes it available for system-wide use. ```bash mkdir build cmake -B build -DCMAKE_BUILD_TYPE=Release cmake --build build --config Release cmake --install build ``` -------------------------------- ### Install hwinfo via CMake Source: https://github.com/lfreist/hwinfo/blob/main/README.md Steps to clone, build, and install the hwinfo library using CMake. ```bash git clone https://github.com/lfreist/hwinfo && cd hwinfo mkdir build cmake -B build && cmake --build build cmake --install build ``` -------------------------------- ### hwinfo::getAllCPUs() Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/api-reference/CPU.md Retrieves information for all installed processors on the system. This is the primary function to get CPU data. ```APIDOC ## hwinfo::getAllCPUs() ### Description Retrieves a vector containing `CPU` objects, each representing an installed processor on the system. ### Function Signature `std::vector getAllCPUs();` ### Returns A `std::vector` where each element provides detailed information about a CPU. ### Example ```cpp const auto cpus = hwinfo::getAllCPUs(); for (const auto& cpu : cpus) { std::cout << "Socket ID: " << cpu.id() << std::endl; std::cout << "Model: " << cpu.modelName() << std::endl; std::cout << "Vendor: " << cpu.vendor() << std::endl; std::cout << "Physical Cores: " << cpu.numPhysicalCores() << std::endl; std::cout << "Logical Cores: " << cpu.numLogicalCores() << std::endl; std::cout << "Flags: "; for (const auto& flag : cpu.flags()) { std::cout << flag << " "; } std::cout << std::endl; for (const auto& core : cpu.cores()) { std::cout << " Core " << core.id << ": " << core.regular_frequency_hz / 1e6 << " MHz" << std::endl; } } ``` ``` -------------------------------- ### hwinfo::getAllDisks() Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/api-reference/Disk.md Retrieves information for all installed disks on the system. This is the primary function to get a list of Disk objects. ```APIDOC ## hwinfo::getAllDisks() ### Description Retrieves information for all installed disks on the system. ### Returns - `std::vector`: A vector containing Disk objects, each representing a storage device. ### Example ```cpp const auto disks = hwinfo::getAllDisks(); if (!disks.empty()) { // Access information from the first disk std::cout << "Vendor: " << disks[0].vendor() << std::endl; } ``` ``` -------------------------------- ### Starting CPU Monitor Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/api-reference/Monitoring.md Starts a pre-configured CPU monitor. This is thread-safe and idempotent. ```cpp hwinfo::monitoring::cpu::Monitor monitor(fetch_fn, callback_fn, interval); monitor.start(); ``` -------------------------------- ### hwinfo::getAllGPUs() Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/api-reference/GPU.md Retrieves information for all installed GPUs in the system. This is the primary function to get a list of GPU objects. ```APIDOC ## hwinfo::getAllGPUs() ### Description Retrieves a vector containing information for all detected Graphics Processing Units (GPUs) in the system. ### Function Signature `std::vector getAllGPUs()` ### Returns A `std::vector` of `GPU` objects, where each object represents an installed GPU. ### Example ```cpp #include #include #include int main() { const auto gpus = hwinfo::getAllGPUs(); if (!gpus.empty()) { std::cout << "GPU Vendor: " << gpus[0].vendor() << std::endl; std::cout << "GPU Name: " << gpus[0].name() << std::endl; std::cout << "Dedicated Memory: " << gpus[0].dedicated_memory_Bytes() << " bytes" << std::endl; } else { std::cout << "No GPUs found." << std::endl; } return 0; } ``` ``` -------------------------------- ### Monitor Battery Status Example Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/api-reference/Battery.md A comprehensive example demonstrating how to retrieve and display detailed information for all detected batteries, including vendor, model, capacity, energy levels, and state. ```cpp #include #include int main() { const auto batteries = hwinfo::getAllBatteries(); std::cout << std::fixed << std::setprecision(1); for (const auto& battery : batteries) { std::cout << "Battery " << battery.id() << ":\n" << " Vendor: " << battery.vendor() << "\n" << " Model: " << battery.model() << "\n" << " Technology: " << battery.technology() << "\n" << " Capacity: " << battery.capacity() << "%\n" << " Energy: " << battery.energyNow() << " / " << battery.energyFull() << " mWh\n" << " State: " << battery.state() << "\n"; } return 0; } ``` -------------------------------- ### Get All CPUs Function Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/api-reference/CPU.md Retrieves information for all installed CPUs. This function is thread-safe and does not block or throw exceptions. ```cpp std::vector getAllCPUs(); ``` -------------------------------- ### Get Mainboard Version Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/api-reference/MainBoard.md Retrieves the version or revision string of the mainboard. Example: "Rev 1.xx". ```cpp hwinfo::MainBoard mainboard; std::cout << "Version: " << mainboard.version() << std::endl; ``` -------------------------------- ### Get All CPUs Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/api-reference/CPU.md Retrieves information for all installed processors. This function is the primary entry point for accessing CPU data. ```cpp const auto cpus = hwinfo::getAllCPUs(); ``` -------------------------------- ### Get OS Version Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/api-reference/OS.md Retrieves the operating system version string. Example: "22621" for Windows or "12.6.1" for macOS. ```cpp hwinfo::OS os; std::cout << "Version: " << os.version() << std::endl; ``` -------------------------------- ### Live Monitoring Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/README.md This example shows how to set up real-time monitoring for CPU utilization and free RAM using the hwinfo monitoring framework. ```APIDOC ## Live Monitoring ### Description This example shows how to set up real-time monitoring for CPU utilization and free RAM using the hwinfo monitoring framework. ### Code Example ```cpp #include #include #include #include int main() { // Create CPU monitor auto cpu_monitor = hwinfo::monitoring::cpu::Monitor( hwinfo::monitoring::cpu::fetch, [](const hwinfo::monitoring::cpu::Data& data) { std::cout << "CPU: " << data.utilization * 100.0 << "%" << std::endl; }, std::chrono::milliseconds(1000) ); // Create memory monitor auto ram_monitor = hwinfo::monitoring::ram::Monitor( hwinfo::monitoring::ram::fetch, [](const hwinfo::monitoring::ram::Data& data) { std::cout << "RAM Free: " << data.free_bytes / (1024.0 * 1024.0 * 1024.0) << " GiB" << std::endl; }, std::chrono::milliseconds(1000) ); // Start monitoring cpu_monitor.start(); ram_monitor.start(); // Monitor for 10 seconds std::this_thread::sleep_for(std::chrono::seconds(10)); // Stop automatically on destruction return 0; } ``` ``` -------------------------------- ### Get OS Name Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/api-reference/OS.md Retrieves the full operating system name. Example: "Microsoft Windows 11 Professional". ```cpp hwinfo::OS os; std::cout << "OS Name: " << os.name() << std::endl; ``` -------------------------------- ### Get Mainboard Vendor Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/api-reference/MainBoard.md Retrieves the manufacturer name of the mainboard. Example: "ASUS", "Gigabyte". ```cpp hwinfo::MainBoard mainboard; std::cout << "Vendor: " << mainboard.vendor() << std::endl; ``` -------------------------------- ### Build Executable and Link Library Source: https://github.com/lfreist/hwinfo/blob/main/examples/CMakeLists.txt Defines an executable target named 'system_info' and links it with the 'lfreist-hwinfo::hwinfo' library. Installs the target. ```cmake add_executable(system_info system_infoMain.cpp) target_link_libraries(system_info PRIVATE lfreist-hwinfo::hwinfo) install(TARGETS system_info) ``` -------------------------------- ### Build Another Executable and Link Library Source: https://github.com/lfreist/hwinfo/blob/main/examples/CMakeLists.txt Defines an executable target named 'live_monitor' and links it with the 'lfreist-hwinfo::hwinfo' library. Installs the target. ```cmake add_executable(live_monitor live_monitorMain.cpp) target_link_libraries(live_monitor PRIVATE lfreist-hwinfo::hwinfo) install(TARGETS live_monitor) ``` -------------------------------- ### getAllCPUs() Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/api-reference/CPU.md Retrieves information for all installed CPUs on the system. This function is thread-safe and does not block. ```APIDOC ## Function: getAllCPUs() ### Description Retrieves information for all installed CPUs. ### Signature `std::vector getAllCPUs();` ### Returns `std::vector`: A vector containing `CPU` objects, with one entry per CPU socket. ### Thread-Safety Yes, safe to call from multiple threads. ### Blocking No. ### Exceptions None. ### Example ```cpp #include #include int main() { const auto cpus = hwinfo::getAllCPUs(); for (const auto& cpu : cpus) { std::cout << "Socket " << cpu.id() << ": " << cpu.vendor() << " " << cpu.modelName() << " (" << cpu.numPhysicalCores() << " cores / " << cpu.numLogicalCores() << " threads)" << std::endl; } return 0; } ``` ``` -------------------------------- ### SI Prefix Usage Example Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/types.md Demonstrates how to use SI prefixes for unit conversion, specifically converting bytes to Gigabytes. ```cpp uint64_t bytes = 1500000000; double gb = bytes / 1 * hwinfo::unit::SiPrefix::GIGA; ``` -------------------------------- ### getAllDisks() Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/api-reference/Disk.md Retrieves information for all installed disks. This function is thread-safe and non-blocking. ```APIDOC ## Free Function: getAllDisks() ### Description Retrieves information for all installed disks. ### Returns `std::vector` with one entry per disk device. ### Thread-Safe Yes ### Blocking No ### Example ```cpp #include #include int main() { const auto disks = hwinfo::getAllDisks(); for (const auto& disk : disks) { std::cout << "Disk " << disk.id() << ": " << disk.vendor() << " " << disk.model() << " (" << disk.size() / (1024 * 1024 * 1024) << " GB)" << std::endl; } return 0; } ``` ``` -------------------------------- ### IEC Prefix Usage Example Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/types.md Demonstrates using the unit_prefix_to function with an IEC prefix to convert bytes to Gibibytes. ```cpp uint64_t bytes = 1073741824; // 1 GiB double gib = hwinfo::unit::unit_prefix_to(bytes, hwinfo::unit::IECPrefix::GIBI); // gib == 1.0 ``` -------------------------------- ### CPU Monitoring with Monitor Template Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/api-reference/Monitoring.md Instantiates and starts a Monitor for CPU utilization. The callback function prints the utilization percentage every second. ```cpp auto monitor = hwinfo::monitoring::cpu::Monitor( []() { return hwinfo::monitoring::cpu::fetch(); }, [](const hwinfo::monitoring::cpu::Data& data) { std::cout << "CPU: " << data.utilization * 100 << "%" << std::endl; }, std::chrono::milliseconds(1000) ); monitor.start(); ``` -------------------------------- ### getAllGPUs() Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/api-reference/GPU.md Retrieves information for all installed GPUs. This function is thread-safe and non-blocking. ```APIDOC ## Function: getAllGPUs() ### Description Retrieves information for all installed GPUs on the system. This function is designed to be thread-safe and non-blocking. ### Signature ```cpp std::vector getAllGPUs(); ``` ### Returns - `std::vector`: A vector containing `GPU` objects, where each object represents an installed GPU device. ### Thread-Safety Yes ### Blocking No ### Example Usage ```cpp #include #include int main() { const auto gpus = hwinfo::getAllGPUs(); for (const auto& gpu : gpus) { std::cout << "GPU " << gpu.id() << ": " << gpu.vendor() << " " << gpu.name() << std::endl; } return 0; } ``` ``` -------------------------------- ### CPU::cores() Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/api-reference/CPU.md Gets detailed information about each core, including cache and frequency. ```APIDOC ## CPU::cores() ### Description Returns a vector of `Core` structures, each containing detailed information about a specific CPU core. ### Method `const std::vector& cores() const` ### Return Type `const std::vector&` ### Example ```cpp const auto cpus = hwinfo::getAllCPUs(); for (const auto& core : cpus[0].cores()) { std::cout << "Core " << core.id << ": " << core.regular_frequency_hz / 1e6 << " MHz" << std::endl; } ``` ``` -------------------------------- ### hwinfo::getAllGPUs Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/INDEX.md Retrieves a list of all graphics processing units (GPUs) installed in the system. ```APIDOC ## hwinfo::getAllGPUs ### Description Retrieves a list of all graphics processing units (GPUs) installed in the system. ### Method Free Function ### Returns - `std::vector`: A vector of GPU objects. ### Platform Support Linux ✓ | macOS ✗ | Windows ✓ ``` -------------------------------- ### Get All GPUs Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/api-reference/GPU.md Retrieves information for all installed GPU devices. This function is thread-safe and non-blocking. ```cpp std::vector getAllGPUs(); ``` -------------------------------- ### Include hwinfo via find_package Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/configuration.md Use this method when hwinfo is installed system-wide or in a known location. It requires the 'CONFIG' mode to be available. ```cmake find_package(hwinfo REQUIRED) add_executable(your_executable your_executable.cpp) target_link_libraries(your_executable PUBLIC lfreist-hwinfo::hwinfo) ``` -------------------------------- ### Complete Disk Information Example Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/api-reference/Utilities.md Demonstrates how to retrieve and display information about all disks, including model, size in GiB, and mount points, using various utility functions. ```cpp #include #include #include #include #include using namespace hwinfo::unit; int main() { const auto disks = hwinfo::getAllDisks(); std::cout << std::fixed << std::setprecision(2); for (const auto& disk : disks) { std::string info = "Disk " + std::to_string(disk.id()) + ": "; info += disk.vendor() + " " + disk.model(); std::cout << info << "\n" << " Model: " << disk.model() << "\n" << " Size: " << unit_prefix_to(disk.size(), IECPrefix::GIBI) << " GiB\n"; if (!disk.mount_points().empty()) { std::string mounts = hwinfo::utils::join(disk.mount_points(), ", "); std::cout << " Mounts: " << mounts << "\n"; } } return 0; } ``` -------------------------------- ### Get Kernel/Build Identifier Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/api-reference/OS.md Retrieves the kernel or OS build identifier. Example: "5.15.0-86-generic" on Linux. ```cpp hwinfo::OS os; std::cout << "Kernel: " << os.kernel() << std::endl; ``` -------------------------------- ### Memory::modules() Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/api-reference/Memory.md Returns detailed information about each RAM module installed in the system. The information includes vendor, model, size, and frequency. ```APIDOC ## modules() ### Description Returns detailed information about each RAM module. ### Signature ```cpp const std::vector& modules() const ``` ### Return Type `const std::vector&` ### Details Vector of Module structures containing vendor, model, and specifications for each RAM module. ``` -------------------------------- ### Basic hwinfo Build Example Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/configuration.md Performs a basic build of hwinfo with all components enabled and Release configuration. This generates both static and shared libraries. ```bash mkdir build cmake -B build -DCMAKE_BUILD_TYPE=Release cmake --build build --config Release ``` -------------------------------- ### Get Mainboard Model Name Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/api-reference/MainBoard.md Retrieves the model designation of the mainboard. Example: "PRIME Z490-A". ```cpp hwinfo::MainBoard mainboard; std::cout << "Model: " << mainboard.name() << std::endl; ``` -------------------------------- ### Retrieve All Mainboard Information Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/api-reference/MainBoard.md Includes necessary headers and demonstrates how to instantiate MainBoard and print all available motherboard details: vendor, model, version, and serial number. ```cpp #include #include int main() { hwinfo::MainBoard mainboard; std::cout << "Mainboard Information:\n" << " Vendor: " << mainboard.vendor() << "\n" << " Model: " << mainboard.name() << "\n" << " Version: " << mainboard.version() << "\n" << " Serial: " << mainboard.serialNumber() << "\n"; return 0; } ``` -------------------------------- ### Network::description() Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/api-reference/Network.md Gets the human-readable description of the network interface. This often corresponds to the type of network adapter. ```APIDOC ## Method: Network::description() ### Description Returns a human-readable description of the network interface, such as "Ethernet" or "Wi-Fi". ### Signature ```cpp const std::string& description() const; ``` ### Return Type - `const std::string&`: The description of the network interface. ### Example ```cpp const auto networks = hwinfo::getAllNetworks(); std::cout << "Description: " << networks[0].description() << std::endl; ``` ``` -------------------------------- ### List All Disks Example C++ Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/api-reference/Disk.md Demonstrates how to iterate through all detected disks and print their basic information such as ID, vendor, model, and size. Requires including the hwinfo/disk.h header. ```cpp #include #include int main() { const auto disks = hwinfo::getAllDisks(); for (const auto& disk : disks) { std::cout << "Disk " << disk.id() << ": " << disk.vendor() << " " << disk.model() << " (" << disk.size() / (1024 * 1024 * 1024) << " GB)" << std::endl; } return 0; } ``` -------------------------------- ### Get All Disks C++ Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/api-reference/Disk.md Retrieves a vector of Disk objects, each containing information about an installed disk. This function is thread-safe and non-blocking. ```cpp std::vector getAllDisks(); ``` -------------------------------- ### Enable OpenCL for GPU Information Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/configuration.md Enables the OpenCL backend for enhanced GPU information gathering. Requires OpenCL development libraries to be installed. ```cmake option(HWINFO_GPU_OPENCL "Enable usage of OpenCL in GPU information" OFF) ``` -------------------------------- ### Basic Hardware Enumeration Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/README.md This example demonstrates how to retrieve basic hardware information such as CPU details, RAM size, OS information, and disk details using the hwinfo library. ```APIDOC ## Basic Hardware Enumeration ### Description This example demonstrates how to retrieve basic hardware information such as CPU details, RAM size, OS information, and disk details using the hwinfo library. ### Code Example ```cpp #include #include #include using namespace hwinfo::unit; int main() { // CPU information const auto cpus = hwinfo::getAllCPUs(); for (const auto& cpu : cpus) { std::cout << "CPU " << cpu.id() << ": " << cpu.vendor() << " " << cpu.modelName() << " (" << cpu.numPhysicalCores() << " cores)" << std::endl; } // Memory information hwinfo::Memory memory; std::cout << "RAM: " << unit_prefix_to(memory.size(), IECPrefix::GIBI) << " GiB" << std::endl; // OS information hwinfo::OS os; std::cout << "OS: " << os.name() << std::endl; // Disk information const auto disks = hwinfo::getAllDisks(); for (const auto& disk : disks) { std::cout << "Disk " << disk.id() << ": " << unit_prefix_to(disk.size(), IECPrefix::GIBI) << " GiB (" << disk.disk_interface() << ")" << std::endl; } return 0; } ``` ``` -------------------------------- ### Get GPU Driver Version Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/api-reference/GPU.md Retrieves the version string of the installed GPU driver. Use after calling hwinfo::getAllGPUs(). ```cpp const auto gpus = hwinfo::getAllGPUs(); std::cout << "Driver: " << gpus[0].driverVersion() << std::endl; ``` -------------------------------- ### Get All GPUs Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/api-reference/GPU.md Retrieves information for all installed GPUs in the system. This is the primary function to use before accessing individual GPU properties. ```cpp const auto gpus = hwinfo::getAllGPUs(); ``` -------------------------------- ### Get CPU Vendor Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/api-reference/CPU.md Retrieves and prints the vendor string of the first detected CPU. This helps identify the manufacturer (e.g., Intel, AMD). ```cpp const auto cpus = hwinfo::getAllCPUs(); std::cout << "Vendor: " << cpus[0].vendor() << std::endl; ``` -------------------------------- ### Get Disk Model Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/api-reference/Disk.md Retrieves the model name of the first disk. Ensure hwinfo::getAllDisks() has been called to populate the disk information. ```cpp const auto disks = hwinfo::getAllDisks(); std::cout << "Model: " << disks[0].model() << std::endl; ``` -------------------------------- ### Get Disk Vendor Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/api-reference/Disk.md Retrieves the vendor name of the first disk in the system. Requires calling hwinfo::getAllDisks() first. ```cpp const auto disks = hwinfo::getAllDisks(); std::cout << "Vendor: " << disks[0].vendor() << std::endl; ``` -------------------------------- ### Configure OS Module Source: https://github.com/lfreist/hwinfo/blob/main/src/CMakeLists.txt Sets up the OS library, including source files and installation targets. Use when building the OS information retrieval component. ```cmake if (HWINFO_OS) set(OS_SRC_FILES os.cpp apple/os.cpp linux/os.cpp windows/os.cpp windows/utils/wmi_wrapper.cpp ) add_library(hwinfo_os ${HWINFO_BUILD} ${OS_SRC_FILES}) if(${HWINFO_SHARED}) target_compile_definitions(hwinfo_os PUBLIC -DHWINFO_EXPORTS) endif() target_include_directories(hwinfo_os PUBLIC $ $) target_link_libraries(hwinfo INTERFACE hwinfo_os) set_target_properties(hwinfo_os PROPERTIES OUTPUT_NAME "hwinfo_os") install(TARGETS hwinfo_os EXPORT lfreist-hwinfoTargets LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION lib RUNTIME DESTINATION bin) install(FILES ${HWINFO_INCLUDE_DIR}/hwinfo/os.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/hwinfo) endif () ``` -------------------------------- ### Live Hardware Monitoring Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/README.md Sets up and runs live monitoring for CPU utilization and free RAM. Uses dedicated monitoring modules and callbacks for data updates. Monitoring runs for a specified duration. ```cpp #include #include #include #include int main() { // Create CPU monitor auto cpu_monitor = hwinfo::monitoring::cpu::Monitor( hwinfo::monitoring::cpu::fetch, [](const hwinfo::monitoring::cpu::Data& data) { std::cout << "CPU: " << data.utilization * 100.0 << "%" << std::endl; }, std::chrono::milliseconds(1000) ); // Create memory monitor auto ram_monitor = hwinfo::monitoring::ram::Monitor( hwinfo::monitoring::ram::fetch, [](const hwinfo::monitoring::ram::Data& data) { std::cout << "RAM Free: " << data.free_bytes / (1024.0 * 1024.0 * 1024.0) << " GiB" << std::endl; }, std::chrono::milliseconds(1000) ); // Start monitoring cpu_monitor.start(); ram_monitor.start(); // Monitor for 10 seconds std::this_thread::sleep_for(std::chrono::seconds(10)); // Stop automatically on destruction return 0; } ``` -------------------------------- ### Get Battery Model Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/api-reference/Battery.md Retrieves the model designation of the battery. Use this to get the specific model name. ```cpp const auto batteries = hwinfo::getAllBatteries(); std::cout << "Model: " << batteries[0].model() << std::endl; ``` -------------------------------- ### Version-Aware CMake Configuration Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/configuration.md This example shows how to use `find_package` with version checking to ensure compatibility and retrieve the hwinfo version. It links against the library if found, otherwise, it reports a fatal error. ```cmake find_package(hwinfo REQUIRED CONFIG) if(hwinfo_FOUND) message(STATUS "hwinfo found: ${hwinfo_VERSION}") target_link_libraries(my_app PRIVATE lfreist-hwinfo::hwinfo) else() message(FATAL_ERROR "hwinfo not found") endif() ``` -------------------------------- ### Initialize MainBoard Object Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/api-reference/MainBoard.md Instantiates a MainBoard object. This action queries system motherboard information upon creation. ```cpp hwinfo::MainBoard mainboard; ``` -------------------------------- ### Configure Mainboard Module Source: https://github.com/lfreist/hwinfo/blob/main/src/CMakeLists.txt Sets up the Mainboard library, including source files, platform-specific linking, and installation targets. Use when building the mainboard information retrieval component. ```cmake if (HWINFO_MAINBOARD) set(MAINBOARD_SRC_FILES mainboard.cpp apple/mainboard.cpp linux/mainboard.cpp windows/mainboard.cpp windows/utils/wmi_wrapper.cpp ) add_library(hwinfo_mainboard ${HWINFO_BUILD} ${MAINBOARD_SRC_FILES}) if(${HWINFO_SHARED}) target_compile_definitions(hwinfo_mainboard PUBLIC -DHWINFO_EXPORTS) endif() target_include_directories(hwinfo_mainboard PUBLIC $ $) if(APPLE) target_link_libraries(hwinfo_mainboard PRIVATE "-framework IOKit" "-framework CoreFoundation") endif() target_link_libraries(hwinfo INTERFACE hwinfo_mainboard) set_target_properties(hwinfo_mainboard PROPERTIES OUTPUT_NAME "hwinfo_mainboard") install(TARGETS hwinfo_mainboard EXPORT lfreist-hwinfoTargets LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION lib RUNTIME DESTINATION bin) install(FILES ${HWINFO_INCLUDE_DIR}/hwinfo/mainboard.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/hwinfo) endif () ``` -------------------------------- ### Minimal CMake Configuration Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/configuration.md This snippet demonstrates the most basic way to integrate hwinfo using `add_subdirectory`, which assumes hwinfo is already present in the specified path. It enables all default components. ```cmake cmake_minimum_required(VERSION 3.14) project(MyProject) # Use default options (all components enabled) add_subdirectory(hwinfo) add_executable(my_app main.cpp) target_link_libraries(my_app PRIVATE hwinfo::hwinfo) ``` -------------------------------- ### GPU::device_id() Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/api-reference/GPU.md Gets the device ID of the GPU. ```APIDOC ## GPU::device_id() ### Description Returns the device ID of the GPU, which uniquely identifies the specific GPU model, often in hexadecimal format. ### Method `const std::string& device_id() const` ### Return Type `const std::string&` ### Example ```cpp const auto gpus = hwinfo::getAllGPUs(); if (!gpus.empty()) { std::cout << "Device ID: " << gpus[0].device_id() << std::endl; } ``` ``` -------------------------------- ### Build with OpenCL Support Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/configuration.md Builds hwinfo with GPU detection enabled and the OpenCL backend activated for enhanced GPU information. Requires OpenCL development libraries. ```bash mkdir build cmake -B build \ -DCMAKE_BUILD_TYPE=Release \ -DHWINFO_GPU=ON \ -DHWINFO_GPU_OPENCL=ON cmake --build build --config Release ``` -------------------------------- ### Detailed Disk Information Listing C++ Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/api-reference/Disk.md Provides a comprehensive example of listing all disks and their detailed attributes, including vendor, model, interface, size in GiB, serial number, and mount points. Uses hwinfo::unit::unit_prefix_to for size formatting. ```cpp #include #include #include #include using namespace hwinfo::unit; int main() { const auto disks = hwinfo::getAllDisks(); std::cout << std::fixed << std::setprecision(2); for (const auto& disk : disks) { std::cout << "Disk " << disk.id() << ":\n" << " Vendor: " << disk.vendor() << "\n" << " Model: " << disk.model() << "\n" << " Interface: " << disk.disk_interface() << "\n" << " Size: " << unit_prefix_to(disk.size(), IECPrefix::GIBI) << " GiB\n" << " Serial: " << disk.serial_number() << "\n"; if (!disk.mount_points().empty()) { std::cout << " Mounts: "; for (size_t i = 0; i < disk.mount_points().size(); ++i) { if (i > 0) std::cout << ", "; std::cout << disk.mount_points()[i]; } std::cout << "\n"; } } return 0; } ``` -------------------------------- ### GPU::vendor_id() Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/api-reference/GPU.md Gets the vendor ID of the GPU. ```APIDOC ## GPU::vendor_id() ### Description Returns the vendor ID of the GPU, typically in hexadecimal format (e.g., "10DE" for NVIDIA). ### Method `const std::string& vendor_id() const` ### Return Type `const std::string&` ### Example ```cpp const auto gpus = hwinfo::getAllGPUs(); if (!gpus.empty()) { std::cout << "Vendor ID: " << gpus[0].vendor_id() << std::endl; } ``` ``` -------------------------------- ### GPU::id() Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/api-reference/GPU.md Gets the unique identifier for the GPU. ```APIDOC ## GPU::id() ### Description Returns a unique identifier for the GPU. ### Method `std::uint32_t id() const` ### Return Type `std::uint32_t` ### Example ```cpp const auto gpus = hwinfo::getAllGPUs(); if (!gpus.empty()) { std::cout << "GPU ID: " << gpus[0].id() << std::endl; } ``` ``` -------------------------------- ### CPU Monitor Setup Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/api-reference/Monitoring.md Sets up a type alias for CPU monitoring, allowing for the creation of a monitor object that periodically fetches and processes CPU data. ```cpp auto monitor = hwinfo::monitoring::cpu::Monitor( hwinfo::monitoring::cpu::fetch, [](const hwinfo::monitoring::cpu::Data& d) { std::cout << d.utilization * 100 << "%" << std::endl; }, std::chrono::milliseconds(500) ); ``` -------------------------------- ### GPU::num_cores() Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/api-reference/GPU.md Gets the number of cores/shaders on the GPU. ```APIDOC ## GPU::num_cores() ### Description Returns the number of parallel processing cores or shaders available on the GPU. ### Method `std::uint64_t num_cores() const` ### Return Type `std::uint64_t` ### Example ```cpp const auto gpus = hwinfo::getAllGPUs(); if (!gpus.empty()) { std::cout << "Cores: " << gpus[0].num_cores() << std::endl; } ``` ``` -------------------------------- ### Check for Empty CPU or OS Data Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/README.md Demonstrates how to check for empty return values from getAllCPUs() and the OS() constructor to handle cases where data might not be available. ```cpp const auto cpus = hwinfo::getAllCPUs(); if (cpus.empty()) { // No CPUs detected (should not happen) } hwinfo::OS os; if (os.name().empty()) { // OS name not available } ``` -------------------------------- ### version() Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/api-reference/OS.md Returns the operating system version string. ```APIDOC ## version() ### Description Returns the operating system version. ### Method ```cpp std::string version() const; ``` ### Parameters None ### Return Type `std::string` ### Details Version string (e.g., "22621" for Windows, "12.6.1" for macOS) ### Example ```cpp hwinfo::OS os; std::cout << "Version: " << os.version() << std::endl; ``` ``` -------------------------------- ### Disk::id() Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/api-reference/Disk.md Gets the unique identifier for the disk. ```APIDOC ## Disk::id() ### Description Returns the disk identifier. ### Method `std::uint32_t id() const` ### Return Type `std::uint32_t` ### Description Unique disk identifier ### Example ```cpp const auto disks = hwinfo::getAllDisks(); std::cout << "Disk ID: " << disks[0].id() << std::endl; ``` ``` -------------------------------- ### GPU::driverVersion() Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/api-reference/GPU.md Gets the driver version of the GPU. ```APIDOC ## GPU::driverVersion() ### Description Returns the version string of the installed GPU driver. ### Method `const std::string& driverVersion() const` ### Return Type `const std::string&` ### Example ```cpp const auto gpus = hwinfo::getAllGPUs(); if (!gpus.empty()) { std::cout << "Driver: " << gpus[0].driverVersion() << std::endl; } ``` ``` -------------------------------- ### Configure GPU Module Source: https://github.com/lfreist/hwinfo/blob/main/src/CMakeLists.txt Sets up the GPU library, including source files, conditional OpenCL support, and installation targets. Use when building the GPU information retrieval component. ```cmake if (HWINFO_GPU) set(GPU_SRC_FILES gpu.cpp apple/gpu.cpp linux/gpu.cpp windows/gpu.cpp windows/utils/wmi_wrapper.cpp PCIMapper.cpp ) if (HWINFO_GPU_OPENCL) add_subdirectory(opencl) endif () add_library(hwinfo_gpu ${HWINFO_BUILD} ${GPU_SRC_FILES}) if(${HWINFO_SHARED}) target_compile_definitions(hwinfo_gpu PUBLIC -DHWINFO_EXPORTS) endif() if(HWINFO_GPU_OPENCL) target_compile_definitions(hwinfo_gpu PUBLIC USE_OCL) target_link_libraries(hwinfo_gpu PRIVATE opencl_device) endif () target_include_directories(hwinfo_gpu PUBLIC $ $ $) add_dependencies(hwinfo_gpu generate_pci_ids_header) target_link_libraries(hwinfo INTERFACE hwinfo_gpu) set_target_properties(hwinfo_gpu PROPERTIES OUTPUT_NAME "hwinfo_gpu") install(TARGETS hwinfo_gpu EXPORT lfreist-hwinfoTargets LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION lib RUNTIME DESTINATION bin) install(FILES ${HWINFO_INCLUDE_DIR}/hwinfo/gpu.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/hwinfo) if(HWINFO_GPU_OPENCL) install(DIRECTORY ${HWINFO_INCLUDE_DIR}/hwinfo/opencl DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/hwinfo) endif () endif () ``` -------------------------------- ### GPU::name() Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/api-reference/GPU.md Gets the model name of the GPU. ```APIDOC ## GPU::name() ### Description Returns the model name of the GPU, specifying the exact model (e.g., "NVIDIA GeForce RTX 3070 Ti"). ### Method `const std::string& name() const` ### Return Type `const std::string&` ### Example ```cpp const auto gpus = hwinfo::getAllGPUs(); if (!gpus.empty()) { std::cout << "Name: " << gpus[0].name() << std::endl; } ``` ``` -------------------------------- ### GPU::vendor() Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/api-reference/GPU.md Gets the vendor name of the GPU. ```APIDOC ## GPU::vendor() ### Description Returns the vendor name of the GPU, indicating the manufacturer (e.g., "NVIDIA", "AMD"). ### Method `const std::string& vendor() const` ### Return Type `const std::string&` ### Example ```cpp const auto gpus = hwinfo::getAllGPUs(); if (!gpus.empty()) { std::cout << "Vendor: " << gpus[0].vendor() << std::endl; } ``` ``` -------------------------------- ### Fetch hwinfo using FetchContent (CMake 3.11+) Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/configuration.md Leverage CMake's FetchContent module to download and build hwinfo directly from its Git repository during the configuration process. This is a convenient way to manage external dependencies without manual submodule setup. ```cmake include(FetchContent) FetchContent_Declare( hwinfo GIT_REPOSITORY https://github.com/lfreist/hwinfo.git GIT_TAG main ) FetchContent_MakeAvailable(hwinfo) add_executable(your_executable your_executable.cpp) target_link_libraries(your_executable PRIVATE hwinfo::hwinfo) ``` -------------------------------- ### Disk::model() Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/api-reference/Disk.md Gets the model designation of the disk. ```APIDOC ## Disk::model() ### Description Returns the disk model name. ### Method `const std::string& model() const` ### Return Type `const std::string&` ### Default Value `""` ### Example ```cpp const auto disks = hwinfo::getAllDisks(); std::cout << "Model: " << disks[0].model() << std::endl; ``` ``` -------------------------------- ### Custom Component Selection Build Source: https://github.com/lfreist/hwinfo/blob/main/_autodocs/configuration.md Builds hwinfo with specific components enabled (CPU, RAM) and others disabled (Disk, GPU, Mainboard, Battery, OS). Useful for minimizing library size. ```bash mkdir build cmake -B build \ -DCMAKE_BUILD_TYPE=Release \ -DHWINFO_CPU=ON \ -DHWINFO_RAM=ON \ -DHWINFO_DISK=OFF \ -DHWINFO_GPU=OFF \ -DHWINFO_MAINBOARD=OFF \ -DHWINFO_BATTERY=OFF \ -DHWINFO_OS=OFF cmake --build build --config Release ```