10 #ifndef LLVM_SUPPORT_CHRONO_H
11 #define LLVM_SUPPORT_CHRONO_H
33 template <
typename D = std::chrono::nanoseconds>
34 using TimePoint = std::chrono::time_point<std::chrono::system_clock, D>;
38 using namespace std::chrono;
39 return system_clock::to_time_t(
40 time_point_cast<system_clock::time_point::duration>(TP));
46 using namespace std::chrono;
47 return time_point_cast<seconds>(system_clock::from_time_t(T));
52 raw_ostream &operator<<(raw_ostream &OS, sys::TimePoint<> TP);
79 template <
typename Period>
struct unit {
static const char value[]; };
82 template <>
struct unit<std::ratio<3600>> {
static const char value[]; };
83 template <>
struct unit<std::ratio<60>> {
static const char value[]; };
84 template <>
struct unit<std::ratio<1>> {
static const char value[]; };
85 template <>
struct unit<std::milli> {
static const char value[]; };
86 template <>
struct unit<std::micro> {
static const char value[]; };
87 template <>
struct unit<std::nano> {
static const char value[]; };
90 template <
typename Rep,
typename Period>
93 typedef std::chrono::duration<Rep, Period> Dur;
94 typedef typename std::conditional<
95 std::chrono::treat_as_floating_point<Rep>::value, double, intmax_t>::type
98 template <
typename AsPeriod>
static InternalRep getAs(
const Dur &
D) {
99 using namespace std::chrono;
100 return duration_cast<duration<InternalRep, AsPeriod>>(
D).
count();
103 static std::pair<InternalRep, StringRef> consumeUnit(
StringRef &
Style,
105 using namespace std::chrono;
107 return {getAs<std::nano>(
D),
"ns"};
109 return {getAs<std::micro>(
D),
"us"};
111 return {getAs<std::milli>(
D),
"ms"};
113 return {getAs<std::ratio<1>>(
D),
"s"};
115 return {getAs<std::ratio<60>>(
D),
"m"};
117 return {getAs<std::ratio<3600>>(
D),
"h"};
121 static bool consumeShowUnit(
StringRef &Style) {
128 assert(0 &&
"Unrecognised duration format");
136 std::tie(count, unit) = consumeUnit(Style, D);
137 bool show_unit = consumeShowUnit(Style);
143 Stream <<
" " << unit;
150 #endif // LLVM_SUPPORT_CHRONO_H
LLVM_ATTRIBUTE_ALWAYS_INLINE std::time_t toTimeT(TimePoint<> TP)
Convert a TimePoint to std::time_t.
LLVM_ATTRIBUTE_ALWAYS_INLINE TimePoint< std::chrono::seconds > toTimePoint(std::time_t T)
Convert a std::time_t to a TimePoint.
#define LLVM_ATTRIBUTE_ALWAYS_INLINE
LLVM_ATTRIBUTE_ALWAYS_INLINE - On compilers where we have a directive to do so, mark a method "always...
LLVM_ATTRIBUTE_ALWAYS_INLINE bool consume_front(StringRef Prefix)
Returns true if this StringRef has the given prefix and removes that prefix.
auto count(R &&Range, const E &Element) -> typename std::iterator_traits< decltype(std::begin(Range))>::difference_type
Wrapper function around std::count to count the number of times an element Element occurs in the give...
format_object< Ts...> format(const char *Fmt, const Ts &...Vals)
These are helper functions used to produce formatted output.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This class implements an extremely fast bulk output stream that can only output to a stream...
StringRef - Represent a constant reference to a string, i.e.
std::chrono::time_point< std::chrono::system_clock, D > TimePoint
A time point on the system clock.