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 #ifndef TENSORFLOW_C_EAGER_TFE_MONITORING_INTERNAL_H_ 16 #define TENSORFLOW_C_EAGER_TFE_MONITORING_INTERNAL_H_ 17 18 #include <functional> 19 #include <memory> 20 #include <string> 21 22 #include "absl/memory/memory.h" 23 #include "tensorflow/core/lib/monitoring/counter.h" 24 #include "tensorflow/core/lib/monitoring/gauge.h" 25 #include "tensorflow/core/lib/monitoring/sampler.h" 26 #include "tensorflow/core/platform/types.h" 27 28 struct TFE_MonitoringCounterCell { 29 tensorflow::monitoring::CounterCell cell; 30 }; 31 32 template <int NumLabels> 33 struct TFE_MonitoringCounter { 34 template <typename... LabelDesc> TFE_MonitoringCounterTFE_MonitoringCounter35 TFE_MonitoringCounter(const char* name, const char* description, 36 LabelDesc&&... label) { 37 counter = absl::WrapUnique(tensorflow::monitoring::Counter<NumLabels>::New( 38 name, description, label...)); 39 } 40 41 std::unique_ptr<tensorflow::monitoring::Counter<NumLabels>> counter; 42 }; 43 44 struct TFE_MonitoringCounter0 : TFE_MonitoringCounter<0> { 45 using TFE_MonitoringCounter::TFE_MonitoringCounter; 46 }; 47 struct TFE_MonitoringCounter1 : TFE_MonitoringCounter<1> { 48 using TFE_MonitoringCounter::TFE_MonitoringCounter; 49 }; 50 struct TFE_MonitoringCounter2 : TFE_MonitoringCounter<2> { 51 using TFE_MonitoringCounter::TFE_MonitoringCounter; 52 }; 53 54 struct TFE_MonitoringIntGaugeCell { 55 tensorflow::monitoring::GaugeCell<tensorflow::int64> cell; 56 }; 57 struct TFE_MonitoringStringGaugeCell { 58 tensorflow::monitoring::GaugeCell<tensorflow::string> cell; 59 }; 60 struct TFE_MonitoringBoolGaugeCell { 61 tensorflow::monitoring::GaugeCell<bool> cell; 62 }; 63 64 template <typename ValueType, int NumLabels> 65 struct TFE_MonitoringGauge { 66 template <typename... LabelDesc> TFE_MonitoringGaugeTFE_MonitoringGauge67 TFE_MonitoringGauge(const char* name, const char* description, 68 LabelDesc&&... label) { 69 gauge = absl::WrapUnique( 70 tensorflow::monitoring::Gauge<ValueType, NumLabels>::New( 71 name, description, label...)); 72 } 73 74 std::unique_ptr<tensorflow::monitoring::Gauge<ValueType, NumLabels>> gauge; 75 }; 76 77 struct TFE_MonitoringIntGauge0 : TFE_MonitoringGauge<tensorflow::int64, 0> { 78 using TFE_MonitoringGauge::TFE_MonitoringGauge; 79 }; 80 struct TFE_MonitoringIntGauge1 : TFE_MonitoringGauge<tensorflow::int64, 1> { 81 using TFE_MonitoringGauge::TFE_MonitoringGauge; 82 }; 83 struct TFE_MonitoringIntGauge2 : TFE_MonitoringGauge<tensorflow::int64, 2> { 84 using TFE_MonitoringGauge::TFE_MonitoringGauge; 85 }; 86 87 struct TFE_MonitoringStringGauge0 : TFE_MonitoringGauge<tensorflow::string, 0> { 88 using TFE_MonitoringGauge::TFE_MonitoringGauge; 89 }; 90 struct TFE_MonitoringStringGauge1 : TFE_MonitoringGauge<tensorflow::string, 1> { 91 using TFE_MonitoringGauge::TFE_MonitoringGauge; 92 }; 93 struct TFE_MonitoringStringGauge2 : TFE_MonitoringGauge<tensorflow::string, 2> { 94 using TFE_MonitoringGauge::TFE_MonitoringGauge; 95 }; 96 97 struct TFE_MonitoringBoolGauge0 : TFE_MonitoringGauge<bool, 0> { 98 using TFE_MonitoringGauge::TFE_MonitoringGauge; 99 }; 100 struct TFE_MonitoringBoolGauge1 : TFE_MonitoringGauge<bool, 1> { 101 using TFE_MonitoringGauge::TFE_MonitoringGauge; 102 }; 103 struct TFE_MonitoringBoolGauge2 : TFE_MonitoringGauge<bool, 2> { 104 using TFE_MonitoringGauge::TFE_MonitoringGauge; 105 }; 106 107 struct TFE_MonitoringBuckets { TFE_MonitoringBucketsTFE_MonitoringBuckets108 explicit TFE_MonitoringBuckets( 109 std::function<std::unique_ptr<tensorflow::monitoring::Buckets>(void)> 110 fn) { 111 create_buckets = fn; 112 } 113 114 std::function<std::unique_ptr<tensorflow::monitoring::Buckets>(void)> 115 create_buckets; 116 }; 117 118 struct TFE_MonitoringSamplerCell { 119 tensorflow::monitoring::SamplerCell cell; 120 }; 121 122 template <int NumLabels> 123 struct TFE_MonitoringSampler { 124 template <typename... LabelDesc> TFE_MonitoringSamplerTFE_MonitoringSampler125 TFE_MonitoringSampler( 126 const char* name, 127 std::unique_ptr<tensorflow::monitoring::Buckets> buckets, 128 const char* description, LabelDesc&&... label) { 129 sampler = absl::WrapUnique(tensorflow::monitoring::Sampler<NumLabels>::New( 130 {name, description, label...}, std::move(buckets))); 131 } 132 133 std::unique_ptr<tensorflow::monitoring::Sampler<NumLabels>> sampler; 134 }; 135 136 struct TFE_MonitoringSampler0 : TFE_MonitoringSampler<0> { 137 using TFE_MonitoringSampler::TFE_MonitoringSampler; 138 }; 139 struct TFE_MonitoringSampler1 : TFE_MonitoringSampler<1> { 140 using TFE_MonitoringSampler::TFE_MonitoringSampler; 141 }; 142 struct TFE_MonitoringSampler2 : TFE_MonitoringSampler<2> { 143 using TFE_MonitoringSampler::TFE_MonitoringSampler; 144 }; 145 146 #endif // TENSORFLOW_C_EAGER_TFE_MONITORING_INTERNAL_H_ 147