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

Method fixed_sample_size_run

libCacheSim/mrcProfiler/mrcProfiler.cpp:171–265  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

169}
170
171void mrcProfiler::MRCProfilerSHARDS::fixed_sample_size_run() {
172 // 1. init
173 request_t *req = new_request();
174 double sample_rate = 1.0;
175 std::vector<double> local_hit_cnt_vec(mrc_size_vec.size(), 0);
176 std::vector<double> local_hit_size_vec(mrc_size_vec.size(), 0);
177 double sampled_cnt = 0, sampled_size = 0;
178 int64_t current_time = 0;
179 int64_t max_to_keep = params_.shards_params.sample_size;
180
181 MinValueMap<int64_t, uint64_t> min_value_map(max_to_keep);
182 robin_hood::unordered_map<obj_id_t, int64_t> last_access_time_map;
183 SplayTree<int64_t, uint64_t> rd_tree;
184
185 // 2. go through the trace
186 read_one_req(reader_, req);
187 /* going through the trace */
188 do {
189 DEBUG_ASSERT(req->obj_size != 0);
190 n_req_ += 1;
191 sum_obj_size_req += req->obj_size;
192
193 uint64_t hash_value = get_hash_value_int_64_with_salt(
194 req->obj_id, params_.shards_params.salt);
195
196 current_time += 1;
197 if (!min_value_map.full() || hash_value < min_value_map.get_max_value() ||
198 last_access_time_map.count(req->obj_id)) {
199 // this is a sampled req
200
201 if (!last_access_time_map.count(req->obj_id)) {
202 bool poped = false;
203 int64_t poped_id = min_value_map.insert(req->obj_id, hash_value, poped);
204 if (poped) {
205 // this is a sampled req
206 int64_t poped_id_access_time = last_access_time_map[poped_id];
207 rd_tree.erase(poped_id_access_time);
208 last_access_time_map.erase(poped_id);
209 }
210 }
211
212 if (!min_value_map.full()) {
213 sample_rate = 1.0; // still 100% sample rate
214 } else {
215 sample_rate = min_value_map.get_max_value() * 1.0 /
216 UINT64_MAX; // adjust the sample rate
217 }
218
219 sampled_cnt += 1.0 / sample_rate;
220 sampled_size += 1.0 * req->obj_size / sample_rate;
221
222 if (last_access_time_map.count(req->obj_id)) {
223 int64_t last_acc_time = last_access_time_map[req->obj_id];
224 int64_t stack_distance =
225 rd_tree.getDistance(last_acc_time) * 1.0 / sample_rate;
226
227 last_access_time_map[req->obj_id] = current_time;
228

Callers

nothing calls this directly

Calls 13

new_requestFunction · 0.85
read_one_reqFunction · 0.85
free_requestFunction · 0.85
fullMethod · 0.80
get_max_valueMethod · 0.80
getDistanceMethod · 0.80
sizeMethod · 0.45
countMethod · 0.45
insertMethod · 0.45
eraseMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected