summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/timer-ns.cpp66
1 files changed, 50 insertions, 16 deletions
diff --git a/src/timer-ns.cpp b/src/timer-ns.cpp
index b467ce19..1f927f14 100644
--- a/src/timer-ns.cpp
+++ b/src/timer-ns.cpp
@@ -8,27 +8,61 @@ namespace floormat {
-Debug& operator<<(Debug& dbg, const Ns& box)
+Debug& operator<<(Debug& dbg, const Ns& val)
{
- const auto value = (float)((double)box.stamp * 1e-6);
- const auto absval = Math::abs(value);
+ const char* unit;
+ double x = val.stamp;
int precision;
- if (absval < 2)
- precision = 4;
- else if (absval < 5)
- precision = 2;
- else if (absval < 100)
+ if (val >= 10*Second)
+ {
+ unit = "s";
+ x *= 1e-9;
precision = 1;
+ }
+#if 0
+ else if (val >= 1*Second)
+ {
+ unit = "ms";
+ x *= 1e-6;
+ precision = 3;
+
+ }
+#endif
+ else if (val >= 100*Millisecond)
+ {
+ unit = "ms";
+ x *= 1e-6;
+ precision = 3;
+ }
+ else if (val >= 50*Microsecond)
+ {
+ unit = "ms";
+ x *= 1e-6;
+ precision = 4;
+ }
+ else if (val >= 1*Microsecond)
+ {
+ unit = "usec";
+ x *= 1e-3;
+ precision = 3;
+ }
+ else if (val.stamp > 1000)
+ {
+ char buf[64];
+ std::snprintf(buf, sizeof buf, "%llu_%llu ns",
+ val.stamp / 1000, val.stamp % 1000);
+ return dbg;
+ }
else
+ {
+ unit = "ns";
precision = 0;
- auto flags = dbg.flags();
- dbg << "";
- dbg.setFlags(flags | Debug::Flag::NoSpace);
- //dbg << "{";
- dbg << fraction(value, precision);
- dbg << " ms";
- //dbg << "}";
- dbg.setFlags(flags);
+ }
+ if (!precision)
+ dbg << (uint64_t)x << Debug::space << unit;
+ else
+ dbg << fraction((float)x, precision) << Debug::space << unit;
+
return dbg;
}