@@ -79,6 +79,15 @@ inline unsigned long int ts_diff_now(struct timeval a)
7979 return bval - aval;
8080}
8181
82+ inline timeval timeval_factorial_avarge ( timeval a, timeval b, unsigned int weight)
83+ {
84+ timeval tv;
85+ double factor = ((double )weight - 1 ) / weight;
86+ tv.tv_sec = factor * a.tv_sec + (double )b.tv_sec / weight ;
87+ tv.tv_usec = factor * a.tv_usec + (double )b.tv_usec / weight ;
88+ return (tv);
89+ }
90+
8291client::request::request (request_type type, unsigned int size, struct timeval * sent_time, unsigned int keys)
8392 : m_type(type), m_size(size), m_keys(keys)
8493{
@@ -955,9 +964,10 @@ unsigned long int client_group::get_total_latency(void)
955964unsigned long int client_group::get_duration_usec (void )
956965{
957966 unsigned long int duration = 0 ;
958- for (std::vector<client*>::iterator i = m_clients.begin (); i != m_clients.end (); i++) {
959- if ((*i)->get_stats ()->get_duration_usec () > duration)
960- duration = (*i)->get_stats ()->get_duration_usec ();
967+ unsigned int thread_counter = 1 ;
968+ for (std::vector<client*>::iterator i = m_clients.begin (); i != m_clients.end (); i++, thread_counter++) {
969+ float factor = ((float )(thread_counter - 1 ) / thread_counter);
970+ duration = factor * duration + (float )(*i)->get_stats ()->get_duration_usec () / thread_counter ;
961971 }
962972
963973 return duration;
@@ -966,10 +976,10 @@ unsigned long int client_group::get_duration_usec(void)
966976void client_group::merge_run_stats (run_stats* target)
967977{
968978 assert (target != NULL );
969-
979+ unsigned int iteration_counter = 1 ;
970980 for (std::vector<client*>::iterator i = m_clients.begin (); i != m_clients.end (); i++) {
971- target->merge (*(*i)->get_stats ());
972- }
981+ target->merge (*(*i)->get_stats (), iteration_counter++ );
982+ }
973983}
974984
975985void client_group::write_client_stats (const char *prefix)
@@ -1294,14 +1304,12 @@ void run_stats::aggregate_average(const std::vector<run_stats>& all_stats)
12941304
12951305}
12961306
1297- void run_stats::merge (const run_stats& other)
1307+ void run_stats::merge (const run_stats& other, int iteration )
12981308{
12991309 bool new_stats = false ;
13001310
1301- if (!m_start_time.tv_sec )
1302- m_start_time = other.m_start_time ;
1303- if (!m_end_time.tv_sec )
1304- m_end_time = other.m_end_time ;
1311+ m_start_time = timeval_factorial_avarge ( m_start_time, other.m_start_time , iteration );
1312+ m_end_time = timeval_factorial_avarge ( m_end_time, other.m_end_time , iteration );
13051313
13061314 // aggregate the one_second_stats vectors. this is not efficient
13071315 // but it's not really important (small numbers, not realtime)
0 commit comments