1/* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2
3Licensed under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License.
5You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9Unless required by applicable law or agreed to in writing, software
10distributed under the License is distributed on an "AS IS" BASIS,
11WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12See the License for the specific language governing permissions and
13limitations 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
28struct TFE_MonitoringCounterCell {
29 tensorflow::monitoring::CounterCell cell;
30};
31
32template <int NumLabels>
33struct TFE_MonitoringCounter {
34 template <typename... LabelDesc>
35 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
44struct TFE_MonitoringCounter0 : TFE_MonitoringCounter<0> {
45 using TFE_MonitoringCounter::TFE_MonitoringCounter;
46};
47struct TFE_MonitoringCounter1 : TFE_MonitoringCounter<1> {
48 using TFE_MonitoringCounter::TFE_MonitoringCounter;
49};
50struct TFE_MonitoringCounter2 : TFE_MonitoringCounter<2> {
51 using TFE_MonitoringCounter::TFE_MonitoringCounter;
52};
53
54struct TFE_MonitoringIntGaugeCell {
55 tensorflow::monitoring::GaugeCell<int64_t> cell;
56};
57struct TFE_MonitoringStringGaugeCell {
58 tensorflow::monitoring::GaugeCell<tensorflow::string> cell;
59};
60struct TFE_MonitoringBoolGaugeCell {
61 tensorflow::monitoring::GaugeCell<bool> cell;
62};
63
64template <typename ValueType, int NumLabels>
65struct TFE_MonitoringGauge {
66 template <typename... LabelDesc>
67 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
77struct TFE_MonitoringIntGauge0 : TFE_MonitoringGauge<int64_t, 0> {
78 using TFE_MonitoringGauge::TFE_MonitoringGauge;
79};
80struct TFE_MonitoringIntGauge1 : TFE_MonitoringGauge<int64_t, 1> {
81 using TFE_MonitoringGauge::TFE_MonitoringGauge;
82};
83struct TFE_MonitoringIntGauge2 : TFE_MonitoringGauge<int64_t, 2> {
84 using TFE_MonitoringGauge::TFE_MonitoringGauge;
85};
86
87struct TFE_MonitoringStringGauge0 : TFE_MonitoringGauge<tensorflow::string, 0> {
88 using TFE_MonitoringGauge::TFE_MonitoringGauge;
89};
90struct TFE_MonitoringStringGauge1 : TFE_MonitoringGauge<tensorflow::string, 1> {
91 using TFE_MonitoringGauge::TFE_MonitoringGauge;
92};
93struct TFE_MonitoringStringGauge2 : TFE_MonitoringGauge<tensorflow::string, 2> {
94 using TFE_MonitoringGauge::TFE_MonitoringGauge;
95};
96struct TFE_MonitoringStringGauge3 : TFE_MonitoringGauge<tensorflow::string, 3> {
97 using TFE_MonitoringGauge::TFE_MonitoringGauge;
98};
99struct TFE_MonitoringStringGauge4 : TFE_MonitoringGauge<tensorflow::string, 4> {
100 using TFE_MonitoringGauge::TFE_MonitoringGauge;
101};
102
103struct TFE_MonitoringBoolGauge0 : TFE_MonitoringGauge<bool, 0> {
104 using TFE_MonitoringGauge::TFE_MonitoringGauge;
105};
106struct TFE_MonitoringBoolGauge1 : TFE_MonitoringGauge<bool, 1> {
107 using TFE_MonitoringGauge::TFE_MonitoringGauge;
108};
109struct TFE_MonitoringBoolGauge2 : TFE_MonitoringGauge<bool, 2> {
110 using TFE_MonitoringGauge::TFE_MonitoringGauge;
111};
112
113struct TFE_MonitoringBuckets {
114 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
124struct TFE_MonitoringSamplerCell {
125 tensorflow::monitoring::SamplerCell cell;
126};
127
128template <int NumLabels>
129struct TFE_MonitoringSampler {
130 template <typename... LabelDesc>
131 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
142struct TFE_MonitoringSampler0 : TFE_MonitoringSampler<0> {
143 using TFE_MonitoringSampler::TFE_MonitoringSampler;
144};
145struct TFE_MonitoringSampler1 : TFE_MonitoringSampler<1> {
146 using TFE_MonitoringSampler::TFE_MonitoringSampler;
147};
148struct TFE_MonitoringSampler2 : TFE_MonitoringSampler<2> {
149 using TFE_MonitoringSampler::TFE_MonitoringSampler;
150};
151
152#endif // TENSORFLOW_C_EAGER_TFE_MONITORING_INTERNAL_H_
153