* @brief read the reverse trace and write to the output file * * @param ofilepath * @param stat * @param output_txt * @param lcs_ver */
| 328 | * @param lcs_ver |
| 329 | */ |
| 330 | static void _reverse_file(std::string ofilepath, lcs_trace_stat_t stat, bool output_txt, int64_t lcs_ver) { |
| 331 | size_t file_size; |
| 332 | char *mapped_file = reinterpret_cast<char *>(utils::setup_mmap(ofilepath + ".reverse", &file_size)); |
| 333 | size_t pos = file_size; |
| 334 | |
| 335 | std::ofstream ofile(ofilepath, std::ios::out | std::ios::binary | std::ios::trunc); |
| 336 | _write_lcs_header(ofile, stat, lcs_ver); |
| 337 | |
| 338 | INFO("start to reverse the trace...\n"); |
| 339 | std::ofstream ofile_txt; |
| 340 | if (output_txt) ofile_txt.open(ofilepath + ".txt", std::ios::out | std::ios::trunc); |
| 341 | |
| 342 | lcs_req_full_t lcs_req_full; |
| 343 | size_t lcs_full_req_entry_size = sizeof(lcs_req_full_t); |
| 344 | |
| 345 | // for lcs version 4-8, we need to read the features |
| 346 | size_t n_features = 0; |
| 347 | if (lcs_ver >= 4 && lcs_ver <= 8) { |
| 348 | n_features = LCS_VER_TO_N_FEATURES[lcs_ver]; |
| 349 | } |
| 350 | |
| 351 | size_t entry_size = lcs_full_req_entry_size + n_features * sizeof(int32_t); |
| 352 | |
| 353 | while (pos >= entry_size) { |
| 354 | pos -= entry_size; |
| 355 | memcpy(&lcs_req_full, mapped_file + pos, lcs_full_req_entry_size); |
| 356 | if (lcs_req_full.next_access_vtime != INT64_MAX) { |
| 357 | /* req.next_access_vtime is the vtime start from the end */ |
| 358 | lcs_req_full.next_access_vtime = stat.n_req - lcs_req_full.next_access_vtime; |
| 359 | } |
| 360 | |
| 361 | if (lcs_ver == 1) { |
| 362 | lcs_req_v1_t lcs_req_v1; |
| 363 | lcs_req_v1.clock_time = lcs_req_full.clock_time; |
| 364 | lcs_req_v1.obj_id = lcs_req_full.obj_id; |
| 365 | lcs_req_v1.obj_size = lcs_req_full.obj_size; |
| 366 | lcs_req_v1.next_access_vtime = lcs_req_full.next_access_vtime; |
| 367 | |
| 368 | ofile.write(reinterpret_cast<char *>(&lcs_req_v1), sizeof(lcs_req_v1)); |
| 369 | } else if (lcs_ver == 2) { |
| 370 | lcs_req_v2_t lcs_req_v2; |
| 371 | lcs_req_v2.clock_time = lcs_req_full.clock_time; |
| 372 | lcs_req_v2.obj_id = lcs_req_full.obj_id; |
| 373 | lcs_req_v2.obj_size = lcs_req_full.obj_size; |
| 374 | lcs_req_v2.op = lcs_req_full.op; |
| 375 | lcs_req_v2.tenant = lcs_req_full.tenant; |
| 376 | lcs_req_v2.next_access_vtime = lcs_req_full.next_access_vtime; |
| 377 | |
| 378 | ofile.write(reinterpret_cast<char *>(&lcs_req_v2), sizeof(lcs_req_v2)); |
| 379 | } else if (lcs_ver == 3) { |
| 380 | lcs_req_v3_t lcs_req_v3; |
| 381 | lcs_req_v3.clock_time = lcs_req_full.clock_time; |
| 382 | lcs_req_v3.obj_id = lcs_req_full.obj_id; |
| 383 | lcs_req_v3.ttl = lcs_req_full.ttl; |
| 384 | lcs_req_v3.obj_size = lcs_req_full.obj_size; |
| 385 | lcs_req_v3.op = lcs_req_full.op; |
| 386 | lcs_req_v3.tenant = lcs_req_full.tenant; |
| 387 | lcs_req_v3.next_access_vtime = lcs_req_full.next_access_vtime; |
no test coverage detected