| 11 | #define MILLION 1000000ul |
| 12 | |
| 13 | void calWriteAmp(reader_t *reader, cache_t *cache) { |
| 14 | /* random seed */ |
| 15 | srand(time(NULL)); |
| 16 | set_rand_seed(rand()); |
| 17 | |
| 18 | request_t *req = new_request(); |
| 19 | read_one_req(reader, req); |
| 20 | uint64_t start_ts = (uint64_t)req->clock_time; |
| 21 | req->clock_time = 0; |
| 22 | |
| 23 | std::unordered_set<uint64_t> seen; |
| 24 | |
| 25 | int64_t n_req = 0, n_byte = 0, n_uniq_obj = 0, n_uniq_byte = 0; |
| 26 | int64_t n_miss = 0, n_miss_byte = 0; |
| 27 | while (req->valid) { |
| 28 | n_req++; |
| 29 | n_byte += req->obj_size; |
| 30 | if (seen.find(req->obj_id) == seen.end()) { |
| 31 | seen.insert(req->obj_id); |
| 32 | n_uniq_obj++; |
| 33 | n_uniq_byte += req->obj_size; |
| 34 | } |
| 35 | |
| 36 | if (cache->get(cache, req) == false) { |
| 37 | n_miss += 1; |
| 38 | n_miss_byte += req->obj_size; |
| 39 | } |
| 40 | |
| 41 | read_one_req(reader, req); |
| 42 | req->clock_time -= start_ts; |
| 43 | } |
| 44 | |
| 45 | printf("%s %32s miss ratio %.4lf byte miss ratio %.4lf, ", |
| 46 | basename(reader->trace_path), cache->cache_name, |
| 47 | n_miss / (double)n_req, n_miss_byte / (double)n_byte); |
| 48 | |
| 49 | int64_t n_byte_write = n_miss_byte; |
| 50 | if (strcasecmp("fifo", cache->cache_name) == 0) { |
| 51 | ; |
| 52 | } else if (strcasestr(cache->cache_name, "flashProb") != NULL) { |
| 53 | flashProb_params_t *params = (flashProb_params_t *)cache->eviction_params; |
| 54 | |
| 55 | n_byte_write = params->n_byte_admit_to_disk; |
| 56 | |
| 57 | if (strcasestr(params->disk->cache_name, "Clock") != NULL) { |
| 58 | Clock_params_t *clock_params = |
| 59 | (Clock_params_t *)params->disk->eviction_params; |
| 60 | n_byte_write += clock_params->n_byte_rewritten; |
| 61 | } |
| 62 | } else if (strcasecmp(cache->cache_name, "FIFO_Reinsertion") == 0) { |
| 63 | FIFO_Reinsertion_params_t *params = |
| 64 | (FIFO_Reinsertion_params_t *)cache->eviction_params; |
| 65 | |
| 66 | n_byte_write = n_miss_byte + params->n_byte_rewritten; |
| 67 | } else if (strcasestr(cache->cache_name, "TinyLFU") != NULL) { |
| 68 | WTinyLFU_params_t *params = (WTinyLFU_params_t *)cache->eviction_params; |
| 69 | n_byte_write = params->n_admit_bytes; |
| 70 |
no test coverage detected