]>
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. | |
11fdf7f2 TL |
6 | * |
7 | * Author: J. Eric Ivancich <ivancich@redhat.com> | |
8 | * | |
9 | * This is free software; you can redistribute it and/or modify it | |
10 | * under the terms of the GNU Lesser General Public License version | |
11 | * 2.1, as published by the Free Software Foundation. See file | |
12 | * COPYING. | |
7c673cae FG |
13 | */ |
14 | ||
15 | ||
16 | #pragma once | |
17 | ||
18 | ||
19 | #include <unistd.h> | |
20 | #include <assert.h> | |
21 | #include <sys/time.h> | |
22 | ||
23 | #include <limits> | |
24 | #include <cmath> | |
25 | #include <chrono> | |
26 | ||
27 | ||
28 | namespace crimson { | |
29 | namespace dmclock { | |
30 | // we're using double to represent time, but we could change it by | |
31 | // changing the following declarations (and by making sure a min | |
32 | // function existed) | |
33 | using Time = double; | |
34 | static const Time TimeZero = 0.0; | |
35 | static const Time TimeMax = std::numeric_limits<Time>::max(); | |
36 | static const double NaN = nan(""); | |
37 | ||
38 | ||
39 | inline Time get_time() { | |
d2e6a577 FG |
40 | #if defined(__linux__) |
41 | struct timespec now; | |
42 | auto result = clock_gettime(CLOCK_REALTIME, &now); | |
43 | (void) result; // reference result in case assert is compiled out | |
44 | assert(0 == result); | |
45 | return now.tv_sec + (now.tv_nsec / 1.0e9); | |
46 | #else | |
7c673cae FG |
47 | struct timeval now; |
48 | auto result = gettimeofday(&now, NULL); | |
d2e6a577 | 49 | (void) result; // reference result in case assert is compiled out |
7c673cae | 50 | assert(0 == result); |
d2e6a577 FG |
51 | return now.tv_sec + (now.tv_usec / 1.0e6); |
52 | #endif | |
7c673cae FG |
53 | } |
54 | ||
9f95a23c | 55 | std::string format_time(const Time& time, unsigned modulo = 1000); |
7c673cae FG |
56 | |
57 | void debugger(); | |
58 | ||
59 | } // namespace dmclock | |
60 | } // namespace crimson |