summaryrefslogtreecommitdiffstats
path: root/src/time_histogram.cpp
diff options
context:
space:
mode:
authorIdo Barnea <ibarnea@cisco.com>2016-06-02 15:17:46 +0300
committerIdo Barnea <ibarnea@cisco.com>2016-06-02 15:18:06 +0300
commitf26d353e820577c133d26b283bea66c4febeecc3 (patch)
tree16aa0decfacdce57b0c4bdc1b7026f190fd263a9 /src/time_histogram.cpp
parent825a35322828e53080549c4f09bb9469d7806387 (diff)
flow latency json changes
Diffstat (limited to 'src/time_histogram.cpp')
-rwxr-xr-xsrc/time_histogram.cpp41
1 files changed, 32 insertions, 9 deletions
diff --git a/src/time_histogram.cpp b/src/time_histogram.cpp
index 8a92cb6f..fefa59d6 100755
--- a/src/time_histogram.cpp
+++ b/src/time_histogram.cpp
@@ -66,10 +66,6 @@ bool CTimeHistogram::Add(dsec_t dt) {
return false;
}
period_elem.inc_high_cnt();
-
- if ( m_max_dt < dt) {
- m_max_dt = dt;
- }
period_elem.update_max(dt);
uint32_t d_10usec = (uint32_t)(dt*100000.0);
@@ -118,6 +114,9 @@ void CTimeHistogram::update() {
update_average(period_elem);
m_total_cnt += period_elem.get_cnt();
m_total_cnt_high += period_elem.get_high_cnt();
+ if ( m_max_dt < period_elem.get_max()) {
+ m_max_dt = period_elem.get_max();
+ }
}
void CTimeHistogram::update_average(CTimeHistogramPerPeriodData &period_elem) {
@@ -180,11 +179,7 @@ void CTimeHistogram::Dump(FILE *fd) {
}
}
-/*
- { "histogram" : [ {} ,{} ] }
-
-*/
-
+// Used in statefull
void CTimeHistogram::dump_json(std::string name,std::string & json ) {
char buff[200];
if (name != "")
@@ -222,3 +217,31 @@ void CTimeHistogram::dump_json(std::string name,std::string & json ) {
}
json+=" ] } ,";
}
+
+// Used in stateless
+void CTimeHistogram::dump_json(Json::Value & json, bool add_histogram) {
+ int i, j;
+ uint32_t base=10;
+ CTimeHistogramPerPeriodData &period_elem = m_period_data[get_read_period_index()];
+
+ json["total_max"] = get_usec(m_max_dt);
+ json["last_max"] = get_usec(period_elem.get_max());
+ json["average"] = get_average_latency();
+
+ if (add_histogram) {
+ for (j = 0; j < HISTOGRAM_SIZE_LOG; j++) {
+ for (i = 0; i < HISTOGRAM_SIZE; i++) {
+ if (m_hcnt[j][i] > 0) {
+ std::string key = static_cast<std::ostringstream*>( &(std::ostringstream()
+ << int(base * (i + 1)) ) )->str();
+ json["histogram"][key] = Json::Value::UInt64(m_hcnt[j][i]);
+ }
+ }
+ base = base * 10;
+ }
+ if (m_total_cnt != m_total_cnt_high) {
+ json["histogram"]["0"] = Json::Value::UInt64(m_total_cnt - m_total_cnt_high);
+ }
+ }
+}
+