MCPcopy Create free account
hub / github.com/1a1a11a/libCacheSim / _reverse_file

Function _reverse_file

libCacheSim/bin/traceUtils/traceConvOracleGeneral.cpp:135–195  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

133}
134
135static 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

Callers 1

convert_to_oracleGeneralFunction · 0.70

Calls 5

setup_mmapFunction · 0.85
assertFunction · 0.85
reserveMethod · 0.45
findMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected