1 /* Copyright 2017 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 Gauge metric for mobile platforms. 17 18 #ifndef TENSORFLOW_CORE_LIB_MONITORING_MOBILE_GAUGE_H_ 19 #define TENSORFLOW_CORE_LIB_MONITORING_MOBILE_GAUGE_H_ 20 21 #if !defined(IS_MOBILE_PLATFORM) || !defined(TENSORFLOW_INCLUDED_FROM_GAUGE_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_gauge.h directly; use gauge.h instead 26 #endif // !defined(IS_MOBILE_PLATFORM) || 27 // !defined(TENSORFLOW_INCLUDED_FROM_GAUGE_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 // GaugeCell which has a null implementation. 37 template <typename T> 38 class GaugeCell { 39 public: 40 public: GaugeCell()41 GaugeCell() {} ~GaugeCell()42 ~GaugeCell() {} 43 Set(const T & value)44 void Set(const T& value) {} value()45 T value() const { return T(); } 46 47 private: 48 TF_DISALLOW_COPY_AND_ASSIGN(GaugeCell); 49 }; 50 51 // Gauge which has a null implementation. 52 template <typename ValueType, int NumLabels> 53 class Gauge { 54 public: ~Gauge()55 ~Gauge() {} 56 57 template <typename... MetricDefArgs> New(MetricDefArgs &&...metric_def_args)58 static Gauge* New(MetricDefArgs&&... metric_def_args) { 59 static_assert(std::is_same<ValueType, int64>::value || 60 std::is_same<ValueType, string>::value || 61 std::is_same<ValueType, bool>::value, 62 "Gauge only allows bool, int64, and string types."); 63 return new Gauge(); 64 } 65 66 template <typename... Labels> GetCell(const Labels &...labels)67 GaugeCell<ValueType>* GetCell(const Labels&... labels) { 68 return &default_gauge_cell_; 69 } 70 GetStatus()71 Status GetStatus() { return Status::OK(); } 72 73 private: Gauge()74 Gauge() {} 75 76 GaugeCell<ValueType> default_gauge_cell_; 77 78 TF_DISALLOW_COPY_AND_ASSIGN(Gauge); 79 }; 80 81 } // namespace monitoring 82 } // namespace tensorflow 83 84 #endif // TENSORFLOW_CORE_LIB_MONITORING_MOBILE_GAUGE_H_ 85