| 55 | } |
| 56 | |
| 57 | void export_histogram_to_csv(ReuseHistogram* hist, float rate, char* path) { |
| 58 | printf("Histogram path: %s\n", path); |
| 59 | |
| 60 | FILE* file = fopen(path, "w"); |
| 61 | if (!file) return; |
| 62 | |
| 63 | fprintf(file, "Distance,Frequency\n"); |
| 64 | |
| 65 | if (hist->cold_miss_bin > 0) { |
| 66 | fprintf(file, "ColdMiss,%lu\n", hist->cold_miss_bin); |
| 67 | } |
| 68 | |
| 69 | GHashTableIter iter; |
| 70 | gpointer key, value; |
| 71 | g_hash_table_iter_init(&iter, hist->bins); |
| 72 | while (g_hash_table_iter_next(&iter, &key, &value)) { |
| 73 | uint64_t distance = *(uint64_t*)key; |
| 74 | BinEntry* bin = (BinEntry*)value; |
| 75 | double scaled_distance = (double)(distance) / (double)rate; |
| 76 | |
| 77 | if (scaled_distance > (double)UINT64_MAX) { |
| 78 | fprintf(file, "Overflow,%lu\n", bin->frequency); |
| 79 | } else { |
| 80 | fprintf(file, "%lu,%lu\n", (uint64_t)scaled_distance, bin->frequency); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | fclose(file); |
| 85 | } |
| 86 | |
| 87 | uint64_t get_min_distance(ReuseHistogram* hist) { |
| 88 | if (!hist || g_hash_table_size(hist->bins) == 0) { |
no outgoing calls
no test coverage detected