klee
Time.h
Go to the documentation of this file.
1//===-- Time.h --------------------------------------------------*- C++ -*-===//
2//
3// The KLEE Symbolic Virtual Machine
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef KLEE_TIME_H
11#define KLEE_TIME_H
12
13#include "llvm/Support/raw_ostream.h"
14
15#include <chrono>
16#include <string>
17#include <sys/time.h>
18
19namespace klee {
20 namespace time {
21
26
27 struct Point;
28 struct Span;
29
31 std::string getClockInfo();
32
35
38
39 struct Point {
40 using SteadyTimePoint = std::chrono::steady_clock::time_point;
41
43
44 // ctors
45 Point() = default;
46 explicit Point(SteadyTimePoint p): point(p) {};
47
48 // operators
49 Point& operator+=(const Span&);
50 Point& operator-=(const Span&);
51 };
52
53 // operators
54 Point operator+(const Point&, const Span&);
55 Point operator+(const Span&, const Point&);
56 Point operator-(const Point&, const Span&);
57 Span operator-(const Point&, const Point&);
58 bool operator==(const Point&, const Point&);
59 bool operator!=(const Point&, const Point&);
60 bool operator<(const Point&, const Point&);
61 bool operator<=(const Point&, const Point&);
62 bool operator>(const Point&, const Point&);
63 bool operator>=(const Point&, const Point&);
64
65 namespace { using Duration = std::chrono::steady_clock::duration; }
66
67 struct Span {
68 Duration duration = Duration::zero();
69
70 // ctors
71 Span() = default;
72 explicit Span(const Duration &d): duration(d) {}
73 explicit Span(const std::string &s);
74
75 // operators
76 Span& operator=(const Duration&);
77 Span& operator+=(const Span&);
78 Span& operator-=(const Span&);
79 Span& operator*=(unsigned);
80 Span& operator*=(double);
81
82 // conversions
83 explicit operator Duration() const;
84 explicit operator bool() const;
85 explicit operator timeval() const;
86
87 std::uint64_t toMicroseconds() const;
88 double toSeconds() const;
89 std::tuple<std::uint32_t, std::uint8_t, std::uint8_t> toHMS() const; // hours, minutes, seconds
90 };
91
92 Span operator+(const Span&, const Span&);
93 Span operator-(const Span&, const Span&);
94 Span operator*(const Span&, double);
95 Span operator*(double, const Span&);
96 Span operator*(const Span&, unsigned);
97 Span operator*(unsigned, const Span&);
98 Span operator/(const Span&, unsigned);
99 bool operator==(const Span&, const Span&);
100 bool operator<=(const Span&, const Span&);
101 bool operator>=(const Span&, const Span&);
102 bool operator<(const Span&, const Span&);
103 bool operator>(const Span&, const Span&);
104
106 std::ostream& operator<<(std::ostream&, Span);
107 llvm::raw_ostream& operator<<(llvm::raw_ostream&, Span);
108
110 Span hours(std::uint16_t);
111 Span minutes(std::uint16_t);
112 Span seconds(std::uint64_t);
113 Span milliseconds(std::uint64_t);
114 Span microseconds(std::uint64_t);
115 Span nanoseconds(std::uint64_t);
116
117 } // time
118} // klee
119
120#endif /* KLEE_TIME_H */
bool operator>(const Point &, const Point &)
Definition: Time.cpp:50
Span microseconds(std::uint64_t)
Definition: Time.cpp:141
Point operator+(const Point &, const Span &)
Definition: Time.cpp:42
Span getUserTime()
Returns time spent by this process in user mode.
Definition: Time.cpp:191
Span nanoseconds(std::uint64_t)
Definition: Time.cpp:142
Span minutes(std::uint16_t)
Definition: Time.cpp:138
Span operator/(const Span &, unsigned)
Definition: Time.cpp:125
Span hours(std::uint16_t)
time spans
Definition: Time.cpp:137
Point getWallTime()
Returns point in time using a monotonic steady clock.
Definition: Time.cpp:206
bool operator>=(const Point &, const Point &)
Definition: Time.cpp:51
Span operator*(const Span &, double)
Definition: Time.cpp:117
std::string getClockInfo()
Returns information about clock.
Definition: Time.cpp:179
bool operator<=(const Point &, const Point &)
Definition: Time.cpp:49
bool operator==(const Point &, const Point &)
Definition: Time.cpp:46
Span seconds(std::uint64_t)
Definition: Time.cpp:139
Span milliseconds(std::uint64_t)
Definition: Time.cpp:140
bool operator!=(const Point &, const Point &)
Definition: Time.cpp:47
bool operator<(const Point &, const Point &)
Definition: Time.cpp:48
std::ostream & operator<<(std::ostream &, Span)
Span -> "X.Ys".
Definition: Time.cpp:132
Point operator-(const Point &, const Span &)
Definition: Time.cpp:44
Definition: main.cpp:291
Point & operator+=(const Span &)
Definition: Time.cpp:39
Point(SteadyTimePoint p)
Definition: Time.h:46
Point & operator-=(const Span &)
Definition: Time.cpp:40
SteadyTimePoint point
Definition: Time.h:42
std::chrono::steady_clock::time_point SteadyTimePoint
Definition: Time.h:40
Span(const Duration &d)
Definition: Time.h:72
double toSeconds() const
Definition: Time.cpp:163
std::tuple< std::uint32_t, std::uint8_t, std::uint8_t > toHMS() const
Definition: Time.cpp:167
std::uint64_t toMicroseconds() const
Definition: Time.cpp:159
Span & operator*=(unsigned)
Definition: Time.cpp:109
Duration duration
Definition: Time.h:68
Span & operator-=(const Span &)
Definition: Time.cpp:108
Span & operator=(const Duration &)
Definition: Time.cpp:106
Span & operator+=(const Span &)
Definition: Time.cpp:107