| 90 | } |
| 91 | |
| 92 | void mrcProfiler::MRCProfilerSHARDS::fixed_sample_rate_run() { |
| 93 | // 1. init |
| 94 | request_t *req = new_request(); |
| 95 | double sample_rate = params_.shards_params.sample_rate; |
| 96 | std::vector<double> local_hit_cnt_vec(mrc_size_vec.size(), 0); |
| 97 | std::vector<double> local_hit_size_vec(mrc_size_vec.size(), 0); |
| 98 | uint64_t sample_max = UINT64_MAX * sample_rate; |
| 99 | if (sample_rate == 1) { |
| 100 | INFO("sample_rate is 1, no need to sample\n"); |
| 101 | sample_max = UINT64_MAX; |
| 102 | } |
| 103 | double sampled_cnt = 0, sampled_size = 0; |
| 104 | int64_t current_time = 0; |
| 105 | robin_hood::unordered_map<obj_id_t, int64_t> last_access_time_map; |
| 106 | SplayTree<int64_t, uint64_t> rd_tree; |
| 107 | |
| 108 | // 2. go through the trace |
| 109 | read_one_req(reader_, req); |
| 110 | /* going through the trace */ |
| 111 | do { |
| 112 | DEBUG_ASSERT(req->obj_size != 0); |
| 113 | n_req_ += 1; |
| 114 | sum_obj_size_req += req->obj_size; |
| 115 | |
| 116 | uint64_t hash_value = get_hash_value_int_64_with_salt( |
| 117 | req->obj_id, params_.shards_params.salt); |
| 118 | current_time += 1; |
| 119 | if (hash_value <= sample_max) { |
| 120 | sampled_cnt += 1.0 / sample_rate; |
| 121 | sampled_size += 1.0 * req->obj_size / sample_rate; |
| 122 | |
| 123 | if (last_access_time_map.count(req->obj_id)) { |
| 124 | int64_t last_access_time = last_access_time_map[req->obj_id]; |
| 125 | size_t stack_distance = |
| 126 | rd_tree.getDistance(last_access_time) / sample_rate; |
| 127 | |
| 128 | last_access_time_map[req->obj_id] = current_time; |
| 129 | |
| 130 | // update tree |
| 131 | rd_tree.erase(last_access_time); |
| 132 | rd_tree.insert(current_time, req->obj_size); |
| 133 | |
| 134 | // find bucket to increase hit cnt and hit size |
| 135 | auto it = std::lower_bound(mrc_size_vec.begin(), mrc_size_vec.end(), |
| 136 | stack_distance); |
| 137 | |
| 138 | if (it != mrc_size_vec.end()) { |
| 139 | // update hit cnt and hit size |
| 140 | int idx = std::distance(mrc_size_vec.begin(), it); |
| 141 | local_hit_cnt_vec[idx] += 1.0 / sample_rate; |
| 142 | local_hit_size_vec[idx] += 1.0 * req->obj_size / sample_rate; |
| 143 | } |
| 144 | |
| 145 | } else { |
| 146 | last_access_time_map[req->obj_id] = current_time; |
| 147 | // update the tree |
| 148 | rd_tree.insert(current_time, req->obj_size); |
| 149 | } |
nothing calls this directly
no test coverage detected