]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | ||
4 | /* | |
5 | * Copyright (C) 2017 Red Hat Inc. | |
6 | */ | |
7 | ||
8 | ||
9 | #pragma once | |
10 | ||
11 | ||
12 | #include <unistd.h> | |
13 | #include <assert.h> | |
14 | #include <sys/time.h> | |
15 | ||
16 | #include <limits> | |
17 | #include <cmath> | |
18 | #include <chrono> | |
19 | ||
20 | ||
21 | namespace crimson { | |
22 | namespace dmclock { | |
23 | // we're using double to represent time, but we could change it by | |
24 | // changing the following declarations (and by making sure a min | |
25 | // function existed) | |
26 | using Time = double; | |
27 | static const Time TimeZero = 0.0; | |
28 | static const Time TimeMax = std::numeric_limits<Time>::max(); | |
29 | static const double NaN = nan(""); | |
30 | ||
31 | ||
32 | inline Time get_time() { | |
d2e6a577 FG |
33 | #if defined(__linux__) |
34 | struct timespec now; | |
35 | auto result = clock_gettime(CLOCK_REALTIME, &now); | |
36 | (void) result; // reference result in case assert is compiled out | |
37 | assert(0 == result); | |
38 | return now.tv_sec + (now.tv_nsec / 1.0e9); | |
39 | #else | |
7c673cae FG |
40 | struct timeval now; |
41 | auto result = gettimeofday(&now, NULL); | |
d2e6a577 | 42 | (void) result; // reference result in case assert is compiled out |
7c673cae | 43 | assert(0 == result); |
d2e6a577 FG |
44 | return now.tv_sec + (now.tv_usec / 1.0e6); |
45 | #endif | |
7c673cae FG |
46 | } |
47 | ||
48 | std::string format_time(const Time& time, uint modulo = 1000); | |
49 | ||
50 | void debugger(); | |
51 | ||
52 | } // namespace dmclock | |
53 | } // namespace crimson |