time.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2016 The Cartographer Authors
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *      http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #ifndef CARTOGRAPHER_COMMON_TIME_H_
00018 #define CARTOGRAPHER_COMMON_TIME_H_
00019 
00020 #include <chrono>
00021 #include <ostream>
00022 #include <ratio>
00023 
00024 #include "cartographer/common/port.h"
00025 
00026 namespace cartographer {
00027 namespace common {
00028 
00029 constexpr int64 kUtsEpochOffsetFromUnixEpochInSeconds =
00030     (719162ll * 24ll * 60ll * 60ll);
00031 
00032 struct UniversalTimeScaleClock {
00033   using rep = int64;
00034   using period = std::ratio<1, 10000000>;
00035   using duration = std::chrono::duration<rep, period>;
00036   using time_point = std::chrono::time_point<UniversalTimeScaleClock>;
00037   static constexpr bool is_steady = true;
00038 };
00039 
00040 // Represents Universal Time Scale durations and timestamps which are 64-bit
00041 // integers representing the 100 nanosecond ticks since the Epoch which is
00042 // January 1, 1 at the start of day in UTC.
00043 using Duration = UniversalTimeScaleClock::duration;
00044 using Time = UniversalTimeScaleClock::time_point;
00045 
00046 // Convenience functions to create common::Durations.
00047 Duration FromSeconds(double seconds);
00048 Duration FromMilliseconds(int64 milliseconds);
00049 
00050 // Returns the given duration in seconds.
00051 double ToSeconds(Duration duration);
00052 double ToSeconds(std::chrono::steady_clock::duration duration);
00053 
00054 // Creates a time from a Universal Time Scale.
00055 Time FromUniversal(int64 ticks);
00056 
00057 // Outputs the Universal Time Scale timestamp for a given Time.
00058 int64 ToUniversal(Time time);
00059 
00060 // For logging and unit tests, outputs the timestamp integer.
00061 std::ostream& operator<<(std::ostream& os, Time time);
00062 
00063 // CPU time consumed by the thread so far, in seconds.
00064 double GetThreadCpuTimeSeconds();
00065 
00066 }  // namespace common
00067 }  // namespace cartographer
00068 
00069 #endif  // CARTOGRAPHER_COMMON_TIME_H_


cartographer
Author(s): The Cartographer Authors
autogenerated on Thu May 9 2019 02:27:36