@@ -79,6 +79,15 @@ inline unsigned long int ts_diff_now(struct timeval a)
79
79
return bval - aval;
80
80
}
81
81
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
+
82
91
client::request::request (request_type type, unsigned int size, struct timeval * sent_time, unsigned int keys)
83
92
: m_type(type), m_size(size), m_keys(keys)
84
93
{
@@ -955,9 +964,10 @@ unsigned long int client_group::get_total_latency(void)
955
964
unsigned long int client_group::get_duration_usec (void )
956
965
{
957
966
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 ;
961
971
}
962
972
963
973
return duration;
@@ -966,10 +976,10 @@ unsigned long int client_group::get_duration_usec(void)
966
976
void client_group::merge_run_stats (run_stats* target)
967
977
{
968
978
assert (target != NULL );
969
-
979
+ unsigned int iteration_counter = 1 ;
970
980
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
+ }
973
983
}
974
984
975
985
void client_group::write_client_stats (const char *prefix)
@@ -1294,14 +1304,12 @@ void run_stats::aggregate_average(const std::vector<run_stats>& all_stats)
1294
1304
1295
1305
}
1296
1306
1297
- void run_stats::merge (const run_stats& other)
1307
+ void run_stats::merge (const run_stats& other, int iteration )
1298
1308
{
1299
1309
bool new_stats = false ;
1300
1310
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 );
1305
1313
1306
1314
// aggregate the one_second_stats vectors. this is not efficient
1307
1315
// but it's not really important (small numbers, not realtime)
0 commit comments