From: Marcin Siodelski Date: Mon, 20 Apr 2015 14:53:02 +0000 (+0200) Subject: [3804] Fixed broken conversion of duration to text X-Git-Tag: trac3791_base~2^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e8ed802ddd792bddc0b5d0fe3ae3134c6ce2b474;p=thirdparty%2Fkea.git [3804] Fixed broken conversion of duration to text --- diff --git a/src/lib/util/stopwatch_impl.cc b/src/lib/util/stopwatch_impl.cc index b124aea0f0..79fc71ae23 100644 --- a/src/lib/util/stopwatch_impl.cc +++ b/src/lib/util/stopwatch_impl.cc @@ -13,6 +13,7 @@ // PERFORMANCE OF THIS SOFTWARE. #include +#include #include namespace isc { @@ -87,7 +88,8 @@ std::string StopwatchImpl::logFormat(const boost::posix_time::time_duration& duration) { std::ostringstream s; s << duration.total_milliseconds() << "."; - s << (duration.total_microseconds() % 1000) << " ms"; + s << std::setfill('0') << std::setw(3) << (duration.total_microseconds() % 1000) + << " ms"; return (s.str()); } diff --git a/src/lib/util/tests/stopwatch_unittest.cc b/src/lib/util/tests/stopwatch_unittest.cc index 4a0fc53fa5..973b71fe7d 100644 --- a/src/lib/util/tests/stopwatch_unittest.cc +++ b/src/lib/util/tests/stopwatch_unittest.cc @@ -287,14 +287,14 @@ TEST_F(StopwatchTest, autostart) { // Make sure that the conversion to the loggable string works as expected. TEST_F(StopwatchTest, logFormat) { - time_duration duration = microseconds(223543); - EXPECT_EQ("223.543 ms", StopwatchImpl::logFormat(duration)); + time_duration duration = microseconds(223043); + EXPECT_EQ("223.043 ms", StopwatchImpl::logFormat(duration)); duration = microseconds(1234); EXPECT_EQ("1.234 ms", StopwatchImpl::logFormat(duration)); duration = microseconds(2000); - EXPECT_EQ("2.0 ms", StopwatchImpl::logFormat(duration)); + EXPECT_EQ("2.000 ms", StopwatchImpl::logFormat(duration)); } } // end of anonymous namespace