* @brief Parse the MRC size string. * * In MRC profiling, it is necessary to support setting the cache size and the * number of test points. For setting the cache size, I referenced the * implementation in cachesim, which allows specifying a fixed cache size (e.g., * 1GiB) or a Working Set Size (WSS)-based cache size (a float between 0 and 1). * * For setting the number of test points, the
| 246 | * @param params The structure to store the parsed MRC profiler parameters. |
| 247 | */ |
| 248 | static void parse_mrc_size_params(const char *mrc_size_str, |
| 249 | mrcProfiler::mrc_profiler_params_t ¶ms) { |
| 250 | std::vector<std::string> mrc_size_vec = split_by_char(mrc_size_str, ','); |
| 251 | |
| 252 | // parse mrc size |
| 253 | if (mrc_size_vec.size() == 0) { |
| 254 | printf("mrc size must be set\n"); |
| 255 | exit(1); |
| 256 | } |
| 257 | |
| 258 | bool wss_based_mrc = false; |
| 259 | bool interval_based_mrc = false; |
| 260 | // 1. check whether the first size is a double |
| 261 | if (mrc_size_vec[0].find_first_not_of("0123456789.") == std::string::npos) { |
| 262 | wss_based_mrc = true; |
| 263 | } |
| 264 | |
| 265 | // 2. check whether the number of split strings is 3 and the last part is an |
| 266 | // integer |
| 267 | if (mrc_size_vec.size() == 3 && |
| 268 | mrc_size_vec[mrc_size_vec.size() - 1].find_first_not_of("0123456789") == |
| 269 | std::string::npos) { |
| 270 | // if the last size is an integer and greater than 1, then it is interval |
| 271 | // based mrc |
| 272 | int64_t mrc_points = atoi(mrc_size_vec[mrc_size_vec.size() - 1].c_str()); |
| 273 | if (mrc_points > 1) { |
| 274 | interval_based_mrc = true; |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | if (interval_based_mrc) { |
| 279 | int64_t mrc_points = atoi(mrc_size_vec[mrc_size_vec.size() - 1].c_str()); |
| 280 | mrc_size_vec.erase(mrc_size_vec.end() - 1); |
| 281 | if (mrc_size_vec.size() != 2) { |
| 282 | ERROR("mrc size setting wrong, current %s\n", mrc_size_str); |
| 283 | exit(1); |
| 284 | } |
| 285 | if (wss_based_mrc) { |
| 286 | double start_ratio = atof(mrc_size_vec[0].c_str()); |
| 287 | double end_ratio = atof(mrc_size_vec[1].c_str()); |
| 288 | if (start_ratio < 0 || end_ratio > 1 || start_ratio >= end_ratio) { |
| 289 | ERROR("mrc start size or end size wrong, current %s\n", mrc_size_str); |
| 290 | exit(1); |
| 291 | } |
| 292 | double interval = (end_ratio - start_ratio) / (mrc_points - 1); |
| 293 | for (int i = 0; i < mrc_points - 1; i++) { |
| 294 | double ratio = start_ratio + interval * i; |
| 295 | params.profile_wss_ratio.push_back(ratio); |
| 296 | } |
| 297 | params.profile_wss_ratio.push_back(end_ratio); |
| 298 | } else { |
| 299 | uint64_t start_size = |
| 300 | conv_size_str_to_byte_ul((char *)mrc_size_vec[0].c_str()); |
| 301 | uint64_t end_size = |
| 302 | conv_size_str_to_byte_ul((char *)mrc_size_vec[1].c_str()); |
| 303 | if (start_size >= end_size) { |
| 304 | ERROR("mrc start size or end size wrong, current %s\n", mrc_size_str); |
| 305 | exit(1); |
no test coverage detected