]>
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() { | |
33 | struct timeval now; | |
34 | auto result = gettimeofday(&now, NULL); | |
35 | (void) result; | |
36 | assert(0 == result); | |
37 | return now.tv_sec + (now.tv_usec / 1000000.0); | |
38 | } | |
39 | ||
40 | std::string format_time(const Time& time, uint modulo = 1000); | |
41 | ||
42 | void debugger(); | |
43 | ||
44 | } // namespace dmclock | |
45 | } // namespace crimson |