diff --git a/libCacheSim/bin/MRC/SHARDS.c b/libCacheSim/bin/MRC/SHARDS.c index 9c98ecee..db2ca444 100644 --- a/libCacheSim/bin/MRC/SHARDS.c +++ b/libCacheSim/bin/MRC/SHARDS.c @@ -99,7 +99,7 @@ void generate_shards_mrc(struct PARAM *params, char *path) { params->reader->init_params.sampler->sampling_ratio = 1.0; params->reader->sampler->sampling_ratio = 1.0; uint64_t n_req = get_num_of_req(params->reader); - printf("n_req: %" PRIu64 "\n", n_req); + printf("n_req: %lu\n", n_req); params->reader->init_params.sampler->sampling_ratio = params->rate; params->reader->sampler->sampling_ratio = params->rate; diff --git a/libCacheSim/bin/MRC/main.c b/libCacheSim/bin/MRC/main.c index c7a3c368..13b12e9d 100644 --- a/libCacheSim/bin/MRC/main.c +++ b/libCacheSim/bin/MRC/main.c @@ -4,24 +4,20 @@ #include #include #include - #include "../../include/libCacheSim/sampling.h" #include "../cachesim/internal.h" #include "mrc_internal.h" int main(int argc, char **argv) { if (argc < 5) { - fprintf(stderr, - "Usage:\n" + fprintf(stderr, "Usage:\n" " For SHARDS:\n" - " %s SHARDS " - "[--size SIZE] [other options]\n\n" + " %s SHARDS [--size SIZE] [other options]\n\n" " For MINI:\n" - " %s MINI " - " [other options]\n", + " %s MINI [other options]\n", argv[0], argv[0]); return 1; - } +} // printf("Received Arguments:\n"); // for (int i = 0; i < argc; i++) { @@ -31,7 +27,7 @@ int main(int argc, char **argv) { char *algorithm_type = argv[1]; printf("Algorithm type: %s\n", algorithm_type); if (strcmp(algorithm_type, "MINI") == 0) { - char *path = argv[7]; + char* path=argv[7]; struct MINI_arguments arguments; parse_mini_cmd(argc, argv, &arguments); cache_stat_t *return_value = generate_mini_mrc(&arguments); @@ -43,16 +39,11 @@ int main(int argc, char **argv) { } fprintf(output_file, "Cache Size,Miss Ratio, Miss Ratio Byte\n"); - for (int i = 0; i < arguments.n_cache_size * arguments.n_eviction_algo; - i++) { - uint64_t cache_size = (uint64_t)((float)return_value[i].cache_size / - return_value[i].sampler_ratio); - double miss_ratio = - (double)return_value[i].n_miss / (double)return_value[i].n_req; - double miss_ratio_byte = (double)return_value[i].n_miss_byte / - (double)return_value[i].n_req_byte; - fprintf(output_file, "%" PRId64 ",%f, %f\n", cache_size, miss_ratio, - miss_ratio_byte); + for (int i = 0; i < arguments.n_cache_size * arguments.n_eviction_algo; i++) { + uint64_t cache_size = (uint64_t)((float)return_value[i].cache_size / return_value[i].sampler_ratio); + double miss_ratio = (double)return_value[i].n_miss / (double)return_value[i].n_req; + double miss_ratio_byte = (double)return_value[i].n_miss_byte / (double)return_value[i].n_req_byte; + fprintf(output_file, "%ld,%f, %f\n", cache_size, miss_ratio, miss_ratio_byte); } fclose(output_file); @@ -66,4 +57,4 @@ int main(int argc, char **argv) { fprintf(stderr, "Error: unknown algorithm type\n"); return 1; } -} +} \ No newline at end of file diff --git a/libCacheSim/bin/cachesim/sim.c b/libCacheSim/bin/cachesim/sim.c index 6d448d16..2103de07 100644 --- a/libCacheSim/bin/cachesim/sim.c +++ b/libCacheSim/bin/cachesim/sim.c @@ -93,7 +93,7 @@ void simulate(reader_t *reader, cache_t *cache, int report_interval, int warmup_ (double)req_cnt / 1000000.0 / runtime); } else { snprintf(output_str, 1024, - "%s %s cache size %8" PRId64 ", %16lu req, miss ratio %.4lf, throughput " + "%s %s cache size %8ld, %16lu req, miss ratio %.4lf, throughput " "%.2lf MQPS\n", reader->trace_path, detailed_cache_name, cache->cache_size, (unsigned long)req_cnt, (double)miss_cnt / (double)req_cnt, diff --git a/libCacheSim/bin/debug/aligned.c b/libCacheSim/bin/debug/aligned.c index df7b6988..45627c49 100644 --- a/libCacheSim/bin/debug/aligned.c +++ b/libCacheSim/bin/debug/aligned.c @@ -142,7 +142,7 @@ void test_unaligned_read_mmap(char* filepath) { printf("uint16_t unaligned read time: %.4f sec\n", time_read_uint16_unaligned); printf("uint8_t aligned read time: %.4f sec\n", time_read_uint8_aligned); printf("uint8_t unaligned read time: %.4f sec\n", time_read_uint8_unaligned); - printf("s: %" PRId64 "\n", s); + printf("s: %ld\n", s); close(fd); } @@ -264,7 +264,7 @@ void test_unaligned_read_mmap_struct(char* filepath) { printf("struct aligned read time: %.4f sec\n", time_read_struct_aligned); printf("struct unaligned read time: %.4f sec\n", time_read_struct_unaligned); - printf("s: %" PRId64 "\n", s); + printf("s: %ld\n", s); close(fd); } @@ -314,7 +314,7 @@ void test_unaligned_read_struct(char* filepath) { printf("struct aligned read time: %.4f sec\n", time_read_struct_aligned); printf("struct unaligned read time: %.4f sec\n", time_read_struct_unaligned); - printf("s: %" PRId64 "\n", s); + printf("s: %ld\n", s); } int main(int argc, char* argv[]) { diff --git a/libCacheSim/bin/mrcProfiler/main.cpp b/libCacheSim/bin/mrcProfiler/main.cpp index 630bff1e..c2f0fa0b 100644 --- a/libCacheSim/bin/mrcProfiler/main.cpp +++ b/libCacheSim/bin/mrcProfiler/main.cpp @@ -19,7 +19,7 @@ void print_args(struct arguments *args) { printf("trace_type: %d\n", args->trace_type); printf("trace_type_params: %s\n", args->trace_type_params); printf("ofilepath: %s\n", args->ofilepath); - printf("n_req: %" PRId64 "\n", args->n_req); + printf("n_req: %ld\n", args->n_req); printf("verbose: %d\n", args->verbose); printf("cache_algorithm_str: %s\n", args->cache_algorithm_str); printf("mrc_size_str: %s\n", args->mrc_size_str); diff --git a/libCacheSim/bin/traceUtils/traceConvLCS.cpp b/libCacheSim/bin/traceUtils/traceConvLCS.cpp index dc072787..11d0c87a 100644 --- a/libCacheSim/bin/traceUtils/traceConvLCS.cpp +++ b/libCacheSim/bin/traceUtils/traceConvLCS.cpp @@ -27,15 +27,11 @@ struct obj_info { typedef lcs_req_v3_t lcs_req_full_t; -static void _reverse_file(std::string ofilepath, lcs_trace_stat_t stat, - bool output_txt, int64_t lcs_ver); -static void _write_lcs_header(std::ofstream &ofile, lcs_trace_stat_t &stat, - int64_t lcs_ver); -static void _analyze_trace( - lcs_trace_stat_t &stat, - const std::unordered_map &obj_map, - const std::unordered_map &tenant_cnt, - const std::unordered_map &ttl_cnt); +static void _reverse_file(std::string ofilepath, lcs_trace_stat_t stat, bool output_txt, int64_t lcs_ver); +static void _write_lcs_header(std::ofstream &ofile, lcs_trace_stat_t &stat, int64_t lcs_ver); +static void _analyze_trace(lcs_trace_stat_t &stat, const std::unordered_map &obj_map, + const std::unordered_map &tenant_cnt, + const std::unordered_map &ttl_cnt); /** * @brief Convert a trace to lcs format @@ -47,11 +43,9 @@ static void _analyze_trace( * @param remove_size_change * @param lcs_ver the version of lcs format, see lcs.h for more details */ -void convert_to_lcs(reader_t *reader, std::string ofilepath, bool output_txt, - bool remove_size_change, int lcs_ver) { +void convert_to_lcs(reader_t *reader, std::string ofilepath, bool output_txt, bool remove_size_change, int lcs_ver) { request_t *req = new_request(); - std::ofstream ofile_temp(ofilepath + ".reverse", - std::ios::out | std::ios::binary | std::ios::trunc); + std::ofstream ofile_temp(ofilepath + ".reverse", std::ios::out | std::ios::binary | std::ios::trunc); std::unordered_map obj_map; std::unordered_map tenant_cnt; std::unordered_map ttl_cnt; @@ -63,31 +57,23 @@ void convert_to_lcs(reader_t *reader, std::string ofilepath, bool output_txt, int64_t n_req_total = get_num_of_req(reader); obj_map.reserve(n_req_total / 100 + 1e4); - INFO("%s: %.2f M requests in total\n", reader->trace_path, - (double)n_req_total / 1.0e6); + INFO("%s: %.2f M requests in total\n", reader->trace_path, (double)n_req_total / 1.0e6); reader->read_direction = READ_BACKWARD; reader_set_read_pos(reader, 1.0); go_back_one_req(reader); read_one_req(reader, req); - // because we read backwards, the first request is the last request in the - // trace + // because we read backwards, the first request is the last request in the trace stat.end_timestamp = req->clock_time; while (true) { if (lcs_ver == 1 || lcs_ver == 2) { if (req->clock_time > UINT32_MAX) { - WARN( - "clock_time %" PRId64 " > UINT32_MAX, may cause overflow consider using " - "lcs_ver 3\n", - req->clock_time); + WARN("clock_time %ld > UINT32_MAX, may cause overflow consider using lcs_ver 3\n", req->clock_time); } if (req->obj_size > UINT32_MAX) { - WARN( - "obj_size %" PRId64 " > UINT32_MAX, may cause overflow consider using " - "lcs_ver 3\n", - req->obj_size); + WARN("obj_size %ld > UINT32_MAX, may cause overflow consider using lcs_ver 3\n", req->obj_size); } } @@ -105,10 +91,8 @@ void convert_to_lcs(reader_t *reader, std::string ofilepath, bool output_txt, info_it->second.freq++; if (info_it->second.size != req->obj_size) { if (!remove_size_change) { - WARN( - "find object size change, prev %" PRId64 " new %" PRId64 ", please enable " - "remove_size_change\n", - info_it->second.size, req->obj_size); + WARN("find object size change, prev %ld new %ld, please enable remove_size_change\n", info_it->second.size, + req->obj_size); } else { req->obj_size = info_it->second.size; } @@ -124,11 +108,9 @@ void convert_to_lcs(reader_t *reader, std::string ofilepath, bool output_txt, lcs_req.ttl = req->ttl; lcs_req.next_access_vtime = req->next_access_vtime; - if (lcs_req.op == OP_GET || lcs_req.op == OP_GETS || - lcs_req.op == OP_READ) { + if (lcs_req.op == OP_GET || lcs_req.op == OP_GETS || lcs_req.op == OP_READ) { stat.n_read++; - } else if (lcs_req.op == OP_WRITE || lcs_req.op == OP_SET || - lcs_req.op == OP_REPLACE || lcs_req.op == OP_ADD || + } else if (lcs_req.op == OP_WRITE || lcs_req.op == OP_SET || lcs_req.op == OP_REPLACE || lcs_req.op == OP_ADD || lcs_req.op == OP_UPDATE) { stat.n_write++; } else if (lcs_req.op == OP_DELETE) { @@ -149,11 +131,9 @@ void convert_to_lcs(reader_t *reader, std::string ofilepath, bool output_txt, ttl_cnt[req->ttl]++; } - ofile_temp.write(reinterpret_cast(&lcs_req), - sizeof(lcs_req_full_t)); + ofile_temp.write(reinterpret_cast(&lcs_req), sizeof(lcs_req_full_t)); for (int i = 0; i < n_features; i++) { - ofile_temp.write(reinterpret_cast(&req->features[i]), - sizeof(int32_t)); + ofile_temp.write(reinterpret_cast(&req->features[i]), sizeof(int32_t)); } stat.n_req_byte += req->obj_size; @@ -161,16 +141,15 @@ void convert_to_lcs(reader_t *reader, std::string ofilepath, bool output_txt, if (stat.n_req % 100000000 == 0) { INFO( - "%s: %f M requests (%.2lf GB), trace time %ld, working set %" PRId64 " " - "object, %" PRId64 " B (%.2lf GB)\n", - reader->trace_path, stat.n_req / 1e6, - (double)stat.n_req_byte / GiB, - (long)(stat.end_timestamp - req->clock_time), stat.n_obj, - stat.n_obj_byte, (double)stat.n_obj_byte / GiB); + "%s: %ld M requests (%.2lf GB), trace time %ld, working set %lld " + "object, %lld B (%.2lf GB)\n", + reader->trace_path, (long)(stat.n_req / 1e6), (double)stat.n_req_byte / GiB, + (long)(stat.end_timestamp - req->clock_time), (long long)stat.n_obj, (long long)stat.n_obj_byte, + (double)stat.n_obj_byte / GiB); } if (stat.n_req > n_req_total * 2) { - ERROR("n_req_curr (%" PRId64 ") > n_req_total (%" PRId64 ")\n", stat.n_req, n_req_total); + ERROR("n_req_curr (%ld) > n_req_total (%ld)\n", stat.n_req, n_req_total); } if (read_one_req_above(reader, req) != 0) { @@ -192,8 +171,7 @@ void convert_to_lcs(reader_t *reader, std::string ofilepath, bool output_txt, _reverse_file(ofilepath, stat, output_txt, lcs_ver); } -static void _write_lcs_header(std::ofstream &ofile, lcs_trace_stat_t &stat, - int64_t lcs_ver) { +static void _write_lcs_header(std::ofstream &ofile, lcs_trace_stat_t &stat, int64_t lcs_ver) { lcs_trace_header_t lcs_header; memset(&lcs_header, 0, sizeof(lcs_header)); lcs_header.start_magic = LCS_TRACE_START_MAGIC; @@ -201,28 +179,21 @@ static void _write_lcs_header(std::ofstream &ofile, lcs_trace_stat_t &stat, lcs_header.stat = stat; lcs_header.version = lcs_ver; - ofile.write(reinterpret_cast(&lcs_header), - sizeof(lcs_trace_header_t)); + ofile.write(reinterpret_cast(&lcs_header), sizeof(lcs_trace_header_t)); } -static void _analyze_trace( - lcs_trace_stat_t &stat, - const std::unordered_map &obj_map, - const std::unordered_map &tenant_cnt, - const std::unordered_map &ttl_cnt) { +static void _analyze_trace(lcs_trace_stat_t &stat, const std::unordered_map &obj_map, + const std::unordered_map &tenant_cnt, + const std::unordered_map &ttl_cnt) { INFO("########################################\n"); - INFO( - "trace stat: n_req %lld, n_obj %lld, n_byte %lld (%.2lf GiB), " - "n_uniq_byte %lld (%.2lf GiB)\n", - (long long)stat.n_req, (long long)stat.n_obj, (long long)stat.n_req_byte, - (double)stat.n_req_byte / GiB, (long long)stat.n_obj_byte, - (double)stat.n_obj_byte / GiB); - INFO("n_read %lld, n_write %lld, n_delete %lld\n", (long long)stat.n_read, - (long long)stat.n_write, (long long)stat.n_delete); - - INFO("start time %lld, end time %lld, duration %lld seconds %.2lf days\n", - (long long)stat.start_timestamp, (long long)stat.end_timestamp, - (long long)(stat.end_timestamp - stat.start_timestamp), + INFO("trace stat: n_req %lld, n_obj %lld, n_byte %lld (%.2lf GiB), n_uniq_byte %lld (%.2lf GiB)\n", + (long long)stat.n_req, (long long)stat.n_obj, (long long)stat.n_req_byte, (double)stat.n_req_byte / GiB, + (long long)stat.n_obj_byte, (double)stat.n_obj_byte / GiB); + INFO("n_read %lld, n_write %lld, n_delete %lld\n", (long long)stat.n_read, (long long)stat.n_write, + (long long)stat.n_delete); + + INFO("start time %lld, end time %lld, duration %lld seconds %.2lf days\n", (long long)stat.start_timestamp, + (long long)stat.end_timestamp, (long long)(stat.end_timestamp - stat.start_timestamp), (double)(stat.end_timestamp - stat.start_timestamp) / (24 * 3600.0)); /**** analyze object size ****/ @@ -243,26 +214,19 @@ static void _analyze_trace( } } - std::vector> size_cnt_vec(size_cnt.begin(), - size_cnt.end()); - std::sort(size_cnt_vec.begin(), size_cnt_vec.end(), - [](const auto &a, const auto &b) { return a.second > b.second; }); - for (size_t i = 0; i < std::min(size_cnt_vec.size(), (size_t)N_MOST_COMMON); - i++) { + std::vector> size_cnt_vec(size_cnt.begin(), size_cnt.end()); + std::sort(size_cnt_vec.begin(), size_cnt_vec.end(), [](const auto &a, const auto &b) { return a.second > b.second; }); + for (size_t i = 0; i < std::min(size_cnt_vec.size(), (size_t)N_MOST_COMMON); i++) { stat.most_common_obj_sizes[i] = size_cnt_vec[i].first; - stat.most_common_obj_size_ratio[i] = - (float)size_cnt_vec[i].second / stat.n_obj; + stat.most_common_obj_size_ratio[i] = (float)size_cnt_vec[i].second / stat.n_obj; } - INFO("object size: smallest %lld, largest %lld\n", - (long long)stat.smallest_obj_size, (long long)stat.largest_obj_size); - INFO( - "most common object sizes (req fraction): %" PRId64 "(%.4lf) %" PRId64 "(%.4lf) " - "%" PRId64 "(%.4lf) %" PRId64 "(%.4lf)...\n", - stat.most_common_obj_sizes[0], stat.most_common_obj_size_ratio[0], - stat.most_common_obj_sizes[1], stat.most_common_obj_size_ratio[1], - stat.most_common_obj_sizes[2], stat.most_common_obj_size_ratio[2], - stat.most_common_obj_sizes[3], stat.most_common_obj_size_ratio[3]); + INFO("object size: smallest %lld, largest %lld\n", (long long)stat.smallest_obj_size, + (long long)stat.largest_obj_size); + INFO("most common object sizes (req fraction): %ld(%.4lf) %ld(%.4lf) %ld(%.4lf) %ld(%.4lf)...\n", + stat.most_common_obj_sizes[0], stat.most_common_obj_size_ratio[0], stat.most_common_obj_sizes[1], + stat.most_common_obj_size_ratio[1], stat.most_common_obj_sizes[2], stat.most_common_obj_size_ratio[2], + stat.most_common_obj_sizes[3], stat.most_common_obj_size_ratio[3]); /**** analyze object popularity ****/ std::unordered_map freq_cnt; @@ -275,12 +239,9 @@ static void _analyze_trace( } // sort by freq - std::vector> freq_cnt_vec(freq_cnt.begin(), - freq_cnt.end()); - std::sort(freq_cnt_vec.begin(), freq_cnt_vec.end(), - [](const auto &a, const auto &b) { return a.first > b.first; }); - for (size_t i = 0; i < std::min(freq_cnt_vec.size(), (size_t)N_MOST_COMMON); - i++) { + std::vector> freq_cnt_vec(freq_cnt.begin(), freq_cnt.end()); + std::sort(freq_cnt_vec.begin(), freq_cnt_vec.end(), [](const auto &a, const auto &b) { return a.first > b.first; }); + for (size_t i = 0; i < std::min(freq_cnt_vec.size(), (size_t)N_MOST_COMMON); i++) { stat.highest_freq[i] = freq_cnt_vec[i].first; } @@ -303,80 +264,57 @@ static void _analyze_trace( stat.skewness = -slope; // sort by freq count - std::sort(freq_cnt_vec.begin(), freq_cnt_vec.end(), - [](const auto &a, const auto &b) { return a.second > b.second; }); - for (size_t i = 0; i < std::min(freq_cnt_vec.size(), (size_t)N_MOST_COMMON); - i++) { + std::sort(freq_cnt_vec.begin(), freq_cnt_vec.end(), [](const auto &a, const auto &b) { return a.second > b.second; }); + for (size_t i = 0; i < std::min(freq_cnt_vec.size(), (size_t)N_MOST_COMMON); i++) { stat.most_common_freq[i] = freq_cnt_vec[i].first; stat.most_common_freq_ratio[i] = (float)freq_cnt_vec[i].second / stat.n_obj; } - INFO("highest freq: %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " skewness %.4lf\n", stat.highest_freq[0], - stat.highest_freq[1], stat.highest_freq[2], stat.highest_freq[3], - stat.skewness); - INFO( - "most common freq (req fraction): %d(%.4lf) %d(%.4lf) %d(%.4lf) " - "%d(%.4lf)...\n", - stat.most_common_freq[0], stat.most_common_freq_ratio[0], - stat.most_common_freq[1], stat.most_common_freq_ratio[1], - stat.most_common_freq[2], stat.most_common_freq_ratio[2], - stat.most_common_freq[3], stat.most_common_freq_ratio[3]); + INFO("highest freq: %ld %ld %ld %ld skewness %.4lf\n", stat.highest_freq[0], stat.highest_freq[1], + stat.highest_freq[2], stat.highest_freq[3], stat.skewness); + INFO("most common freq (req fraction): %d(%.4lf) %d(%.4lf) %d(%.4lf) %d(%.4lf)...\n", stat.most_common_freq[0], + stat.most_common_freq_ratio[0], stat.most_common_freq[1], stat.most_common_freq_ratio[1], + stat.most_common_freq[2], stat.most_common_freq_ratio[2], stat.most_common_freq[3], + stat.most_common_freq_ratio[3]); /**** analyze tenant ****/ stat.n_tenant = tenant_cnt.size(); - std::vector> tenant_cnt_vec(tenant_cnt.begin(), - tenant_cnt.end()); + std::vector> tenant_cnt_vec(tenant_cnt.begin(), tenant_cnt.end()); std::sort(tenant_cnt_vec.begin(), tenant_cnt_vec.end(), [](const auto &a, const auto &b) { return a.second > b.second; }); - for (size_t i = 0; i < std::min(tenant_cnt_vec.size(), (size_t)N_MOST_COMMON); - i++) { + for (size_t i = 0; i < std::min(tenant_cnt_vec.size(), (size_t)N_MOST_COMMON); i++) { stat.most_common_tenants[i] = tenant_cnt_vec[i].first; - stat.most_common_tenant_ratio[i] = - (float)tenant_cnt_vec[i].second / stat.n_req; + stat.most_common_tenant_ratio[i] = (float)tenant_cnt_vec[i].second / stat.n_req; } if (stat.n_tenant > 1) { INFO("#tenant: %ld\n", (long)stat.n_tenant); - INFO( - "most common tenants (req fraction): %d(%.4lf) %d(%.4lf) %d(%.4lf) " - "%d(%.4lf)...\n", - stat.most_common_tenants[0], stat.most_common_tenant_ratio[0], - stat.most_common_tenants[1], stat.most_common_tenant_ratio[1], - stat.most_common_tenants[2], stat.most_common_tenant_ratio[2], - stat.most_common_tenants[3], stat.most_common_tenant_ratio[3]); + INFO("most common tenants (req fraction): %d(%.4lf) %d(%.4lf) %d(%.4lf) %d(%.4lf)...\n", + stat.most_common_tenants[0], stat.most_common_tenant_ratio[0], stat.most_common_tenants[1], + stat.most_common_tenant_ratio[1], stat.most_common_tenants[2], stat.most_common_tenant_ratio[2], + stat.most_common_tenants[3], stat.most_common_tenant_ratio[3]); } /**** analyze ttl ****/ stat.n_ttl = ttl_cnt.size(); - std::vector> ttl_cnt_vec(ttl_cnt.begin(), - ttl_cnt.end()); - std::sort(ttl_cnt_vec.begin(), ttl_cnt_vec.end(), - [](const auto &a, const auto &b) { return a.second > b.second; }); - stat.smallest_ttl = std::min_element(ttl_cnt_vec.begin(), ttl_cnt_vec.end(), - [](const auto &a, const auto &b) { - return a.first < b.first; - }) - ->first; - stat.largest_ttl = std::max_element(ttl_cnt_vec.begin(), ttl_cnt_vec.end(), - [](const auto &a, const auto &b) { - return a.first < b.first; - }) - ->first; - for (size_t i = 0; i < std::min(ttl_cnt_vec.size(), (size_t)N_MOST_COMMON); - i++) { + std::vector> ttl_cnt_vec(ttl_cnt.begin(), ttl_cnt.end()); + std::sort(ttl_cnt_vec.begin(), ttl_cnt_vec.end(), [](const auto &a, const auto &b) { return a.second > b.second; }); + stat.smallest_ttl = std::min_element(ttl_cnt_vec.begin(), ttl_cnt_vec.end(), [](const auto &a, const auto &b) { + return a.first < b.first; + })->first; + stat.largest_ttl = std::max_element(ttl_cnt_vec.begin(), ttl_cnt_vec.end(), [](const auto &a, const auto &b) { + return a.first < b.first; + })->first; + for (size_t i = 0; i < std::min(ttl_cnt_vec.size(), (size_t)N_MOST_COMMON); i++) { stat.most_common_ttls[i] = ttl_cnt_vec[i].first; stat.most_common_ttl_ratio[i] = (float)ttl_cnt_vec[i].second / stat.n_req; } if (stat.n_ttl > 1) { INFO("#ttl: %ld\n", (long)stat.n_ttl); - INFO("smallest ttl: %ld, largest ttl: %ld\n", (long)stat.smallest_ttl, - (long)stat.largest_ttl); - INFO( - "most common ttls (req fraction): %d(%.4lf) %d(%.4lf) %d(%.4lf) " - "%d(%.4lf)...\n", - stat.most_common_ttls[0], stat.most_common_ttl_ratio[0], - stat.most_common_ttls[1], stat.most_common_ttl_ratio[1], - stat.most_common_ttls[2], stat.most_common_ttl_ratio[2], - stat.most_common_ttls[3], stat.most_common_ttl_ratio[3]); + INFO("smallest ttl: %ld, largest ttl: %ld\n", (long)stat.smallest_ttl, (long)stat.largest_ttl); + INFO("most common ttls (req fraction): %d(%.4lf) %d(%.4lf) %d(%.4lf) %d(%.4lf)...\n", stat.most_common_ttls[0], + stat.most_common_ttl_ratio[0], stat.most_common_ttls[1], stat.most_common_ttl_ratio[1], + stat.most_common_ttls[2], stat.most_common_ttl_ratio[2], stat.most_common_ttls[3], + stat.most_common_ttl_ratio[3]); } INFO("########################################\n"); } @@ -389,21 +327,17 @@ static void _analyze_trace( * @param output_txt * @param lcs_ver */ -static void _reverse_file(std::string ofilepath, lcs_trace_stat_t stat, - bool output_txt, int64_t lcs_ver) { +static void _reverse_file(std::string ofilepath, lcs_trace_stat_t stat, bool output_txt, int64_t lcs_ver) { size_t file_size; - char *mapped_file = reinterpret_cast( - utils::setup_mmap(ofilepath + ".reverse", &file_size)); + char *mapped_file = reinterpret_cast(utils::setup_mmap(ofilepath + ".reverse", &file_size)); size_t pos = file_size; - std::ofstream ofile(ofilepath, - std::ios::out | std::ios::binary | std::ios::trunc); + std::ofstream ofile(ofilepath, std::ios::out | std::ios::binary | std::ios::trunc); _write_lcs_header(ofile, stat, lcs_ver); INFO("start to reverse the trace...\n"); std::ofstream ofile_txt; - if (output_txt) - ofile_txt.open(ofilepath + ".txt", std::ios::out | std::ios::trunc); + if (output_txt) ofile_txt.open(ofilepath + ".txt", std::ios::out | std::ios::trunc); lcs_req_full_t lcs_req_full; size_t lcs_full_req_entry_size = sizeof(lcs_req_full_t); @@ -421,8 +355,7 @@ static void _reverse_file(std::string ofilepath, lcs_trace_stat_t stat, memcpy(&lcs_req_full, mapped_file + pos, lcs_full_req_entry_size); if (lcs_req_full.next_access_vtime != INT64_MAX) { /* req.next_access_vtime is the vtime start from the end */ - lcs_req_full.next_access_vtime = - stat.n_req - lcs_req_full.next_access_vtime; + lcs_req_full.next_access_vtime = stat.n_req - lcs_req_full.next_access_vtime; } if (lcs_ver == 1) { @@ -465,15 +398,13 @@ static void _reverse_file(std::string ofilepath, lcs_trace_stat_t stat, base.next_access_vtime = lcs_req_full.next_access_vtime; ofile.write(reinterpret_cast(&base), sizeof(lcs_req_v3)); - ofile.write(mapped_file + pos + lcs_full_req_entry_size, - n_features * sizeof(int32_t)); + ofile.write(mapped_file + pos + lcs_full_req_entry_size, n_features * sizeof(int32_t)); } else { - ERROR("invalid lcs version %" PRId64 "\n", lcs_ver); + ERROR("invalid lcs version %ld\n", lcs_ver); } if (output_txt) { - ofile_txt << lcs_req_full.clock_time << "," << lcs_req_full.obj_id << "," - << lcs_req_full.obj_size << "," + ofile_txt << lcs_req_full.clock_time << "," << lcs_req_full.obj_id << "," << lcs_req_full.obj_size << "," << lcs_req_full.next_access_vtime << "\n"; } } @@ -487,4 +418,4 @@ static void _reverse_file(std::string ofilepath, lcs_trace_stat_t stat, INFO("trace conversion finished, output %s\n", ofilepath.c_str()); } -} // namespace traceConv +} // namespace traceConv \ No newline at end of file diff --git a/libCacheSim/bin/traceUtils/traceConvOracleGeneral.cpp b/libCacheSim/bin/traceUtils/traceConvOracleGeneral.cpp index 826da9c5..1f21cc34 100644 --- a/libCacheSim/bin/traceUtils/traceConvOracleGeneral.cpp +++ b/libCacheSim/bin/traceUtils/traceConvOracleGeneral.cpp @@ -100,7 +100,7 @@ void convert_to_oracleGeneral(reader_t *reader, std::string ofilepath, } if (n_req_curr > n_req_total * 2) { - ERROR("n_req_curr (%" PRId64 ") > n_req_total (%" PRId64 ")\n", n_req_curr, n_req_total); + ERROR("n_req_curr (%ld) > n_req_total (%ld)\n", n_req_curr, n_req_total); } if (read_one_req_above(reader, req) != 0) { diff --git a/libCacheSim/cache/admission/adaptsize/adaptsize_interface.cpp b/libCacheSim/cache/admission/adaptsize/adaptsize_interface.cpp index e894094f..88769278 100644 --- a/libCacheSim/cache/admission/adaptsize/adaptsize_interface.cpp +++ b/libCacheSim/cache/admission/adaptsize/adaptsize_interface.cpp @@ -2,7 +2,6 @@ #include #include #include -#include #include "../../include/libCacheSim/admissionAlgo.h" #include "adaptsize/adaptsize.h" @@ -90,7 +89,7 @@ static void adaptsize_admissioner_parse_params( } else if (strcasecmp(key, "reconf-interval") == 0) { pa->reconf_interval = strtoull(value, &end, 10); } else if (strcasecmp(key, "print") == 0) { - printf("max-iteration=%" PRIu64 ",reconf-interval=%" PRIu64 "", pa->max_iteration, + printf("max-iteration=%lu,reconf-interval=%lu", pa->max_iteration, pa->reconf_interval); exit(0); } else { diff --git a/libCacheSim/cache/eviction/BeladySize.c b/libCacheSim/cache/eviction/BeladySize.c index b39a2e63..015e3f3b 100644 --- a/libCacheSim/cache/eviction/BeladySize.c +++ b/libCacheSim/cache/eviction/BeladySize.c @@ -28,12 +28,10 @@ typedef struct { // **** **** // *********************************************************************** -static void BeladySize_parse_params(cache_t *cache, - const char *cache_specific_params); +static void BeladySize_parse_params(cache_t *cache, const char *cache_specific_params); static void BeladySize_free(cache_t *cache); static bool BeladySize_get(cache_t *cache, const request_t *req); -static cache_obj_t *BeladySize_find(cache_t *cache, const request_t *req, - const bool update_cache); +static cache_obj_t *BeladySize_find(cache_t *cache, const request_t *req, const bool update_cache); static cache_obj_t *BeladySize_insert(cache_t *cache, const request_t *req); static cache_obj_t *BeladySize_to_evict(cache_t *cache, const request_t *req); static void BeladySize_evict(cache_t *cache, const request_t *req); @@ -53,10 +51,8 @@ static void BeladySize_remove_obj(cache_t *cache, cache_obj_t *obj); * @param ccache_params some common cache parameters * @param cache_specific_params Belady specific parameters, should be NULL */ -cache_t *BeladySize_init(const common_cache_params_t ccache_params, - const char *cache_specific_params) { - cache_t *cache = - cache_struct_init("BeladySize", ccache_params, cache_specific_params); +cache_t *BeladySize_init(const common_cache_params_t ccache_params, const char *cache_specific_params) { + cache_t *cache = cache_struct_init("BeladySize", ccache_params, cache_specific_params); cache->cache_init = BeladySize_init; cache->cache_free = BeladySize_free; @@ -67,8 +63,7 @@ cache_t *BeladySize_init(const common_cache_params_t ccache_params, cache->remove = BeladySize_remove; cache->to_evict = BeladySize_to_evict; - BeladySize_params_t *params = - (BeladySize_params_t *)malloc(sizeof(BeladySize_params_t)); + BeladySize_params_t *params = (BeladySize_params_t *)malloc(sizeof(BeladySize_params_t)); cache->eviction_params = params; BeladySize_parse_params(cache, DEFAULT_PARAMS); @@ -108,9 +103,7 @@ static void BeladySize_free(cache_t *cache) { * @param req * @return true if cache hit, false if cache miss */ -static bool BeladySize_get(cache_t *cache, const request_t *req) { - return cache_get_base(cache, req); -} +static bool BeladySize_get(cache_t *cache, const request_t *req) { return cache_get_base(cache, req); } // *********************************************************************** // **** **** @@ -128,8 +121,7 @@ static bool BeladySize_get(cache_t *cache, const request_t *req) { * and if the object is expired, it is removed from the cache * @return the object or NULL if not found */ -static cache_obj_t *BeladySize_find(cache_t *cache, const request_t *req, - const bool update_cache) { +static cache_obj_t *BeladySize_find(cache_t *cache, const request_t *req, const bool update_cache) { cache_obj_t *obj = cache_find_base(cache, req, update_cache); if (!update_cache) { @@ -175,18 +167,15 @@ struct hash_iter_user_data { uint64_t max_score; }; -static inline void hashtable_iter_Belady_size(cache_obj_t *cache_obj, - void *userdata) { - struct hash_iter_user_data *iter_userdata = - (struct hash_iter_user_data *)userdata; +static inline void hashtable_iter_Belady_size(cache_obj_t *cache_obj, void *userdata) { + struct hash_iter_user_data *iter_userdata = (struct hash_iter_user_data *)userdata; if (iter_userdata->max_score == UINT64_MAX) return; uint64_t obj_score; if (cache_obj->Belady.next_access_vtime == -1) obj_score = UINT64_MAX; else - obj_score = cache_obj->obj_size * (cache_obj->Belady.next_access_vtime - - iter_userdata->curr_vtime); + obj_score = cache_obj->obj_size * (cache_obj->Belady.next_access_vtime - iter_userdata->curr_vtime); if (obj_score > iter_userdata->max_score) { iter_userdata->to_evict_obj = cache_obj; @@ -210,8 +199,7 @@ static cache_obj_t *BeladySize_to_evict(cache_t *cache, const request_t *req) { iter_userdata.max_score = 0; iter_userdata.to_evict_obj = NULL; - hashtable_foreach(cache->hashtable, hashtable_iter_Belady_size, - &iter_userdata); + hashtable_foreach(cache->hashtable, hashtable_iter_Belady_size, &iter_userdata); return iter_userdata.to_evict_obj; } @@ -224,8 +212,7 @@ static cache_obj_t *BeladySize_to_evict(cache_t *cache, const request_t *req) { for (int i = 0; i < params->n_sample; i++) { sampled_obj = hashtable_rand_obj(cache->hashtable); sampled_obj_score = - log((double)sampled_obj->obj_size) + - log((double)(sampled_obj->Belady.next_access_vtime - cache->n_req)); + log((double)sampled_obj->obj_size) + log((double)(sampled_obj->Belady.next_access_vtime - cache->n_req)); if (obj_to_evict_score < sampled_obj_score) { obj_to_evict = sampled_obj; obj_to_evict_score = sampled_obj_score; @@ -235,12 +222,10 @@ static cache_obj_t *BeladySize_to_evict(cache_t *cache, const request_t *req) { WARN( "BeladySize_to_evict: obj_to_evict is NULL, " "maybe cache size is too small or hash power too large, " - "current hash table size %" PRIu64 ", n_obj %" PRIu64 ", cache size %" PRIu64 ", request size " - "%" PRIu64 ", and %d samples " + "current hash table size %lu, n_obj %lu, cache size %lu, request size %lu, and %d samples " "obj_to_evict_score %.4lf sampled_obj_score %.4lf\n", - hashsize(cache->hashtable->hashpower), cache->hashtable->n_obj, - cache->cache_size, req->obj_size, params->n_sample, obj_to_evict_score, - sampled_obj_score); + hashsize(cache->hashtable->hashpower), cache->hashtable->n_obj, cache->cache_size, req->obj_size, + params->n_sample, obj_to_evict_score, sampled_obj_score); return BeladySize_to_evict(cache, req); } @@ -292,8 +277,7 @@ static const char *BeladySize_current_params(BeladySize_params_t *params) { * to see the default parameters, use current_params() * or use -e "print" with cachesim */ -static void BeladySize_parse_params(cache_t *cache, - const char *cache_specific_params) { +static void BeladySize_parse_params(cache_t *cache, const char *cache_specific_params) { BeladySize_params_t *params = (BeladySize_params_t *)cache->eviction_params; char *params_str = strdup(cache_specific_params); char *old_params_str = params_str; @@ -319,8 +303,7 @@ static void BeladySize_parse_params(cache_t *cache, printf("current parameters: %s\n", BeladySize_current_params(params)); exit(0); } else { - ERROR("%s does not have parameter %s, support %s\n", cache->cache_name, - key, BeladySize_current_params(params)); + ERROR("%s does not have parameter %s, support %s\n", cache->cache_name, key, BeladySize_current_params(params)); exit(1); } } diff --git a/libCacheSim/cache/eviction/LIRS.c b/libCacheSim/cache/eviction/LIRS.c index 2e5606c0..5a6c21e3 100644 --- a/libCacheSim/cache/eviction/LIRS.c +++ b/libCacheSim/cache/eviction/LIRS.c @@ -711,7 +711,7 @@ static void LIRS_print_cache(cache_t *cache) { (unsigned long)params->hirs_count); cache_obj_t *obj = ((LRU_params_t *)params->LRU_s->eviction_params)->q_head; while (obj) { - printf("%" PRId64 "(%" PRId64 ", %s, %s)->", obj->obj_id, obj->obj_size, + printf("%ld(%lu, %s, %s)->", (long)obj->obj_id, obj->obj_size, obj->LIRS.in_cache ? "R" : "N", obj->LIRS.is_LIR ? "L" : "H"); obj = obj->queue.next; } @@ -720,7 +720,7 @@ static void LIRS_print_cache(cache_t *cache) { printf("Q Stack: \n"); cache_obj_t *obj_q = ((LRU_params_t *)params->LRU_q->eviction_params)->q_head; while (obj_q) { - printf("%ld(%" PRId64 ", %s, %s)->", (long)obj_q->obj_id, obj_q->obj_size, + printf("%ld(%lu, %s, %s)->", (long)obj_q->obj_id, obj_q->obj_size, obj_q->LIRS.in_cache ? "R" : "N", obj_q->LIRS.is_LIR ? "L" : "H"); obj_q = obj_q->queue.next; } @@ -730,7 +730,7 @@ static void LIRS_print_cache(cache_t *cache) { cache_obj_t *obj_nh = ((LRU_params_t *)params->LRU_nh->eviction_params)->q_head; while (obj_nh) { - printf("%ld(%" PRId64 ", %s, %s)->", (long)obj_nh->obj_id, obj_nh->obj_size, + printf("%ld(%lu, %s, %s)->", (long)obj_nh->obj_id, obj_nh->obj_size, obj_nh->LIRS.in_cache ? "R" : "N", obj_nh->LIRS.is_LIR ? "L" : "H"); obj_nh = obj_nh->queue.next; } diff --git a/libCacheSim/cache/eviction/SLRUv0.c b/libCacheSim/cache/eviction/SLRUv0.c index 8ef48888..8aee64bc 100644 --- a/libCacheSim/cache/eviction/SLRUv0.c +++ b/libCacheSim/cache/eviction/SLRUv0.c @@ -20,6 +20,7 @@ typedef struct SLRUv0_params { request_t *req_local; } SLRUv0_params_t; + static const char *DEFAULT_CACHE_PARAMS = "n-seg=4"; // *********************************************************************** @@ -432,7 +433,7 @@ static void SLRUv0_print_cache(cache_t *cache) { cache_obj_t *obj = ((LRU_params_t *)params->LRUs[i]->eviction_params)->q_head; while (obj) { - printf("%ld(%" PRId64 ")->", (long)obj->obj_id, obj->obj_size); + printf("%ld(%lu)->", (long) obj->obj_id, obj->obj_size); obj = obj->queue.next; } printf(" | "); diff --git a/libCacheSim/cache/eviction/cpp/GDSF.cpp b/libCacheSim/cache/eviction/cpp/GDSF.cpp index 9518aa19..86fd49f2 100644 --- a/libCacheSim/cache/eviction/cpp/GDSF.cpp +++ b/libCacheSim/cache/eviction/cpp/GDSF.cpp @@ -23,13 +23,11 @@ extern "C" { // **** **** // *********************************************************************** -cache_t *GDSF_init(const common_cache_params_t ccache_params, - const char *cache_specific_params); +cache_t *GDSF_init(const common_cache_params_t ccache_params, const char *cache_specific_params); static void GDSF_free(cache_t *cache); static bool GDSF_get(cache_t *cache, const request_t *req); -static cache_obj_t *GDSF_find(cache_t *cache, const request_t *req, - const bool update_cache); +static cache_obj_t *GDSF_find(cache_t *cache, const request_t *req, const bool update_cache); static cache_obj_t *GDSF_insert(cache_t *cache, const request_t *req); static cache_obj_t *GDSF_to_evict(cache_t *cache, const request_t *req); static void GDSF_evict(cache_t *cache, const request_t *req); @@ -50,10 +48,8 @@ static bool GDSF_remove(cache_t *cache, const obj_id_t obj_id); * @param cache_specific_params cache specific parameters, see parse_params * function or use -e "print" with the cachesim binary */ -cache_t *GDSF_init(const common_cache_params_t ccache_params, - const char *cache_specific_params) { - cache_t *cache = - cache_struct_init("GDSF", ccache_params, cache_specific_params); +cache_t *GDSF_init(const common_cache_params_t ccache_params, const char *cache_specific_params) { + cache_t *cache = cache_struct_init("GDSF", ccache_params, cache_specific_params); cache->eviction_params = reinterpret_cast(new eviction::GDSF); cache->cache_init = GDSF_init; @@ -116,8 +112,8 @@ static bool GDSF_get(cache_t *cache, const request_t *req) { } } - DEBUG_ASSERT((int64_t)gdsf->pq.size() == cache->n_obj); - DEBUG_ASSERT((int64_t)gdsf->pq_map.size() == cache->n_obj); + DEBUG_ASSERT((int64_t) gdsf->pq.size() == cache->n_obj); + DEBUG_ASSERT((int64_t) gdsf->pq_map.size() == cache->n_obj); return hit; } @@ -138,8 +134,7 @@ static bool GDSF_get(cache_t *cache, const request_t *req) { * and if the object is expired, it is removed from the cache * @return the object or NULL if not found */ -static cache_obj_t *GDSF_find(cache_t *cache, const request_t *req, - const bool update_cache) { +static cache_obj_t *GDSF_find(cache_t *cache, const request_t *req, const bool update_cache) { cache->n_req += 1; auto *gdsf = reinterpret_cast(cache->eviction_params); @@ -152,8 +147,7 @@ static cache_obj_t *GDSF_find(cache_t *cache, const request_t *req, auto node = gdsf->pq_map[obj]; gdsf->pq.erase(node); - double pri = - gdsf->pri_last_evict + (double)(obj->misc.freq) * 1.0e6 / obj->obj_size; + double pri = gdsf->pri_last_evict + (double)(obj->misc.freq) * 1.0e6 / obj->obj_size; eviction::pq_node_type new_node = {obj, pri, cache->n_req}; gdsf->pq.insert(new_node); gdsf->pq_map[obj] = new_node; @@ -172,8 +166,7 @@ static bool GDSF_can_insert(cache_t *cache, const request_t *req) { return false; } - int64_t to_evict_size = - req->obj_size - (cache->cache_size - cache->get_occupied_byte(cache)); + int64_t to_evict_size = req->obj_size - (cache->cache_size - cache->get_occupied_byte(cache)); double pri = gdsf->pri_last_evict + 1.0e6 / req->obj_size; bool can_insert = true; auto iter = gdsf->pq.begin(); @@ -201,8 +194,7 @@ static bool GDSF_can_insert(cache_t *cache, const request_t *req) { if ((n_insert + n_cannot_insert) % 100000 == 0) { if ((double)n_cannot_insert / (n_insert + n_cannot_insert) > 0.01) - DEBUG("size %" PRId64 " n_insert %" PRId64 ", n_cannot_insert %" PRId64 ", ratio %.2f\n", - cache->cache_size, n_insert, n_cannot_insert, + DEBUG("size %ld n_insert %ld, n_cannot_insert %ld, ratio %.2f\n", cache->cache_size, n_insert, n_cannot_insert, (double)n_cannot_insert / (n_insert + n_cannot_insert)); } @@ -223,12 +215,11 @@ static bool GDSF_can_insert(cache_t *cache, const request_t *req) { static cache_obj_t *GDSF_insert(cache_t *cache, const request_t *req) { auto *gdsf = reinterpret_cast(cache->eviction_params); - // this does not affect insertion for most workloads unless object size is too - // large however, when it have effect, it often increases miss ratio because a - // list of small objects (with relatively large priority) will stop the - // insertion of a large object, however, the newly requested large object is - // likely to be more useful than the small objects if (!GDSF_can_insert(cache, - // req)) return nullptr; + // this does not affect insertion for most workloads unless object size is too large + // however, when it have effect, it often increases miss ratio because a list of small objects (with relatively large + // priority) will stop the insertion of a large object, however, the newly requested large object is likely to be more + // useful than the small objects + // if (!GDSF_can_insert(cache, req)) return nullptr; cache_obj_t *obj = cache_insert_base(cache, req); DEBUG_ASSERT(obj != nullptr); diff --git a/libCacheSim/dataStructure/hashtable/chainedHashTableV2.c b/libCacheSim/dataStructure/hashtable/chainedHashTableV2.c index 6b755e45..23c2e070 100644 --- a/libCacheSim/dataStructure/hashtable/chainedHashTableV2.c +++ b/libCacheSim/dataStructure/hashtable/chainedHashTableV2.c @@ -40,8 +40,7 @@ extern "C" { #define OBJ_EMPTY(cache_obj) ((cache_obj)->obj_size == 0) #define NEXT_OBJ(cur_obj) (((cache_obj_t *)(cur_obj))->hash_next) -static void _copy_entries(hashtable_t *new_table, cache_obj_t **old_table, - uint64_t old_size); +static void _copy_entries(hashtable_t *new_table, cache_obj_t **old_table, uint64_t old_size); static void _chained_hashtable_shrink_v2(hashtable_t *hashtable); static void _chained_hashtable_expand_v2(hashtable_t *hashtable); static void print_hashbucket_item_distribution(const hashtable_t *hashtable); @@ -50,8 +49,7 @@ static void print_hashbucket_item_distribution(const hashtable_t *hashtable); /** * get the last object in the hash bucket */ -static inline cache_obj_t *_last_obj_in_bucket(const hashtable_t *hashtable, - const uint64_t hv) { +static inline cache_obj_t *_last_obj_in_bucket(const hashtable_t *hashtable, const uint64_t hv) { cache_obj_t *cur_obj_in_bucket = hashtable->ptr_table[hv]; while (cur_obj_in_bucket->hash_next) { cur_obj_in_bucket = cur_obj_in_bucket->hash_next; @@ -60,10 +58,8 @@ static inline cache_obj_t *_last_obj_in_bucket(const hashtable_t *hashtable, } /* add an object to the hashtable */ -static inline void add_to_table(hashtable_t *hashtable, - cache_obj_t *cache_obj) { - uint64_t hv = get_hash_value_int_64(&cache_obj->obj_id) & - hashmask(hashtable->hashpower); +static inline void add_to_table(hashtable_t *hashtable, cache_obj_t *cache_obj) { + uint64_t hv = get_hash_value_int_64(&cache_obj->obj_id) & hashmask(hashtable->hashpower); if (hashtable->ptr_table[hv] == NULL) { hashtable->ptr_table[hv] = cache_obj; return; @@ -96,9 +92,8 @@ hashtable_t *create_chained_hashtable_v2(const uint16_t hashpower) { size_t size = sizeof(cache_obj_t *) * hashsize(hashtable->hashpower); hashtable->ptr_table = my_malloc_n(cache_obj_t *, hashsize(hashpower)); if (hashtable->ptr_table == NULL) { - ERROR("allocate hash table %zu entry * %lu B = %ld MiB failed\n", - sizeof(cache_obj_t *), (unsigned long)(hashsize(hashpower)), - (long)(sizeof(cache_obj_t *) * hashsize(hashpower) / 1024 / 1024)); + ERROR("allocate hash table %zu entry * %lu B = %ld MiB failed\n", sizeof(cache_obj_t *), + (unsigned long)(hashsize(hashpower)), (long)(sizeof(cache_obj_t *) * hashsize(hashpower) / 1024 / 1024)); exit(1); } memset(hashtable->ptr_table, 0, size); @@ -112,8 +107,7 @@ hashtable_t *create_chained_hashtable_v2(const uint16_t hashpower) { return hashtable; } -cache_obj_t *chained_hashtable_find_obj_id_v2(const hashtable_t *hashtable, - const obj_id_t obj_id) { +cache_obj_t *chained_hashtable_find_obj_id_v2(const hashtable_t *hashtable, const obj_id_t obj_id) { cache_obj_t *cache_obj = NULL; uint64_t hv = get_hash_value_int_64(&obj_id); hv = hv & hashmask(hashtable->hashpower); @@ -128,21 +122,17 @@ cache_obj_t *chained_hashtable_find_obj_id_v2(const hashtable_t *hashtable, return cache_obj; } -cache_obj_t *chained_hashtable_find_v2(const hashtable_t *hashtable, - const request_t *req) { +cache_obj_t *chained_hashtable_find_v2(const hashtable_t *hashtable, const request_t *req) { return chained_hashtable_find_obj_id_v2(hashtable, req->obj_id); } -cache_obj_t *chained_hashtable_find_obj_v2(const hashtable_t *hashtable, - const cache_obj_t *obj_to_find) { +cache_obj_t *chained_hashtable_find_obj_v2(const hashtable_t *hashtable, const cache_obj_t *obj_to_find) { return chained_hashtable_find_obj_id_v2(hashtable, obj_to_find->obj_id); } /* the user needs to make sure the added object is not in the hash table */ -cache_obj_t *chained_hashtable_insert_v2(hashtable_t *hashtable, - const request_t *req) { - if (hashtable->n_obj > (uint64_t)(hashsize(hashtable->hashpower) * - CHAINED_HASHTABLE_EXPAND_THRESHOLD)) { +cache_obj_t *chained_hashtable_insert_v2(hashtable_t *hashtable, const request_t *req) { + if (hashtable->n_obj > (uint64_t)(hashsize(hashtable->hashpower) * CHAINED_HASHTABLE_EXPAND_THRESHOLD)) { _chained_hashtable_expand_v2(hashtable); } @@ -153,11 +143,9 @@ cache_obj_t *chained_hashtable_insert_v2(hashtable_t *hashtable, } /* the user needs to make sure the added object is not in the hash table */ -cache_obj_t *chained_hashtable_insert_obj_v2(hashtable_t *hashtable, - cache_obj_t *cache_obj) { +cache_obj_t *chained_hashtable_insert_obj_v2(hashtable_t *hashtable, cache_obj_t *cache_obj) { DEBUG_ASSERT(hashtable->external_obj); - if (hashtable->n_obj > (uint64_t)(hashsize(hashtable->hashpower) * - CHAINED_HASHTABLE_EXPAND_THRESHOLD)) + if (hashtable->n_obj > (uint64_t)(hashsize(hashtable->hashpower) * CHAINED_HASHTABLE_EXPAND_THRESHOLD)) _chained_hashtable_expand_v2(hashtable); add_to_table(hashtable, cache_obj); @@ -166,11 +154,9 @@ cache_obj_t *chained_hashtable_insert_obj_v2(hashtable_t *hashtable, } /* you need to free the extra_metadata before deleting from hash table */ -void chained_hashtable_delete_v2(hashtable_t *hashtable, - cache_obj_t *cache_obj) { +void chained_hashtable_delete_v2(hashtable_t *hashtable, cache_obj_t *cache_obj) { hashtable->n_obj -= 1; - uint64_t hv = get_hash_value_int_64(&cache_obj->obj_id) & - hashmask(hashtable->hashpower); + uint64_t hv = get_hash_value_int_64(&cache_obj->obj_id) & hashmask(hashtable->hashpower); if (hashtable->ptr_table[hv] == cache_obj) { hashtable->ptr_table[hv] = cache_obj->hash_next; if (!hashtable->external_obj) free_cache_obj(cache_obj); @@ -187,9 +173,8 @@ void chained_hashtable_delete_v2(hashtable_t *hashtable, if (chain_len > max_chain_len) { max_chain_len = chain_len; - WARN("hashtable remove %lu chain len %d, hashtable load %ld/%ld %lf\n", - (unsigned long)cache_obj->obj_id, max_chain_len, - (long)hashtable->n_obj, (long)hashsize(hashtable->hashpower), + WARN("hashtable remove %lu chain len %d, hashtable load %ld/%ld %lf\n", (unsigned long)cache_obj->obj_id, + max_chain_len, (long)hashtable->n_obj, (long)hashsize(hashtable->hashpower), (double)hashtable->n_obj / hashsize(hashtable->hashpower)); print_hashbucket_item_distribution(hashtable); @@ -203,12 +188,10 @@ void chained_hashtable_delete_v2(hashtable_t *hashtable, } } -bool chained_hashtable_try_delete_v2(hashtable_t *hashtable, - cache_obj_t *cache_obj) { +bool chained_hashtable_try_delete_v2(hashtable_t *hashtable, cache_obj_t *cache_obj) { static int max_chain_len = 1; - uint64_t hv = get_hash_value_int_64(&cache_obj->obj_id) & - hashmask(hashtable->hashpower); + uint64_t hv = get_hash_value_int_64(&cache_obj->obj_id) & hashmask(hashtable->hashpower); if (hashtable->ptr_table[hv] == cache_obj) { hashtable->ptr_table[hv] = cache_obj->hash_next; hashtable->n_obj -= 1; @@ -265,8 +248,7 @@ bool chained_hashtable_try_delete_v2(hashtable_t *hashtable, * @param obj_id [The object id to remove] * @return [true or false] */ -bool chained_hashtable_delete_obj_id_v2(hashtable_t *hashtable, - const obj_id_t obj_id) { +bool chained_hashtable_delete_obj_id_v2(hashtable_t *hashtable, const obj_id_t obj_id) { uint64_t hv = get_hash_value_int_64(&obj_id) & hashmask(hashtable->hashpower); cache_obj_t *cur_obj = hashtable->ptr_table[hv]; // the hash bucket is empty @@ -324,8 +306,7 @@ cache_obj_t *chained_hashtable_rand_obj_v2(hashtable_t *hashtable) { return cur_obj; } -void chained_hashtable_foreach_v2(hashtable_t *hashtable, - hashtable_iter iter_func, void *user_data) { +void chained_hashtable_foreach_v2(hashtable_t *hashtable, hashtable_iter iter_func, void *user_data) { cache_obj_t *cur_obj, *next_obj; for (uint64_t i = 0; i < hashsize(hashtable->hashpower); i++) { cur_obj = hashtable->ptr_table[i]; @@ -338,10 +319,8 @@ void chained_hashtable_foreach_v2(hashtable_t *hashtable, } void free_chained_hashtable_v2(hashtable_t *hashtable) { - if (!hashtable->external_obj) - chained_hashtable_foreach_v2(hashtable, foreach_free_obj, NULL); - my_free(sizeof(cache_obj_t *) * hashsize(hashtable->hashpower), - hashtable->ptr_table); + if (!hashtable->external_obj) chained_hashtable_foreach_v2(hashtable, foreach_free_obj, NULL); + my_free(sizeof(cache_obj_t *) * hashsize(hashtable->hashpower), hashtable->ptr_table); my_free(sizeof(hashtable_t), hashtable); } @@ -353,8 +332,7 @@ void free_chained_hashtable_v2(hashtable_t *hashtable) { * @param old_size * @return * void */ -static void _copy_entries(hashtable_t *new_table, cache_obj_t **old_table, - uint64_t old_size) { +static void _copy_entries(hashtable_t *new_table, cache_obj_t **old_table, uint64_t old_size) { cache_obj_t *cur_obj, *next_obj; for (uint64_t i = 0; i < old_size; i++) { cur_obj = old_table[i]; @@ -369,24 +347,16 @@ static void _copy_entries(hashtable_t *new_table, cache_obj_t **old_table, static void _chained_hashtable_shrink_v2(hashtable_t *hashtable) { cache_obj_t **old_table = hashtable->ptr_table; - hashtable->ptr_table = - my_malloc_n(cache_obj_t *, hashsize(--hashtable->hashpower)); + hashtable->ptr_table = my_malloc_n(cache_obj_t *, hashsize(--hashtable->hashpower)); #ifdef USE_HUGEPAGE - madvise(hashtable->table, - sizeof(cache_obj_t *) * hashsize(hashtable->hashpower), - MADV_HUGEPAGE); + madvise(hashtable->table, sizeof(cache_obj_t *) * hashsize(hashtable->hashpower), MADV_HUGEPAGE); #endif - memset(hashtable->ptr_table, 0, - hashsize(hashtable->hashpower) * sizeof(cache_obj_t *)); - ASSERT_NOT_NULL(hashtable->ptr_table, - "unable to shrink hashtable to size %llu\n", - hashsizeULL(hashtable->hashpower)); - - DEBUG( - "shrink hash table size from %llu to %llu, new hashtable load %llu/%llu\n", - hashsizeULL((uint16_t)(hashtable->hashpower + 1)), - hashsizeULL(hashtable->hashpower), hashtable->n_obj, - hashsize(hashtable->hashpower)); + memset(hashtable->ptr_table, 0, hashsize(hashtable->hashpower) * sizeof(cache_obj_t *)); + ASSERT_NOT_NULL(hashtable->ptr_table, "unable to shrink hashtable to size %llu\n", hashsizeULL(hashtable->hashpower)); + + DEBUG("shrink hash table size from %llu to %llu, new hashtable load %lu/%lu\n", + hashsizeULL((uint16_t)(hashtable->hashpower + 1)), hashsizeULL(hashtable->hashpower), hashtable->n_obj, + hashsize(hashtable->hashpower)); _copy_entries(hashtable, old_table, hashsize(hashtable->hashpower + 1)); my_free(sizeof(cache_obj_t) * hashsize(hashtable->hashpower + 1), old_table); @@ -395,25 +365,16 @@ static void _chained_hashtable_shrink_v2(hashtable_t *hashtable) { /* grows the hashtable to the next power of 2. */ static void _chained_hashtable_expand_v2(hashtable_t *hashtable) { cache_obj_t **old_table = hashtable->ptr_table; - hashtable->ptr_table = - my_malloc_n(cache_obj_t *, hashsize(++hashtable->hashpower)); + hashtable->ptr_table = my_malloc_n(cache_obj_t *, hashsize(++hashtable->hashpower)); #ifdef USE_HUGEPAGE - madvise(hashtable->table, - sizeof(cache_obj_t *) * hashsize(hashtable->hashpower), - MADV_HUGEPAGE); + madvise(hashtable->table, sizeof(cache_obj_t *) * hashsize(hashtable->hashpower), MADV_HUGEPAGE); #endif - memset(hashtable->ptr_table, 0, - hashsize(hashtable->hashpower) * sizeof(cache_obj_t *)); - ASSERT_NOT_NULL(hashtable->ptr_table, - "unable to grow hashtable to size %llu\n", - hashsizeULL(hashtable->hashpower)); - - DEBUG( - "expand hashtable from %llu to %llu entries, new hashtable load " - "%llu/%llu\n", - hashsizeULL((uint16_t)(hashtable->hashpower - 1)), - hashsizeULL(hashtable->hashpower), hashtable->n_obj, - hashsize(hashtable->hashpower)); + memset(hashtable->ptr_table, 0, hashsize(hashtable->hashpower) * sizeof(cache_obj_t *)); + ASSERT_NOT_NULL(hashtable->ptr_table, "unable to grow hashtable to size %llu\n", hashsizeULL(hashtable->hashpower)); + + DEBUG("expand hashtable from %llu to %llu entries, new hashtable load %lu/%lu\n", + hashsizeULL((uint16_t)(hashtable->hashpower - 1)), hashsizeULL(hashtable->hashpower), hashtable->n_obj, + hashsize(hashtable->hashpower)); _copy_entries(hashtable, old_table, hashsize(hashtable->hashpower - 1)); my_free(sizeof(cache_obj_t) * hashsize(hashtable->hashpower), old_table); @@ -425,8 +386,7 @@ void check_hashtable_integrity_v2(const hashtable_t *hashtable) { cur_obj = hashtable->ptr_table[i]; while (cur_obj != NULL) { next_obj = cur_obj->hash_next; - assert(i == (get_hash_value_int_64(&cur_obj->obj_id) & - hashmask(hashtable->hashpower))); + assert(i == (get_hash_value_int_64(&cur_obj->obj_id) & hashmask(hashtable->hashpower))); cur_obj = next_obj; } } @@ -439,8 +399,7 @@ static int count_n_obj_in_bucket(cache_obj_t *curr_obj) { obj_id_arr[chain_len] = curr_obj->obj_id; for (int i = 0; i < chain_len; i++) { if (obj_id_arr[i] == curr_obj->obj_id) { - ERROR("obj_id %lu is duplicated in hashtable\n", - (unsigned long)curr_obj->obj_id); + ERROR("obj_id %lu is duplicated in hashtable\n", (unsigned long)curr_obj->obj_id); abort(); } } @@ -476,7 +435,7 @@ void print_chained_hashtable_v2(const hashtable_t *hashtable) { if (cur_obj == NULL) { continue; } - printf("hash bucket %lu: ", (unsigned long)i); + printf("hash bucket %lu: ", (unsigned long) i); while (cur_obj != NULL) { printf("%lu, ", (unsigned long)cur_obj->obj_id); cur_obj = cur_obj->hash_next; diff --git a/libCacheSim/dataStructure/histogram.c b/libCacheSim/dataStructure/histogram.c index 06667359..94823577 100644 --- a/libCacheSim/dataStructure/histogram.c +++ b/libCacheSim/dataStructure/histogram.c @@ -5,7 +5,6 @@ #include #include #include -#include ReuseHistogram* init_histogram(void) { ReuseHistogram* hist = (ReuseHistogram*)malloc(sizeof(ReuseHistogram)); @@ -64,7 +63,7 @@ void export_histogram_to_csv(ReuseHistogram* hist, float rate, char* path) { fprintf(file, "Distance,Frequency\n"); if (hist->cold_miss_bin > 0) { - fprintf(file, "ColdMiss,%" PRIu64 "\n", hist->cold_miss_bin); + fprintf(file, "ColdMiss,%lu\n", hist->cold_miss_bin); } GHashTableIter iter; @@ -76,9 +75,9 @@ void export_histogram_to_csv(ReuseHistogram* hist, float rate, char* path) { double scaled_distance = (double)(distance) / (double)rate; if (scaled_distance > (double)UINT64_MAX) { - fprintf(file, "Overflow,%" PRIu64 "\n", bin->frequency); + fprintf(file, "Overflow,%lu\n", bin->frequency); } else { - fprintf(file, "%" PRIu64 ",%" PRIu64 "\n", (uint64_t)scaled_distance, bin->frequency); + fprintf(file, "%lu,%lu\n", (uint64_t)scaled_distance, bin->frequency); } } diff --git a/libCacheSim/dataStructure/splay_tuple.c b/libCacheSim/dataStructure/splay_tuple.c index 840ad63b..66c13fba 100644 --- a/libCacheSim/dataStructure/splay_tuple.c +++ b/libCacheSim/dataStructure/splay_tuple.c @@ -51,7 +51,6 @@ extern "C" { #endif #include "splay_tuple.h" -#include // static sTree_tuple * sedgewickized_splay (int i, sTree_tuple * t); @@ -275,7 +274,7 @@ void print_sTree_t(sTree_tuple *t, int d) { if (t == NULL) return; print_sTree_t(t->right, d + 1); for (i = 0; i < d; i++) printf(" "); - printf("%" PRIu64 "(%" PRId64 ")\n", t->key->Tmax, t->value); + printf("%lu(%ld)\n", t->key->Tmax, t->value); print_sTree_t(t->left, d + 1); } diff --git a/libCacheSim/include/libCacheSim/reader.h b/libCacheSim/include/libCacheSim/reader.h index 49a6a3b6..cbfea0c3 100644 --- a/libCacheSim/include/libCacheSim/reader.h +++ b/libCacheSim/include/libCacheSim/reader.h @@ -55,8 +55,7 @@ typedef struct { int32_t feature_fields[N_MAX_FEATURES]; // block cache, 0 and -1 means ignore this field, 1 is also invalid - // block_size breaks a large request for multiple blocks into multiple - // requests + // block_size breaks a large request for multiple blocks into multiple requests int32_t block_size; // csv reader @@ -131,8 +130,7 @@ typedef struct reader { /* if true, ignore the obj_size in the trace, and use size one */ bool ignore_obj_size; - // used by block cache trace to split a large request into multiple requests - // to multiple blocks + // used by block cache trace to split a large request into multiple requests to multiple blocks int32_t block_size; /* this is used when @@ -192,13 +190,11 @@ static inline reader_init_param_t default_reader_init_params(void) { * @return a pointer to reader_t struct, the returned reader needs to be * explicitly closed by calling close_reader or close_trace */ -reader_t *setup_reader(const char *trace_path, trace_type_e trace_type, - const reader_init_param_t *reader_init_param); +reader_t *setup_reader(const char *trace_path, trace_type_e trace_type, const reader_init_param_t *reader_init_param); /* this is the same function as setup_reader */ -static inline reader_t *open_trace( - const char *path, const trace_type_e type, - const reader_init_param_t *reader_init_param) { +static inline reader_t *open_trace(const char *path, const trace_type_e type, + const reader_init_param_t *reader_init_param) { return setup_reader(path, type, reader_init_param); } @@ -214,18 +210,14 @@ int64_t get_num_of_req(reader_t *reader); * @param reader * @return */ -static inline trace_type_e get_trace_type(const reader_t *const reader) { - return reader->trace_type; -} +static inline trace_type_e get_trace_type(const reader_t *const reader) { return reader->trace_type; } /** * whether the object id is numeric (only applies to txt and csv traces) * @param reader * @return */ -static inline bool obj_id_is_num(const reader_t *const reader) { - return reader->obj_id_is_num; -} +static inline bool obj_id_is_num(const reader_t *const reader) { return reader->obj_id_is_num; } /** * read one request from reader/trace, stored the info in pre-allocated req @@ -241,9 +233,7 @@ int read_one_req(reader_t *reader, request_t *req); * @param req * return 0 on success and 1 if reach end of trace */ -static inline int read_trace(reader_t *const reader, request_t *const req) { - return read_one_req(reader, req); -} +static inline int read_trace(reader_t *const reader, request_t *const req) { return read_one_req(reader, req); } /** * reset reader, so we can read from the beginning @@ -258,9 +248,7 @@ void reset_reader(reader_t *reader); */ int close_reader(reader_t *reader); -static inline int close_trace(reader_t *const reader) { - return close_reader(reader); -} +static inline int close_trace(reader_t *const reader) { return close_reader(reader); } /** * clone a reader, mostly used in multithreading @@ -288,13 +276,10 @@ static inline void print_reader(reader_t *reader) { "%p, line_buf_size: %zu, csv_delimiter: %c, csv_has_header: %d, " "obj_id_is_num: %d, ignore_size_zero_req: %d, ignore_obj_size: %d, " "n_req_left: %d, last_req_clock_time: %ld\n", - g_trace_type_name[reader->trace_type], reader->trace_path, - reader->trace_start_offset, (long)reader->mmap_offset, - reader->is_zstd_file, reader->item_size, (void *)reader->file, - (void*) reader->line_buf, reader->line_buf_size, reader->csv_delimiter, - reader->csv_has_header, reader->obj_id_is_num, - reader->ignore_size_zero_req, reader->ignore_obj_size, reader->n_req_left, - (long)reader->last_req_clock_time); + g_trace_type_name[reader->trace_type], reader->trace_path, reader->trace_start_offset, (long)reader->mmap_offset, + reader->is_zstd_file, reader->item_size, (void *)reader->file, reader->line_buf, reader->line_buf_size, + reader->csv_delimiter, reader->csv_has_header, reader->obj_id_is_num, reader->ignore_size_zero_req, + reader->ignore_obj_size, reader->n_req_left, (long)reader->last_req_clock_time); } #ifdef __cplusplus diff --git a/libCacheSim/mrcProfiler/mrcProfiler.h b/libCacheSim/mrcProfiler/mrcProfiler.h index 8890c08f..ef3f1dd3 100644 --- a/libCacheSim/mrcProfiler/mrcProfiler.h +++ b/libCacheSim/mrcProfiler/mrcProfiler.h @@ -41,9 +41,9 @@ typedef struct profiler_params { void print() { printf("shards params:\n"); printf(" enable_fix_size: %d\n", enable_fix_size); - printf(" sample_size: %" PRId64 "\n", sample_size); + printf(" sample_size: %ld\n", sample_size); printf(" sample_rate: %f\n", sample_rate); - printf(" salt: %" PRId64 "\n", salt); + printf(" salt: %ld\n", salt); } void parse_params(const char *str) { @@ -117,7 +117,7 @@ typedef struct profiler_params { void print() { printf("minisim params:\n"); printf(" sample_rate: %f\n", sample_rate); - printf(" thread_num: %" PRId64 "\n", thread_num); + printf(" thread_num: %ld\n", thread_num); } void parse_params(const char *str) { diff --git a/libCacheSim/traceReader/customizedReader/lcs.c b/libCacheSim/traceReader/customizedReader/lcs.c index a8fc4c15..36fcfe02 100644 --- a/libCacheSim/traceReader/customizedReader/lcs.c +++ b/libCacheSim/traceReader/customizedReader/lcs.c @@ -14,21 +14,18 @@ extern "C" { static bool _verify_lcs_header(lcs_trace_header_t *header) { /* check whether the trace is valid */ if (header->start_magic != LCS_TRACE_START_MAGIC) { - ERROR("invalid trace file, start magic is wrong 0x%lx\n", - (unsigned long)header->start_magic); + ERROR("invalid trace file, start magic is wrong 0x%lx\n", (unsigned long)header->start_magic); return false; } if (header->end_magic != LCS_TRACE_END_MAGIC) { - ERROR("invalid trace file, end magic is wrong 0x%lx\n", - (unsigned long)header->end_magic); + ERROR("invalid trace file, end magic is wrong 0x%lx\n", (unsigned long)header->end_magic); return false; } lcs_trace_stat_t *stat = &(header->stat); if (stat->n_req < 0 || stat->n_obj < 0) { - ERROR("invalid trace file, n_req %ld, n_obj %ld\n", - (unsigned long)stat->n_req, (unsigned long)stat->n_obj); + ERROR("invalid trace file, n_req %ld, n_obj %ld\n", (unsigned long)stat->n_req, (unsigned long)stat->n_obj); return false; } @@ -36,66 +33,47 @@ static bool _verify_lcs_header(lcs_trace_header_t *header) { } static void _lcs_print_trace_stat(lcs_trace_stat_t *stat) { - printf( - "trace stat: n_req %" PRId64 ", n_obj %" PRId64 ", n_byte %" PRId64 " (%.2lf GiB), " - "n_uniq_byte %" PRId64 " (%.2lf GiB)\n", - stat->n_req, stat->n_obj, - stat->n_req_byte, (double)stat->n_req_byte / GiB, - stat->n_obj_byte, (double)stat->n_obj_byte / GiB); + printf("trace stat: n_req %lld, n_obj %lld, n_byte %lld (%.2lf GiB), n_uniq_byte %lld (%.2lf GiB)\n", + (long long)stat->n_req, (long long)stat->n_obj, (long long)stat->n_req_byte, (double)stat->n_req_byte / GiB, + (long long)stat->n_obj_byte, (double)stat->n_obj_byte / GiB); if (stat->n_read > 0) { - printf("n_read %" PRId64 ", n_write %" PRId64 ", n_delete %" PRId64 "\n", - stat->n_read, stat->n_write, - stat->n_delete); + printf("n_read %lld, n_write %lld, n_delete %lld\n", (long long)stat->n_read, (long long)stat->n_write, + (long long)stat->n_delete); } - printf("start time %" PRId64 ", end time %" PRId64 ", duration %" PRId64 " seconds %.2lf days\n", - stat->start_timestamp, stat->end_timestamp, - (stat->end_timestamp - stat->start_timestamp), + printf("start time %lld, end time %lld, duration %lld seconds %.2lf days\n", (long long)stat->start_timestamp, + (long long)stat->end_timestamp, (long long)(stat->end_timestamp - stat->start_timestamp), (double)(stat->end_timestamp - stat->start_timestamp) / (24 * 3600.0)); - printf("object size: smallest %" PRId64 ", largest %" PRId64 "\n", - stat->smallest_obj_size, stat->largest_obj_size); - printf( - "most common object sizes (req fraction): %" PRId64 "(%.4lf) %" PRId64 "(%.4lf) " - "%" PRId64 "(%.4lf) %" PRId64 "(%.4lf)...\n", - stat->most_common_obj_sizes[0], stat->most_common_obj_size_ratio[0], - stat->most_common_obj_sizes[1], stat->most_common_obj_size_ratio[1], - stat->most_common_obj_sizes[2], stat->most_common_obj_size_ratio[2], - stat->most_common_obj_sizes[3], stat->most_common_obj_size_ratio[3]); - - printf("highest freq: %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " skewness %.4lf\n", - stat->highest_freq[0], stat->highest_freq[1], stat->highest_freq[2], - stat->highest_freq[3], stat->skewness); - printf( - "most common freq (req fraction): %d(%.4lf) %d(%.4lf) %d(%.4lf) " - "%d(%.4lf)...\n", - stat->most_common_freq[0], stat->most_common_freq_ratio[0], - stat->most_common_freq[1], stat->most_common_freq_ratio[1], - stat->most_common_freq[2], stat->most_common_freq_ratio[2], - stat->most_common_freq[3], stat->most_common_freq_ratio[3]); + printf("object size: smallest %lld, largest %lld\n", (long long)stat->smallest_obj_size, + (long long)stat->largest_obj_size); + printf("most common object sizes (req fraction): %ld(%.4lf) %ld(%.4lf) %ld(%.4lf) %ld(%.4lf)...\n", + stat->most_common_obj_sizes[0], stat->most_common_obj_size_ratio[0], stat->most_common_obj_sizes[1], + stat->most_common_obj_size_ratio[1], stat->most_common_obj_sizes[2], stat->most_common_obj_size_ratio[2], + stat->most_common_obj_sizes[3], stat->most_common_obj_size_ratio[3]); + + printf("highest freq: %ld %ld %ld %ld skewness %.4lf\n", stat->highest_freq[0], stat->highest_freq[1], + stat->highest_freq[2], stat->highest_freq[3], stat->skewness); + printf("most common freq (req fraction): %d(%.4lf) %d(%.4lf) %d(%.4lf) %d(%.4lf)...\n", stat->most_common_freq[0], + stat->most_common_freq_ratio[0], stat->most_common_freq[1], stat->most_common_freq_ratio[1], + stat->most_common_freq[2], stat->most_common_freq_ratio[2], stat->most_common_freq[3], + stat->most_common_freq_ratio[3]); if (stat->n_tenant > 1) { printf("#tenant: %ld\n", (long)stat->n_tenant); - printf( - "most common tenants (req fraction): %d(%.4lf) %d(%.4lf) %d(%.4lf) " - "%d(%.4lf)...\n", - stat->most_common_tenants[0], stat->most_common_tenant_ratio[0], - stat->most_common_tenants[1], stat->most_common_tenant_ratio[1], - stat->most_common_tenants[2], stat->most_common_tenant_ratio[2], - stat->most_common_tenants[3], stat->most_common_tenant_ratio[3]); + printf("most common tenants (req fraction): %d(%.4lf) %d(%.4lf) %d(%.4lf) %d(%.4lf)...\n", + stat->most_common_tenants[0], stat->most_common_tenant_ratio[0], stat->most_common_tenants[1], + stat->most_common_tenant_ratio[1], stat->most_common_tenants[2], stat->most_common_tenant_ratio[2], + stat->most_common_tenants[3], stat->most_common_tenant_ratio[3]); } if (stat->n_ttl > 1) { printf("#ttl: %ld\n", (long)stat->n_ttl); - printf("smallest ttl: %ld, largest ttl: %ld\n", (long)stat->smallest_ttl, - (long)stat->largest_ttl); - printf( - "most common ttls (req fraction): %d(%.4lf) %d(%.4lf) %d(%.4lf) " - "%d(%.4lf)...\n", - stat->most_common_ttls[0], stat->most_common_ttl_ratio[0], - stat->most_common_ttls[1], stat->most_common_ttl_ratio[1], - stat->most_common_ttls[2], stat->most_common_ttl_ratio[2], - stat->most_common_ttls[3], stat->most_common_ttl_ratio[3]); + printf("smallest ttl: %ld, largest ttl: %ld\n", (long)stat->smallest_ttl, (long)stat->largest_ttl); + printf("most common ttls (req fraction): %d(%.4lf) %d(%.4lf) %d(%.4lf) %d(%.4lf)...\n", stat->most_common_ttls[0], + stat->most_common_ttl_ratio[0], stat->most_common_ttls[1], stat->most_common_ttl_ratio[1], + stat->most_common_ttls[2], stat->most_common_ttl_ratio[2], stat->most_common_ttls[3], + stat->most_common_ttl_ratio[3]); } } @@ -140,8 +118,8 @@ int lcsReader_setup(reader_t *reader) { exit(1); } - DEBUG("setup lcs reader %s, version %ld, item size %ld\n", reader->trace_path, - (unsigned long)reader->lcs_ver, (unsigned long)reader->item_size); + DEBUG("setup lcs reader %s, version %ld, item size %ld\n", reader->trace_path, (unsigned long)reader->lcs_ver, + (unsigned long)reader->item_size); return 0; } @@ -203,8 +181,7 @@ int lcs_read_one_req(reader_t *reader, request_t *req) { req->next_access_vtime = MAX_REUSE_DISTANCE; } - if (req->obj_size == 0 && reader->ignore_size_zero_req && - reader->read_direction == READ_FORWARD) { + if (req->obj_size == 0 && reader->ignore_size_zero_req && reader->read_direction == READ_FORWARD) { return lcs_read_one_req(reader, req); } return 0; diff --git a/test/test_dataStructure.c b/test/test_dataStructure.c index 5daae002..4b4cfc42 100644 --- a/test/test_dataStructure.c +++ b/test/test_dataStructure.c @@ -19,7 +19,7 @@ void test_chained_hashtable_v2(gconstpointer user_data) { for (int i = 0; i < 1280; i++) { cache_obj_t *obj = chained_hashtable_rand_obj_v2(hashtable); if (!seen_bit[obj->obj_id]) { - printf("object %" PRIu64 " at %d\n", obj->obj_id, i); + printf("object %lu at %d\n", obj->obj_id, i); } seen_bit[obj->obj_id] = true; }