LLVM  4.0.0
Chrono.cpp
Go to the documentation of this file.
1 //===- Support/Chrono.cpp - Utilities for Timing Manipulation ---*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "llvm/Support/Chrono.h"
11 #include "llvm/Config/config.h"
12 #include "llvm/Support/Format.h"
14 
15 namespace llvm {
16 
17 using namespace sys;
18 
19 static inline struct tm getStructTM(TimePoint<> TP) {
20  struct tm Storage;
21  std::time_t OurTime = toTimeT(TP);
22 
23 #if defined(LLVM_ON_UNIX)
24  struct tm *LT = ::localtime_r(&OurTime, &Storage);
25  assert(LT);
26  (void)LT;
27 #endif
28 #if defined(LLVM_ON_WIN32)
29  int Error = ::localtime_s(&Storage, &OurTime);
30  assert(!Error);
31  (void)Error;
32 #endif
33 
34  return Storage;
35 }
36 
37 raw_ostream &operator<<(raw_ostream &OS, TimePoint<> TP) {
38  struct tm LT = getStructTM(TP);
39  char Buffer[sizeof("YYYY-MM-DD HH:MM:SS")];
40  strftime(Buffer, sizeof(Buffer), "%Y-%m-%d %H:%M:%S", &LT);
41  return OS << Buffer << '.'
42  << format("%.9lu",
43  long((TP.time_since_epoch() % std::chrono::seconds(1))
44  .count()));
45 }
46 
47 } // namespace llvm
LLVM_ATTRIBUTE_ALWAYS_INLINE std::time_t toTimeT(TimePoint<> TP)
Convert a TimePoint to std::time_t.
Definition: Chrono.h:36
static struct tm getStructTM(TimePoint<> TP)
Definition: Chrono.cpp:19
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...
Definition: STLExtras.h:791
format_object< Ts...> format(const char *Fmt, const Ts &...Vals)
These are helper functions used to produce formatted output.
Definition: Format.h:124
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Lightweight error class with error context and mandatory checking.
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
std::chrono::time_point< std::chrono::system_clock, D > TimePoint
A time point on the system clock.
Definition: Chrono.h:33