| 30 | } |
| 31 | |
| 32 | void mrcProfiler::MRCProfilerBase::print(const char *output_path) { |
| 33 | if (!has_run_) { |
| 34 | ERROR("MRCProfiler has not been run\n"); |
| 35 | return; |
| 36 | } |
| 37 | |
| 38 | FILE *outfp = stdout; |
| 39 | bool open_output_file = false; |
| 40 | if (output_path != nullptr && strlen(output_path) != 0) { |
| 41 | outfp = fopen(output_path, "w"); |
| 42 | open_output_file = true; |
| 43 | if (outfp == nullptr) { |
| 44 | WARN("failed to open file %s\n", output_path); |
| 45 | outfp = stdout; |
| 46 | open_output_file = false; |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | fprintf(outfp, "profiler: %s\n", profiler_name_); |
| 51 | fprintf(outfp, "trace: %s\n", reader_->trace_path); |
| 52 | fprintf(outfp, "cache_algorithm: %s\n", params_.cache_algorithm_str); |
| 53 | fprintf(outfp, "n_req: %ld\n", n_req_); |
| 54 | fprintf(outfp, "sum_obj_size_req: %ld\n", sum_obj_size_req); |
| 55 | |
| 56 | if (params_.profile_wss_ratio.size() != 0) { |
| 57 | fprintf(outfp, "wss_ratio\t"); |
| 58 | } |
| 59 | fprintf(outfp, "cache_size\tmiss_rate\tbyte_miss_rate\n"); |
| 60 | for (size_t i = 0; i < mrc_size_vec.size(); i++) { |
| 61 | if (params_.profile_wss_ratio.size() != 0) { |
| 62 | fprintf(outfp, "%lf\t", params_.profile_wss_ratio[i]); |
| 63 | } |
| 64 | double miss_rate = 1 - (double)hit_cnt_vec[i] / (n_req_); |
| 65 | double byte_miss_rate = 1 - (double)hit_size_vec[i] / (sum_obj_size_req); |
| 66 | |
| 67 | // clip to [0, 1] |
| 68 | miss_rate = miss_rate > 1 ? 1 : (miss_rate < 0 ? 0 : miss_rate); |
| 69 | byte_miss_rate = |
| 70 | byte_miss_rate > 1 ? 1 : (byte_miss_rate < 0 ? 0 : byte_miss_rate); |
| 71 | fprintf(outfp, "%ldB\t%lf\t%lf\n", mrc_size_vec[i], miss_rate, |
| 72 | byte_miss_rate); |
| 73 | } |
| 74 | |
| 75 | if (open_output_file) { |
| 76 | fclose(outfp); |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | void mrcProfiler::MRCProfilerSHARDS::run() { |
| 81 | if (has_run_) return; |
no test coverage detected