• 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 kSecondsToMillis = 1000ULL;
33   static constexpr uint64 kSecondsToMicros = 1000ULL * 1000ULL;
34   static constexpr uint64 kSecondsToNanos = 1000ULL * 1000ULL * 1000ULL;
35 
36   EnvTime();
37   virtual ~EnvTime() = default;
38 
39   /// \brief Returns a default impl suitable for the current operating
40   /// system.
41   ///
42   /// The result of Default() belongs to this library and must never be deleted.
43   static EnvTime* Default();
44 
45   /// \brief Returns the number of nano-seconds since the Unix epoch.
46   virtual uint64 NowNanos() = 0;
47 
48   /// \brief Returns the number of micro-seconds since the Unix epoch.
NowMicros()49   virtual uint64 NowMicros() { return NowNanos() / kMicrosToNanos; }
50 
51   /// \brief Returns the number of seconds since the Unix epoch.
NowSeconds()52   virtual uint64 NowSeconds() { return NowNanos() / kSecondsToNanos; }
53 };
54 
55 }  // namespace tensorflow
56 
57 #endif  // TENSORFLOW_CORE_PLATFORM_ENV_TIME_H_
58