| 239 | #undef N_TEST |
| 240 | |
| 241 | void cal_working_set_size(reader_t *reader, int64_t *wss_obj, |
| 242 | int64_t *wss_byte) { |
| 243 | reset_reader(reader); |
| 244 | request_t *req = new_request(); |
| 245 | GHashTable *obj_table = g_hash_table_new(g_direct_hash, g_direct_equal); |
| 246 | *wss_obj = 0; |
| 247 | *wss_byte = 0; |
| 248 | |
| 249 | // sample the object space in case there are too many objects |
| 250 | // which can cause a crash |
| 251 | int scaling_factor = 1; |
| 252 | if (reader->file_size > 5 * GiB) { |
| 253 | scaling_factor = 101; |
| 254 | } else if (reader->file_size > 1 * GiB) { |
| 255 | scaling_factor = 11; |
| 256 | } |
| 257 | |
| 258 | int64_t n_req = 0; |
| 259 | INFO("calculating working set size...\n"); |
| 260 | while (read_one_req(reader, req) == 0) { |
| 261 | n_req += 1; |
| 262 | if (n_req % 2000000 == 0) { |
| 263 | DEBUG("processed %ld requests, %lld objects, %lld bytes\n", (long)n_req, |
| 264 | (long long)*wss_obj, (long long)*wss_byte); |
| 265 | } |
| 266 | if (scaling_factor > 1 && req->obj_id % scaling_factor != 0) { |
| 267 | continue; |
| 268 | } |
| 269 | |
| 270 | if (g_hash_table_contains(obj_table, (gconstpointer)req->obj_id)) { |
| 271 | continue; |
| 272 | } |
| 273 | |
| 274 | g_hash_table_add(obj_table, (gpointer)req->obj_id); |
| 275 | |
| 276 | *wss_obj += 1; |
| 277 | *wss_byte += req->obj_size; |
| 278 | } |
| 279 | *wss_obj *= scaling_factor; |
| 280 | *wss_byte *= scaling_factor; |
| 281 | |
| 282 | if (scaling_factor > 1) { |
| 283 | INFO( |
| 284 | "estimated working set size (%.2f sample ratio): %lld object %lld " |
| 285 | "byte\n", |
| 286 | 1.0 / scaling_factor, (long long)*wss_obj, (long long)*wss_byte); |
| 287 | } else { |
| 288 | INFO("working set size: %lld object %lld byte\n", (long long)*wss_obj, |
| 289 | (long long)*wss_byte); |
| 290 | } |
| 291 | |
| 292 | g_hash_table_destroy(obj_table); |
| 293 | free_request(req); |
| 294 | reset_reader(reader); |
| 295 | } |
| 296 | |
| 297 | /** |
| 298 | * @brief Create a reader from the parameters |
no test coverage detected