• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2016 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 
16 // Null implementation of the Counter metric for mobile platforms.
17 
18 #ifndef TENSORFLOW_CORE_LIB_MONITORING_MOBILE_COUNTER_H_
19 #define TENSORFLOW_CORE_LIB_MONITORING_MOBILE_COUNTER_H_
20 
21 #if !defined(IS_MOBILE_PLATFORM) || !defined(TENSORFLOW_INCLUDED_FROM_COUNTER_H)
22 // If this header file were included directly, and something else included its
23 // non-mobile counterpart, there could be an unchecked ODR violation on the
24 // classes below.
25 #error do not include mobile_counter.h directly; use counter.h instead
26 #endif  // !defined(IS_MOBILE_PLATFORM) ||
27         // !defined(TENSORFLOW_INCLUDED_FROM_COUNTER_H)
28 
29 #include "tensorflow/core/lib/core/status.h"
30 #include "tensorflow/core/platform/macros.h"
31 #include "tensorflow/core/platform/types.h"
32 
33 namespace tensorflow {
34 namespace monitoring {
35 
36 // CounterCell which has a null implementation.
37 class CounterCell {
38  public:
CounterCell()39   CounterCell() {}
~CounterCell()40   ~CounterCell() {}
41 
IncrementBy(int64 step)42   void IncrementBy(int64 step) {}
value()43   int64 value() const { return 0; }
44 
45  private:
46   TF_DISALLOW_COPY_AND_ASSIGN(CounterCell);
47 };
48 
49 // Counter which has a null implementation.
50 template <int NumLabels>
51 class Counter {
52  public:
~Counter()53   ~Counter() {}
54 
55   template <typename... MetricDefArgs>
New(MetricDefArgs &&...metric_def_args)56   static Counter* New(MetricDefArgs&&... metric_def_args) {
57     return new Counter<NumLabels>();
58   }
59 
60   template <typename... Labels>
GetCell(const Labels &...labels)61   CounterCell* GetCell(const Labels&... labels) {
62     return &default_counter_cell_;
63   }
64 
GetStatus()65   Status GetStatus() { return Status::OK(); }
66 
67  private:
Counter()68   Counter() {}
69 
70   CounterCell default_counter_cell_;
71 
72   TF_DISALLOW_COPY_AND_ASSIGN(Counter);
73 };
74 
75 }  // namespace monitoring
76 }  // namespace tensorflow
77 
78 #endif  // TENSORFLOW_CORE_LIB_MONITORING_MOBILE_COUNTER_H_
79