| 133 | } |
| 134 | |
| 135 | static void _reverse_file(std::string ofilepath, struct trace_stat stat, |
| 136 | bool output_txt, bool remove_size_change) { |
| 137 | int64_t n_req = 0; |
| 138 | size_t file_size; |
| 139 | char *mapped_file = reinterpret_cast<char *>( |
| 140 | utils::setup_mmap(ofilepath + ".reverse", &file_size)); |
| 141 | size_t pos = file_size; |
| 142 | |
| 143 | std::ofstream ofile(ofilepath, |
| 144 | std::ios::out | std::ios::binary | std::ios::trunc); |
| 145 | std::ofstream ofile_txt; |
| 146 | if (output_txt) |
| 147 | ofile_txt.open(ofilepath + ".txt", std::ios::out | std::ios::trunc); |
| 148 | |
| 149 | /* we remove object size change because some of the systems do not allow |
| 150 | * object size change */ |
| 151 | std::unordered_map<uint64_t, uint32_t> last_obj_size; |
| 152 | last_obj_size.reserve(stat.n_obj); |
| 153 | |
| 154 | oracleGeneral_req_t og_req; |
| 155 | size_t req_entry_size = sizeof(oracleGeneral_req_t); |
| 156 | |
| 157 | while (pos >= req_entry_size) { |
| 158 | pos -= req_entry_size; |
| 159 | memcpy(&og_req, mapped_file + pos, req_entry_size); |
| 160 | if (og_req.next_access_vtime != -1) { |
| 161 | /* re.next_access_vtime is the vtime start from the end */ |
| 162 | og_req.next_access_vtime = stat.n_req - og_req.next_access_vtime; |
| 163 | } |
| 164 | |
| 165 | if (remove_size_change) { |
| 166 | auto it = last_obj_size.find(og_req.obj_id); |
| 167 | if (it != last_obj_size.end()) { |
| 168 | og_req.obj_size = it->second; |
| 169 | } else { |
| 170 | last_obj_size[og_req.obj_id] = og_req.obj_size; |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | ofile.write(reinterpret_cast<char *>(&og_req), req_entry_size); |
| 175 | if (output_txt) { |
| 176 | ofile_txt << og_req.clock_time << "," << og_req.obj_id << "," |
| 177 | << og_req.obj_size << "," << og_req.next_access_vtime << "\n"; |
| 178 | } |
| 179 | |
| 180 | if ((++n_req) % 100000000 == 0) { |
| 181 | INFO("%s: %ld M requests\n", ofilepath.c_str(), (long)(n_req / 1e6)); |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | munmap(mapped_file, file_size); |
| 186 | ofile.close(); |
| 187 | if (output_txt) ofile_txt.close(); |
| 188 | |
| 189 | assert(n_req == stat.n_req); |
| 190 | |
| 191 | remove((ofilepath + ".reverse").c_str()); |
| 192 |
no test coverage detected