From e8ed802ddd792bddc0b5d0fe3ae3134c6ce2b474 Mon Sep 17 00:00:00 2001 From: Marcin Siodelski Date: Mon, 20 Apr 2015 16:53:02 +0200 Subject: [PATCH] [3804] Fixed broken conversion of duration to text --- src/lib/util/stopwatch_impl.cc | 4 +++- src/lib/util/tests/stopwatch_unittest.cc | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) 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 -- 2.47.3