• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2015 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 #ifndef TENSORFLOW_CORE_PLATFORM_ENV_TIME_H_
16 #define TENSORFLOW_CORE_PLATFORM_ENV_TIME_H_
17 
18 #include <stdint.h>
19 
20 #include "tensorflow/core/platform/types.h"
21 
22 namespace tensorflow {
23 
24 /// \brief An interface used by the tensorflow implementation to
25 /// access timer related operations.
26 class EnvTime {
27  public:
28   static constexpr uint64 kMicrosToPicos = 1000ULL * 1000ULL;
29   static constexpr uint64 kMicrosToNanos = 1000ULL;
30   static constexpr uint64 kMillisToMicros = 1000ULL;
31   static constexpr uint64 kMillisToNanos = 1000ULL * 1000ULL;
32   static constexpr uint64 kNanosToPicos = 1000ULL;
33   static constexpr uint64 kSecondsToMillis = 1000ULL;
34   static constexpr uint64 kSecondsToMicros = 1000ULL * 1000ULL;
35   static constexpr uint64 kSecondsToNanos = 1000ULL * 1000ULL * 1000ULL;
36 
37   EnvTime() = default;
38   virtual ~EnvTime() = default;
39 
40   /// \brief Returns the number of nano-seconds since the Unix epoch.
41   static uint64 NowNanos();
42 
43   /// \brief Returns the number of micro-seconds since the Unix epoch.
NowMicros()44   static uint64 NowMicros() { return NowNanos() / kMicrosToNanos; }
45 
46   /// \brief Returns the number of seconds since the Unix epoch.
NowSeconds()47   static uint64 NowSeconds() { return NowNanos() / kSecondsToNanos; }
48 
49   /// \brief A version of NowNanos() that may be overridden by a subclass.
GetOverridableNowNanos()50   virtual uint64 GetOverridableNowNanos() const { return NowNanos(); }
51 
52   /// \brief A version of NowMicros() that may be overridden by a subclass.
GetOverridableNowMicros()53   virtual uint64 GetOverridableNowMicros() const {
54     return GetOverridableNowNanos() / kMicrosToNanos;
55   }
56 
57   /// \brief A version of NowSeconds() that may be overridden by a subclass.
GetOverridableNowSeconds()58   virtual uint64 GetOverridableNowSeconds() const {
59     return GetOverridableNowNanos() / kSecondsToNanos;
60   }
61 };
62 
63 }  // namespace tensorflow
64 
65 #endif  // TENSORFLOW_CORE_PLATFORM_ENV_TIME_H_
66