* @brief Convert a `std::vector ` representing CPU affinity to a string of 0s and 1s. * * @param affinity The affinity. * @return The string. */
| 2981 | * @return The string. |
| 2982 | */ |
| 2983 | std::string affinity_to_string(const std::optional<std::vector<bool>>& affinity) |
| 2984 | { |
| 2985 | if (affinity.has_value()) |
| 2986 | { |
| 2987 | const std::size_t num_bits = affinity->size(); |
| 2988 | std::string str(num_bits, ' '); |
| 2989 | for (std::size_t i = 0; i < num_bits; ++i) |
| 2990 | str[num_bits - i - 1] = (*affinity)[i] ? '1' : '0'; |
| 2991 | return str; |
| 2992 | } |
| 2993 | return "N/A"; |
| 2994 | } |
| 2995 | |
| 2996 | /** |
| 2997 | * @brief Check that getting and setting OS process affinity works. |
no test coverage detected