From 65f51a72b5697e537338422a39a015f2207ab5bc Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 1 Mar 2024 18:45:09 +0100 Subject: improve Ns Debug{} format --- src/timer-ns.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/timer-ns.cpp b/src/timer-ns.cpp index 2b4bfd09..a6d1a073 100644 --- a/src/timer-ns.cpp +++ b/src/timer-ns.cpp @@ -2,6 +2,7 @@ #include "compat/assert.hpp" #include "compat/debug.hpp" #include +#include namespace floormat { @@ -101,10 +102,24 @@ uint64_t Ns::operator*() const { return stamp; } Debug& operator<<(Debug& dbg, const Ns& box) { + const auto value = (float)((double)box.stamp * 1e-6); + const auto absval = Math::abs(value); + int precision; + if (absval < 2) + precision = 4; + else if (absval < 5) + precision = 2; + else if (absval < 100) + precision = 1; + else + precision = 0; auto flags = dbg.flags(); dbg << ""; dbg.setFlags(flags | Debug::Flag::NoSpace); - dbg << fraction((float)((double)box.stamp * 1e-6), 1) << " ms"; + dbg << "{"; + dbg << fraction(value, precision); + //dbg << " ms"; + dbg << "}"; dbg.setFlags(flags); return dbg; } -- cgit v1.2.3