4444#include < assert.h>
4545#endif
4646
47+ #include < math.h>
4748#include < algorithm>
4849
4950#include " client.h"
5051#include " obj_gen.h"
5152#include " memtier_benchmark.h"
5253
54+ float get_2_meaningful_digits (float val)
55+ {
56+ float log = floor (log10 (val));
57+ float factor = pow (10 , log-1 ); // to save 2 digits
58+ float new_val = round ( val / factor);
59+ new_val *= factor;
60+ return new_val;
61+ }
62+
5363void client_event_handler (evutil_socket_t sfd, short evtype, void *opaque)
5464{
5565 client *c = (client *) opaque;
@@ -1067,8 +1077,6 @@ run_stats::run_stats() :
10671077{
10681078 memset (&m_start_time, 0 , sizeof (m_start_time));
10691079 memset (&m_end_time, 0 , sizeof (m_end_time));
1070- memset (m_get_latency, 0 , sizeof (m_get_latency));
1071- memset (m_set_latency, 0 , sizeof (m_set_latency));
10721080}
10731081
10741082void run_stats::set_start_time (struct timeval * start_time)
@@ -1122,10 +1130,7 @@ void run_stats::update_get_op(struct timeval* ts, unsigned int bytes, unsigned i
11221130 m_totals.m_ops ++;
11231131 m_totals.m_latency += latency;
11241132
1125- unsigned int msec_latency = latency / 1000 ;
1126- if (msec_latency > MAX_LATENCY_HISTOGRAM)
1127- msec_latency = MAX_LATENCY_HISTOGRAM;
1128- m_get_latency[msec_latency]++;
1133+ m_get_latency_map[get_2_meaningful_digits ((float )latency/1000 )]++;
11291134}
11301135
11311136void run_stats::update_set_op (struct timeval * ts, unsigned int bytes, unsigned int latency)
@@ -1140,10 +1145,7 @@ void run_stats::update_set_op(struct timeval* ts, unsigned int bytes, unsigned i
11401145 m_totals.m_ops ++;
11411146 m_totals.m_latency += latency;
11421147
1143- unsigned int msec_latency = latency / 1000 ;
1144- if (msec_latency > MAX_LATENCY_HISTOGRAM)
1145- msec_latency = MAX_LATENCY_HISTOGRAM;
1146- m_set_latency[msec_latency]++;
1148+ m_set_latency_map[get_2_meaningful_digits (latency/1000 )]++;
11471149}
11481150
11491151unsigned int run_stats::get_duration (void )
@@ -1214,24 +1216,24 @@ bool run_stats::save_csv(const char *filename)
12141216 total_set_ops += i->m_ops_set ;
12151217 }
12161218
1217- unsigned long int total_count = 0 ;
1219+
1220+ double total_count_float = 0 ;
1221+ int i=0 ;
12181222 fprintf (f, " \n " " Full-Test GET Latency\n " );
12191223 fprintf (f, " Latency (<= msec),Percent\n " );
1220- for (int i = 0 ; i <= MAX_LATENCY_HISTOGRAM; i++) {
1221- if (m_get_latency[i] > 0 ) {
1222- total_count += m_get_latency[i];
1223- fprintf (f, " %u,%.2f\n " , i, (double ) total_count / total_get_ops * 100 );
1224- }
1224+ for ( latency_map_itr it = m_get_latency_map.begin () ; it != m_get_latency_map.end () ; it++ ) {
1225+ total_count_float += it->second ;
1226+ fprintf (f, " %u,%.2f\n " , i, total_count_float / total_get_ops * 100 );
1227+ i++;
12251228 }
1226-
1229+ i= 0 ;
12271230 fprintf (f, " \n " " Full-Test SET Latency\n " );
12281231 fprintf (f, " Latency (<= msec),Percent\n " );
1229- total_count = 0 ;
1230- for (int i = 0 ; i <= MAX_LATENCY_HISTOGRAM; i++) {
1231- if (m_set_latency[i] > 0 ) {
1232- total_count += m_set_latency[i];
1233- fprintf (f, " %u,%.2f\n " , i, (double ) total_count / total_set_ops * 100 );
1234- }
1232+
1233+ for ( latency_map_itr it = m_set_latency_map.begin (); it != m_set_latency_map.end () ; it++ ) {
1234+ total_count_float += it->second ;
1235+ fprintf (f, " %u,%.2f\n " , i, total_count_float / total_get_ops * 100 );
1236+ i++;
12351237 }
12361238
12371239 fclose (f);
@@ -1259,14 +1261,14 @@ void run_stats::debug_dump(void)
12591261 i->m_get_misses );
12601262 }
12611263
1262- for (int i = 0 ; i <= MAX_LATENCY_HISTOGRAM; i++) {
1263- if (m_get_latency[i] > 0 )
1264- benchmark_debug_log (" GET <= %u msec: %u\n " , i, m_get_latency[i]);
1265- }
12661264
1267- for (int i = 0 ; i <= MAX_LATENCY_HISTOGRAM; i++) {
1268- if (m_set_latency[i] > 0 )
1269- benchmark_debug_log (" SET <= %u msec: %u\n " , i, m_set_latency[i]);
1265+ for ( latency_map_itr it = m_get_latency_map.begin () ; it != m_get_latency_map.end () ; it++) {
1266+ if (it->second )
1267+ benchmark_debug_log (" GET <= %u msec: %u\n " , it->first , it->second );
1268+ }
1269+ for ( latency_map_itr it = m_set_latency_map.begin () ; it != m_set_latency_map.end () ; it++) {
1270+ if (it->second )
1271+ benchmark_debug_log (" SET <= %u msec: %u\n " , it->first , it->second );
12701272 }
12711273}
12721274
@@ -1284,12 +1286,14 @@ void run_stats::aggregate_average(const std::vector<run_stats>& all_stats)
12841286 m_totals.add (i_totals);
12851287
12861288 // aggregate latency data
1287- for (int j = 0 ; j < MAX_LATENCY_HISTOGRAM + 1 ; j++) {
1288- m_get_latency[j] += i->m_get_latency [j];
1289- m_set_latency[j] += i->m_set_latency [j];
1290- }
1291- }
12921289
1290+ for ( latency_map_itr_const it = i->m_get_latency_map .begin () ; it != i->m_get_latency_map .end () ; it++) {
1291+ m_get_latency_map[it->first ] += it->second ;
1292+ }
1293+ for ( latency_map_itr_const it = i->m_set_latency_map .begin () ; it != i->m_set_latency_map .end () ; it++) {
1294+ m_set_latency_map[it->first ] += it->second ;
1295+ }
1296+ }
12931297 m_totals.m_ops_sec_set /= all_stats.size ();
12941298 m_totals.m_ops_sec_get /= all_stats.size ();
12951299 m_totals.m_ops_sec /= all_stats.size ();
@@ -1342,11 +1346,13 @@ void run_stats::merge(const run_stats& other, int iteration)
13421346 m_totals.m_ops += other.m_totals .m_ops ;
13431347
13441348 // aggregate latency data
1345- for (int i = 0 ; i < MAX_LATENCY_HISTOGRAM + 1 ; i++) {
1346- m_get_latency[i] += other.m_get_latency [i];
1347- m_set_latency[i] += other.m_set_latency [i];
1349+ for ( latency_map_itr_const it = other.m_get_latency_map .begin () ; it != other.m_get_latency_map .end () ; it++) {
1350+ m_get_latency_map[it->first ] += it->second ;
1351+ }
1352+ for ( latency_map_itr_const it = other.m_set_latency_map .begin () ; it != other.m_set_latency_map .end () ; it++) {
1353+ m_set_latency_map[it->first ] += it->second ;
13481354 }
1349-
1355+
13501356}
13511357
13521358void run_stats::summarize (totals& result) const
@@ -1440,25 +1446,19 @@ void run_stats::print(FILE *out, bool histogram)
14401446 " Request Latency Distribution\n "
14411447 " %-6s %12s %12s\n "
14421448 " ------------------------------------------------------------------------\n " ,
1443- " Type" , " <= msec" , " Percent" );
1449+ " Type" , " <= msec " , " Percent" );
14441450
14451451 unsigned long int total_count = 0 ;
1446- for (int i = 0 ; i <= MAX_LATENCY_HISTOGRAM; i++) {
1447- if (m_set_latency[i] > 0 ) {
1448- total_count += m_set_latency[i];
1449- fprintf (out, " %-6s %12u %12.2f\n " ,
1450- " SET" , i, (double ) total_count / m_totals.m_ops_set * 100 );
1451- }
1452+ for ( latency_map_itr_const it = m_set_latency_map.begin () ; it != m_set_latency_map.end () ; it++) {
1453+ total_count += it->second ;
1454+ fprintf (out, " %-6s %8.3f %12.2f\n " , " SET" , it->first , (double ) total_count / m_totals.m_ops_set * 100 );
14521455 }
1456+ total_count = 0 ;
14531457
14541458 fprintf (out, " ---\n " );
1455- total_count = 0 ;
1456- for (int i = 0 ; i <= MAX_LATENCY_HISTOGRAM; i++) {
1457- if (m_get_latency[i] > 0 ) {
1458- total_count += m_get_latency[i];
1459- fprintf (out, " %-6s %12u %12.2f\n " ,
1460- " GET" , i, (double ) total_count / m_totals.m_ops_get * 100 );
1461- }
1462- }
1459+ for ( latency_map_itr_const it = m_get_latency_map.begin () ; it != m_get_latency_map.end () ; it++) {
1460+ total_count += it->second ;
1461+ fprintf (out, " %-6s %8.3f %12.2f\n " , " GET" , it->first , (double ) total_count / m_totals.m_ops_get * 100 );
1462+ }
14631463}
14641464
0 commit comments