Commit e8ed802d authored by Marcin Siodelski's avatar Marcin Siodelski
Browse files

[3804] Fixed broken conversion of duration to text

parent 04b76159
......@@ -13,6 +13,7 @@
// PERFORMANCE OF THIS SOFTWARE.
#include <util/stopwatch_impl.h>
#include <iomanip>
#include <sstream>
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());
}
......
......@@ -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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment