• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2019 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 PercentileSampler metric for mobile platforms.
17 
18 #ifndef TENSORFLOW_CORE_LIB_MONITORING_MOBILE_PERCENTILE_SAMPLER_H_
19 #define TENSORFLOW_CORE_LIB_MONITORING_MOBILE_PERCENTILE_SAMPLER_H_
20 
21 #if !defined(IS_MOBILE_PLATFORM) || \
22     !defined(TENSORFLOW_INCLUDED_FROM_PERCENTILE_SAMPLER_H)
23 // If this header file were included directly, and something else included its
24 // non-mobile counterpart, there could be an unchecked ODR violation on the
25 // classes below.
26 #error do not include mobile_percentile_sampler.h directly; use percetile_sampler.h instead
27 #endif  // !defined(IS_MOBILE_PLATFORM) ||
28         // !defined(TENSORFLOW_INCLUDED_FROM_PERCENTILE_SAMPLER_H)
29 
30 #include "tensorflow/core/lib/core/status.h"
31 #include "tensorflow/core/lib/monitoring/collection_registry.h"
32 #include "tensorflow/core/lib/monitoring/metric_def.h"
33 #include "tensorflow/core/lib/monitoring/types.h"
34 #include "tensorflow/core/platform/macros.h"
35 
36 namespace tensorflow {
37 namespace monitoring {
38 
39 class PercentileSamplerCell {
40  public:
Add(double sample)41   void Add(double sample) {}
42 
value()43   Percentiles value() const { return Percentiles(); }
44 };
45 
46 template <int NumLabels>
47 class PercentileSampler {
48  public:
49   static PercentileSampler* New(
50       const MetricDef<MetricKind::kCumulative, Percentiles, NumLabels>&
51           metric_def,
52       std::vector<double> percentiles, size_t max_samples,
53       UnitOfMeasure unit_of_measure);
54 
55   template <typename... Labels>
GetCell(const Labels &...labels)56   PercentileSamplerCell* GetCell(const Labels&... labels) {
57     return &default_cell_;
58   }
59 
GetStatus()60   Status GetStatus() { return Status::OK(); }
61 
62  private:
63   PercentileSamplerCell default_cell_;
64 
65   PercentileSampler() = default;
66 
67   TF_DISALLOW_COPY_AND_ASSIGN(PercentileSampler);
68 };
69 
70 template <int NumLabels>
New(const MetricDef<MetricKind::kCumulative,Percentiles,NumLabels> &,std::vector<double>,size_t,UnitOfMeasure)71 PercentileSampler<NumLabels>* PercentileSampler<NumLabels>::New(
72     const MetricDef<MetricKind::kCumulative, Percentiles, NumLabels>&
73     /* metric_def */,
74     std::vector<double> /* percentiles */, size_t /* max_samples */,
75     UnitOfMeasure /* unit_of_measure */) {
76   return new PercentileSampler<NumLabels>();
77 }
78 
79 }  // namespace monitoring
80 }  // namespace tensorflow
81 
82 #endif  // TENSORFLOW_CORE_LIB_MONITORING_MOBILE_PERCENTILE_SAMPLER_H_
83