blob: 1f927f14d6198227fd7dfc48b7d5094a02c5f69a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
#include "timer.hpp"
#include "compat/assert.hpp"
#include "compat/debug.hpp"
#include <cr/Debug.h>
#include <mg/Functions.h>
namespace floormat {
Debug& operator<<(Debug& dbg, const Ns& val)
{
const char* unit;
double x = val.stamp;
int precision;
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;
}
if (!precision)
dbg << (uint64_t)x << Debug::space << unit;
else
dbg << fraction((float)x, precision) << Debug::space << unit;
return dbg;
}
} // namespace floormat
|