• 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 Sampler metric for mobile platforms.
17 
18 #ifndef TENSORFLOW_CORE_LIB_MONITORING_MOBILE_SAMPLER_H_
19 #define TENSORFLOW_CORE_LIB_MONITORING_MOBILE_SAMPLER_H_
20 
21 #if !defined(IS_MOBILE_PLATFORM) || !defined(TENSORFLOW_INCLUDED_FROM_SAMPLER_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_sampler.h directly; use sampler.h to include it instead
26 #endif  // !defined(IS_MOBILE_PLATFORM) ||
27         // !defined(TENSORFLOW_INCLUDED_FROM_SAMPLER_H)
28 
29 #include <memory>
30 
31 #include "tensorflow/core/framework/summary.pb.h"
32 #include "tensorflow/core/lib/core/status.h"
33 #include "tensorflow/core/lib/monitoring/metric_def.h"
34 #include "tensorflow/core/platform/macros.h"
35 #include "tensorflow/core/platform/types.h"
36 
37 namespace tensorflow {
38 namespace monitoring {
39 
40 // SamplerCell which has a null implementation.
41 class SamplerCell {
42  public:
SamplerCell()43   SamplerCell() {}
~SamplerCell()44   ~SamplerCell() {}
45 
Add(double value)46   void Add(double value) {}
value()47   HistogramProto value() const { return HistogramProto(); }
48 
49  private:
50   TF_DISALLOW_COPY_AND_ASSIGN(SamplerCell);
51 };
52 
53 // Buckets which has a null implementation.
54 class Buckets {
55  public:
56   Buckets() = default;
57   ~Buckets() = default;
58 
Explicit(std::initializer_list<double> bucket_limits)59   static std::unique_ptr<Buckets> Explicit(
60       std::initializer_list<double> bucket_limits) {
61     return std::unique_ptr<Buckets>(new Buckets());
62   }
63 
Exponential(double scale,double growth_factor,int bucket_count)64   static std::unique_ptr<Buckets> Exponential(double scale,
65                                               double growth_factor,
66                                               int bucket_count) {
67     return std::unique_ptr<Buckets>(new Buckets());
68   }
69 
explicit_bounds()70   const std::vector<double>& explicit_bounds() const {
71     return explicit_bounds_;
72   }
73 
74  private:
75   std::vector<double> explicit_bounds_;
76 
77   TF_DISALLOW_COPY_AND_ASSIGN(Buckets);
78 };
79 
80 // Sampler which has a null implementation.
81 template <int NumLabels>
82 class Sampler {
83  public:
~Sampler()84   ~Sampler() {}
85 
86   template <typename... MetricDefArgs>
New(const MetricDef<MetricKind::kCumulative,HistogramProto,NumLabels> & metric_def,std::unique_ptr<Buckets> buckets)87   static Sampler* New(const MetricDef<MetricKind::kCumulative, HistogramProto,
88                                       NumLabels>& metric_def,
89                       std::unique_ptr<Buckets> buckets) {
90     return new Sampler<NumLabels>(std::move(buckets));
91   }
92 
93   template <typename... Labels>
GetCell(const Labels &...labels)94   SamplerCell* GetCell(const Labels&... labels) {
95     return &default_sampler_cell_;
96   }
97 
GetStatus()98   Status GetStatus() { return Status::OK(); }
99 
100  private:
Sampler(std::unique_ptr<Buckets> buckets)101   Sampler(std::unique_ptr<Buckets> buckets) : buckets_(std::move(buckets)) {}
102 
103   SamplerCell default_sampler_cell_;
104   std::unique_ptr<Buckets> buckets_;
105 
106   TF_DISALLOW_COPY_AND_ASSIGN(Sampler);
107 };
108 
109 }  // namespace monitoring
110 }  // namespace tensorflow
111 
112 #endif  // TENSORFLOW_CORE_LIB_MONITORING_MOBILE_SAMPLER_H_
113