common/ceph_time: make operator<< for timespan less useless

- not a floating point value, which will revert to scientific notation once
  it gets big.
- behave for negative spans

Signed-off-by: Sage Weil <sage@redhat.com>
This commit is contained in:
Sage Weil 2019-07-08 17:12:49 -05:00
parent ad03fb5b80
commit 353a0e5fac

View File

@ -100,7 +100,20 @@ namespace ceph {
}
std::ostream& operator<<(std::ostream& m, const timespan& t) {
return m << std::chrono::duration<double>(t).count() << "s";
int64_t ns = t.count();
if (ns < 0) {
ns = -ns;
m << "-";
}
m << (ns / 1000000000ll);
ns %= 1000000000ll;
if (ns) {
char oldfill = m.fill();
m.fill('0');
m << '.' << std::setw(9) << ns;
m.fill(oldfill);
}
return m << "s";
}
template<typename Clock,