Home | History | Annotate | Download | only in monitoring
      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 #include <memory>
     22 
     23 #include "tensorflow/core/framework/summary.pb.h"
     24 #include "tensorflow/core/lib/monitoring/metric_def.h"
     25 #include "tensorflow/core/platform/macros.h"
     26 #include "tensorflow/core/platform/types.h"
     27 
     28 namespace tensorflow {
     29 namespace monitoring {
     30 
     31 // SamplerCell which has a null implementation.
     32 class SamplerCell {
     33  public:
     34   SamplerCell() {}
     35   ~SamplerCell() {}
     36 
     37   void Add(double value) {}
     38   HistogramProto value() const { return HistogramProto(); }
     39 
     40  private:
     41   TF_DISALLOW_COPY_AND_ASSIGN(SamplerCell);
     42 };
     43 
     44 // Buckets which has a null implementation.
     45 class Buckets {
     46  public:
     47   Buckets() = default;
     48   ~Buckets() = default;
     49 
     50   static std::unique_ptr<Buckets> Explicit(
     51       std::initializer_list<double> bucket_limits) {
     52     return std::unique_ptr<Buckets>(new Buckets());
     53   }
     54 
     55   static std::unique_ptr<Buckets> Exponential(double scale,
     56                                               double growth_factor,
     57                                               int bucket_count) {
     58     return std::unique_ptr<Buckets>(new Buckets());
     59   }
     60 
     61   const std::vector<double>& explicit_bounds() const {
     62     return explicit_bounds_;
     63   }
     64 
     65  private:
     66   std::vector<double> explicit_bounds_;
     67 
     68   TF_DISALLOW_COPY_AND_ASSIGN(Buckets);
     69 };
     70 
     71 // Sampler which has a null implementation.
     72 template <int NumLabels>
     73 class Sampler {
     74  public:
     75   ~Sampler() {}
     76 
     77   template <typename... MetricDefArgs>
     78   static Sampler* New(const MetricDef<MetricKind::kCumulative, HistogramProto,
     79                                       NumLabels>& metric_def,
     80                       std::unique_ptr<Buckets> buckets) {
     81     return new Sampler<NumLabels>(std::move(buckets));
     82   }
     83 
     84   template <typename... Labels>
     85   SamplerCell* GetCell(const Labels&... labels) {
     86     return &default_sampler_cell_;
     87   }
     88 
     89  private:
     90   Sampler(std::unique_ptr<Buckets> buckets) : buckets_(std::move(buckets)) {}
     91 
     92   SamplerCell default_sampler_cell_;
     93   std::unique_ptr<Buckets> buckets_;
     94 
     95   TF_DISALLOW_COPY_AND_ASSIGN(Sampler);
     96 };
     97 
     98 }  // namespace monitoring
     99 }  // namespace tensorflow
    100 
    101 #endif  // TENSORFLOW_CORE_LIB_MONITORING_MOBILE_SAMPLER_H_
    102