1 //===- llvm/Support/Chrono.h - Utilities for Timing Manipulation-*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_SUPPORT_CHRONO_H
11 #define LLVM_SUPPORT_CHRONO_H
13 #include "llvm/Support/Compiler.h"
24 /// A time point on the system clock. This is provided for two reasons:
25 /// - to insulate us agains subtle differences in behavoir to differences in
26 /// system clock precision (which is implementation-defined and differs between
28 /// - to shorten the type name
29 /// The default precision is nanoseconds. If need a specific precision specify
30 /// it explicitly. If unsure, use the default. If you need a time point on a
31 /// clock other than the system_clock, use std::chrono directly.
32 template <typename D = std::chrono::nanoseconds>
33 using TimePoint = std::chrono::time_point<std::chrono::system_clock, D>;
35 /// Convert a TimePoint to std::time_t
36 LLVM_ATTRIBUTE_ALWAYS_INLINE inline std::time_t toTimeT(TimePoint<> TP) {
37 using namespace std::chrono;
38 return system_clock::to_time_t(
39 time_point_cast<system_clock::time_point::duration>(TP));
42 /// Convert a std::time_t to a TimePoint
43 LLVM_ATTRIBUTE_ALWAYS_INLINE inline TimePoint<std::chrono::seconds>
44 toTimePoint(std::time_t T) {
45 using namespace std::chrono;
46 return time_point_cast<seconds>(system_clock::from_time_t(T));
51 raw_ostream &operator<<(raw_ostream &OS, sys::TimePoint<> TP);
55 #endif // LLVM_SUPPORT_CHRONO_H