@@ -25,6 +25,7 @@ void simulate(reader_t *reader, cache_t *cache, int report_interval,
2525 uint64_t req_cnt = 0 , miss_cnt = 0 ;
2626 uint64_t last_req_cnt = 0 , last_miss_cnt = 0 ;
2727 uint64_t req_byte = 0 , miss_byte = 0 ;
28+ double req_cost = 0 , miss_cost = 0 ;
2829
2930 read_one_req (reader , req );
3031 uint64_t start_ts = (uint64_t )req -> clock_time ;
@@ -52,9 +53,11 @@ void simulate(reader_t *reader, cache_t *cache, int report_interval,
5253
5354 req_cnt ++ ;
5455 req_byte += req -> obj_size ;
56+ req_cost += req -> obj_cost ;
5557 if (cache -> get (cache , req ) == false) {
5658 miss_cnt ++ ;
5759 miss_byte += req -> obj_size ;
60+ miss_cost += req -> obj_cost ;
5861 }
5962 if (req -> clock_time - last_report_ts >= (uint64_t )report_interval &&
6063 req -> clock_time != 0 ) {
@@ -78,28 +81,30 @@ void simulate(reader_t *reader, cache_t *cache, int report_interval,
7881
7982 char output_str [1024 ];
8083 char size_str [64 ];
81-
82- if (!ignore_obj_size ) convert_size_to_str (cache -> cache_size , size_str , 64 );
83- #pragma GCC diagnostic push
84- // Removed unknown pragma warning
85- if (!ignore_obj_size ) {
86- snprintf (output_str , 1024 ,
87- "%s %s cache size %8s, %16lu req, miss ratio %.4lf, throughput "
88- "%.2lf MQPS\n" ,
89- reader -> trace_path , detailed_cache_name , size_str ,
90- (unsigned long )req_cnt , (double )miss_cnt / (double )req_cnt ,
91- (double )req_cnt / 1000000.0 / runtime );
92- } else {
93- snprintf (output_str , 1024 ,
94- "%s %s cache size %8lld, %16lu req, miss ratio %.4lf, throughput "
95- "%.2lf MQPS\n" ,
96- reader -> trace_path , detailed_cache_name ,
97- (long long )cache -> cache_size , (unsigned long )req_cnt ,
98- (double )miss_cnt / (double )req_cnt ,
99- (double )req_cnt / 1000000.0 / runtime );
100- }
101-
102- #pragma GCC diagnostic pop
84+ double miss_ratio = req_cnt > 0 ? (double )miss_cnt / (double )req_cnt : 0.0 ;
85+ double byte_miss_ratio =
86+ req_byte > 0 ? (double )miss_byte / (double )req_byte : 0.0 ;
87+ double cost_saving_ratio = 1.0 - (req_cost > 0 ? miss_cost / req_cost : 0.0 );
88+
89+ if (!ignore_obj_size )
90+ convert_size_to_str (cache -> cache_size , size_str , 64 );
91+ else
92+ snprintf (size_str , sizeof (size_str ), "%lld" , (long long )cache -> cache_size );
93+
94+ bool show_cost = fabs (1 - cost_saving_ratio - miss_ratio ) > 1e-9 ;
95+
96+ int n = snprintf (output_str , sizeof (output_str ),
97+ "%s %s cache size %8s, %16lu req, miss ratio %.4lf" ,
98+ reader -> trace_path , detailed_cache_name , size_str ,
99+ (unsigned long )req_cnt , miss_ratio );
100+ if (!ignore_obj_size )
101+ n += snprintf (output_str + n , sizeof (output_str ) - n ,
102+ ", byte miss ratio %.4lf" , byte_miss_ratio );
103+ if (show_cost )
104+ n += snprintf (output_str + n , sizeof (output_str ) - n ,
105+ ", cost saving ratio %.4lf" , cost_saving_ratio );
106+ snprintf (output_str + n , sizeof (output_str ) - n , ", throughput %.2lf MQPS\n" ,
107+ (double )req_cnt / 1000000.0 / runtime );
103108 printf ("%s" , output_str );
104109 char * output_dir = rindex (ofilepath , '/' );
105110 if (output_dir != NULL ) {
0 commit comments