1 //===- Support/Chrono.cpp - 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 #include "llvm/Support/Chrono.h"
11 #include "llvm/Config/config.h"
12 #include "llvm/Support/Format.h"
13 #include "llvm/Support/raw_ostream.h"
19 const char llvm::detail::unit<std::ratio<3600>>::value[] = "h";
20 const char llvm::detail::unit<std::ratio<60>>::value[] = "m";
21 const char llvm::detail::unit<std::ratio<1>>::value[] = "s";
22 const char llvm::detail::unit<std::milli>::value[] = "ms";
23 const char llvm::detail::unit<std::micro>::value[] = "us";
24 const char llvm::detail::unit<std::nano>::value[] = "ns";
26 static inline struct tm getStructTM(TimePoint<> TP) {
28 std::time_t OurTime = toTimeT(TP);
30 #if defined(LLVM_ON_UNIX)
31 struct tm *LT = ::localtime_r(&OurTime, &Storage);
35 #if defined(LLVM_ON_WIN32)
36 int Error = ::localtime_s(&Storage, &OurTime);
44 raw_ostream &operator<<(raw_ostream &OS, TimePoint<> TP) {
45 struct tm LT = getStructTM(TP);
46 char Buffer[sizeof("YYYY-MM-DD HH:MM:SS")];
47 strftime(Buffer, sizeof(Buffer), "%Y-%m-%d %H:%M:%S", <);
48 return OS << Buffer << '.'
50 long((TP.time_since_epoch() % std::chrono::seconds(1))