From b7c74d4a77f802b5ec5b6177009f0a2937bde201 Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Wed, 21 Apr 2010 14:48:48 +0000 Subject: Count latency samples, don't assume all messages are latency samples. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@936336 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/tests/Statistics.cpp | 11 +++++++---- cpp/src/tests/Statistics.h | 1 + 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'cpp') diff --git a/cpp/src/tests/Statistics.cpp b/cpp/src/tests/Statistics.cpp index a3852e64af..c002bc6a6a 100644 --- a/cpp/src/tests/Statistics.cpp +++ b/cpp/src/tests/Statistics.cpp @@ -52,13 +52,15 @@ void Throughput::report(ostream& o) const { ThroughputAndLatency::ThroughputAndLatency() : total(0), min(numeric_limits::max()), - max(numeric_limits::min()) + max(numeric_limits::min()), + samples(0) {} void ThroughputAndLatency::message(const messaging::Message& m) { Throughput::message(m); types::Variant::Map::const_iterator i = m.getProperties().find("ts"); if (i != m.getProperties().end()) { + ++samples; int64_t start(i->second.asInt64()); int64_t end(sys::Duration(sys::EPOCH, sys::now())); double latency = double(end - start)/sys::TIME_MSEC; @@ -77,11 +79,12 @@ void ThroughputAndLatency::header(ostream& o) const { void ThroughputAndLatency::report(ostream& o) const { Throughput::report(o); - if (messages) + if (samples) { o << fixed << setprecision(2) - << '\t' << min << '\t' << max << '\t' << total/messages; + << '\t' << min << '\t' << max << '\t' << total/samples; + } else - o << "\t<0 messages, can't compute latency>"; + o << "\t[No latency samples]"; } ReporterBase::ReporterBase(ostream& o, int batch, bool wantHeader) diff --git a/cpp/src/tests/Statistics.h b/cpp/src/tests/Statistics.h index 90bdbb6819..091046a17f 100644 --- a/cpp/src/tests/Statistics.h +++ b/cpp/src/tests/Statistics.h @@ -68,6 +68,7 @@ class ThroughputAndLatency : public Throughput { private: double total, min, max; // Milliseconds + int samples; }; /** Report batch and overall statistics */ -- cgit v1.2.1