• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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<int64_t> 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<int64_t, 0> {
78   using TFE_MonitoringGauge::TFE_MonitoringGauge;
79 };
80 struct TFE_MonitoringIntGauge1 : TFE_MonitoringGauge<int64_t, 1> {
81   using TFE_MonitoringGauge::TFE_MonitoringGauge;
82 };
83 struct TFE_MonitoringIntGauge2 : TFE_MonitoringGauge<int64_t, 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 struct TFE_MonitoringStringGauge3 : TFE_MonitoringGauge<tensorflow::string, 3> {
97   using TFE_MonitoringGauge::TFE_MonitoringGauge;
98 };
99 struct TFE_MonitoringStringGauge4 : TFE_MonitoringGauge<tensorflow::string, 4> {
100   using TFE_MonitoringGauge::TFE_MonitoringGauge;
101 };
102 
103 struct TFE_MonitoringBoolGauge0 : TFE_MonitoringGauge<bool, 0> {
104   using TFE_MonitoringGauge::TFE_MonitoringGauge;
105 };
106 struct TFE_MonitoringBoolGauge1 : TFE_MonitoringGauge<bool, 1> {
107   using TFE_MonitoringGauge::TFE_MonitoringGauge;
108 };
109 struct TFE_MonitoringBoolGauge2 : TFE_MonitoringGauge<bool, 2> {
110   using TFE_MonitoringGauge::TFE_MonitoringGauge;
111 };
112 
113 struct TFE_MonitoringBuckets {
TFE_MonitoringBucketsTFE_MonitoringBuckets114   explicit TFE_MonitoringBuckets(
115       std::function<std::unique_ptr<tensorflow::monitoring::Buckets>(void)>
116           fn) {
117     create_buckets = fn;
118   }
119 
120   std::function<std::unique_ptr<tensorflow::monitoring::Buckets>(void)>
121       create_buckets;
122 };
123 
124 struct TFE_MonitoringSamplerCell {
125   tensorflow::monitoring::SamplerCell cell;
126 };
127 
128 template <int NumLabels>
129 struct TFE_MonitoringSampler {
130   template <typename... LabelDesc>
TFE_MonitoringSamplerTFE_MonitoringSampler131   TFE_MonitoringSampler(
132       const char* name,
133       std::unique_ptr<tensorflow::monitoring::Buckets> buckets,
134       const char* description, LabelDesc&&... label) {
135     sampler = absl::WrapUnique(tensorflow::monitoring::Sampler<NumLabels>::New(
136         {name, description, label...}, std::move(buckets)));
137   }
138 
139   std::unique_ptr<tensorflow::monitoring::Sampler<NumLabels>> sampler;
140 };
141 
142 struct TFE_MonitoringSampler0 : TFE_MonitoringSampler<0> {
143   using TFE_MonitoringSampler::TFE_MonitoringSampler;
144 };
145 struct TFE_MonitoringSampler1 : TFE_MonitoringSampler<1> {
146   using TFE_MonitoringSampler::TFE_MonitoringSampler;
147 };
148 struct TFE_MonitoringSampler2 : TFE_MonitoringSampler<2> {
149   using TFE_MonitoringSampler::TFE_MonitoringSampler;
150 };
151 
152 #endif  // TENSORFLOW_C_EAGER_TFE_MONITORING_INTERNAL_H_
153