diff options
-rwxr-xr-x | src/bp_gtest.cpp | 18 | ||||
-rwxr-xr-x | src/time_histogram.cpp | 14 | ||||
-rwxr-xr-x | src/time_histogram.h | 4 |
3 files changed, 21 insertions, 15 deletions
diff --git a/src/bp_gtest.cpp b/src/bp_gtest.cpp index 7bb3da0c..86b7821b 100755 --- a/src/bp_gtest.cpp +++ b/src/bp_gtest.cpp @@ -2657,19 +2657,17 @@ public: TEST_F(time_histogram, test_average) { int i; int j; - // Latency is calculated by low pass filter, so need to give it time to stabilize - for (j=0; j < 13; j++) { - for (i=0; i<100; i++) { - m_hist.Add(10e-6); - } - for (i=0; i<100; i++) { - m_hist.Add(10e-3); + for (j = 0; j < 10; j++) { + for (i = 0; i <= 2000; i++) { + m_hist.Add(10e-7 * i); } m_hist.update(); + // Latency is calculated using low pass filter, with initial value of 0 + EXPECT_EQ(m_hist.get_average_latency(), 1000.0 - (1000.0 / (2 << j))); + EXPECT_EQ(m_hist.get_count(), 2001 * (j+1)); + EXPECT_EQ(m_hist.get_high_count(), 2001 * (j+1) - (11 * (j+1))); + EXPECT_EQ(m_hist.get_max_latency(), 2000); } - - EXPECT_GT(m_hist.get_average_latency(), 5004); - EXPECT_LT(m_hist.get_average_latency(), 5005); m_hist.Dump(stdout); } diff --git a/src/time_histogram.cpp b/src/time_histogram.cpp index dd15c4be..8a92cb6f 100755 --- a/src/time_histogram.cpp +++ b/src/time_histogram.cpp @@ -30,6 +30,8 @@ void CTimeHistogram::Reset() { m_period_data[0].reset(); m_period_data[1].reset(); m_period = 0; + m_total_cnt = 0; + m_total_cnt_high = 0; m_max_dt = 0; m_average = 0; memset(&m_max_ar[0],0,sizeof(m_max_ar)); @@ -57,6 +59,9 @@ bool CTimeHistogram::Add(dsec_t dt) { CTimeHistogramPerPeriodData &period_elem = m_period_data[m_period]; period_elem.inc_cnt(); + period_elem.update_sum(dt); + + // values smaller then certain threshold do not get into the histogram if (dt < m_min_delta) { return false; } @@ -87,8 +92,6 @@ bool CTimeHistogram::Add(dsec_t dt) { } } - period_elem.update_sum(dt); - return true; } @@ -113,6 +116,8 @@ void CTimeHistogram::update() { m_win_cnt = 0; } update_average(period_elem); + m_total_cnt += period_elem.get_cnt(); + m_total_cnt_high += period_elem.get_high_cnt(); } void CTimeHistogram::update_average(CTimeHistogramPerPeriodData &period_elem) { @@ -181,7 +186,6 @@ void CTimeHistogram::Dump(FILE *fd) { */ void CTimeHistogram::dump_json(std::string name,std::string & json ) { - CTimeHistogramPerPeriodData &period_elem = m_period_data[get_read_period_index()]; char buff[200]; if (name != "") sprintf(buff,"\"%s\":{",name.c_str()); @@ -191,8 +195,8 @@ void CTimeHistogram::dump_json(std::string name,std::string & json ) { json += add_json("min_usec", get_usec(m_min_delta)); json += add_json("max_usec", get_usec(m_max_dt)); - json += add_json("high_cnt", period_elem.get_high_cnt()); - json += add_json("cnt", period_elem.get_cnt()); + json += add_json("high_cnt", m_total_cnt_high); + json += add_json("cnt", m_total_cnt); json+=add_json("s_avg", get_average_latency()); int i; int j; diff --git a/src/time_histogram.h b/src/time_histogram.h index 9bdf2c93..da70e677 100755 --- a/src/time_histogram.h +++ b/src/time_histogram.h @@ -85,6 +85,8 @@ public: return period_elem.get_max_usec(); } void dump_json(std::string name,std::string & json ); + uint64_t get_count() {return m_total_cnt;} + uint64_t get_high_count() {return m_total_cnt_high;} private: uint32_t get_usec(dsec_t d); @@ -103,6 +105,8 @@ private: // Each period we switch between the two CTimeHistogramPerPeriodData m_period_data[2]; uint8_t m_period; // 0 or 1 according to m_period_data element we currently use + uint64_t m_total_cnt; + uint64_t m_total_cnt_high; dsec_t m_max_dt; // Total maximum latency dsec_t m_average; /* moving average */ uint32_t m_win_cnt; |