From 7e8bf419bf18aab8ef31e8e2c94ec0d95ffa6404 Mon Sep 17 00:00:00 2001 From: Gordon Sim Date: Thu, 4 Sep 2008 07:51:37 +0000 Subject: Bugfixes: * handle 0 latencies (possible with low resolution timers) correctly * calculate average within lock scope to avoid concurrent updates distorting calculation git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@691900 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/cpp/src/tests/latencytest.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'qpid/cpp/src/tests') diff --git a/qpid/cpp/src/tests/latencytest.cpp b/qpid/cpp/src/tests/latencytest.cpp index 6c3fdd23bd..6f71506d48 100644 --- a/qpid/cpp/src/tests/latencytest.cpp +++ b/qpid/cpp/src/tests/latencytest.cpp @@ -237,9 +237,9 @@ void Receiver::received(Message& msg) void Stats::update(double latency) { Mutex::ScopedLock l(lock); + if (!count || minLatency > latency) minLatency = latency; + if (!count || maxLatency < latency) maxLatency = latency; count++; - if (minLatency == 0 || minLatency > latency) minLatency = latency; - if (maxLatency == 0 || maxLatency < latency) maxLatency = latency; totalLatency += latency; } @@ -249,13 +249,13 @@ void Stats::print() { static bool already_have_stats = false; uint value; - double aux_avg = (totalLatency / count); if (opts.rate) value = opts.rate; else value = opts.count; Mutex::ScopedLock l(lock); + double aux_avg = (totalLatency / count); if (!opts.cumulative) { if (!opts.csv) { std::cout << "Latency(ms): min=" << minLatency << ", max=" << -- cgit v1.2.1