1
#pragma once
2

            
3
#include "envoy/stats/stats.h"
4

            
5
#include "source/common/stats/metric_impl.h"
6

            
7
namespace Envoy {
8
namespace Stats {
9

            
10
/**
11
 * Null gauge implementation.
12
 * No-ops on all calls and requires no underlying metric or data.
13
 */
14
class NullGaugeImpl : public MetricImpl<Gauge> {
15
public:
16
  explicit NullGaugeImpl(SymbolTable& symbol_table)
17
1836581
      : MetricImpl<Gauge>(symbol_table), symbol_table_(symbol_table) {}
18
1836519
  ~NullGaugeImpl() override {
19
    // MetricImpl must be explicitly cleared() before destruction, otherwise it
20
    // will not be able to access the SymbolTable& to free the symbols. An RAII
21
    // alternative would be to store the SymbolTable reference in the
22
    // MetricImpl, costing 8 bytes per stat.
23
1836519
    MetricImpl::clear(symbol_table_);
24
1836519
  }
25

            
26
2
  void add(uint64_t) override {}
27
12
  void inc() override {}
28
7
  void dec() override {}
29
450538
  void set(uint64_t) override {}
30
  void setParentValue(uint64_t) override {}
31
2
  void sub(uint64_t) override {}
32
12
  uint64_t value() const override { return 0; }
33
2
  ImportMode importMode() const override { return ImportMode::NeverImport; }
34
165
  void mergeImportMode(ImportMode /* import_mode */) override {}
35

            
36
  // Metric
37
1
  bool used() const override { return false; }
38
  void markUnused() override {}
39
  bool hidden() const override { return false; }
40
30
  SymbolTable& symbolTable() override { return symbol_table_; }
41

            
42
  // RefcountInterface
43
  void incRefCount() override { refcount_helper_.incRefCount(); }
44
  bool decRefCount() override { return refcount_helper_.decRefCount(); }
45
1
  uint32_t use_count() const override { return refcount_helper_.use_count(); }
46

            
47
private:
48
  RefcountHelper refcount_helper_;
49
  SymbolTable& symbol_table_;
50
};
51

            
52
} // namespace Stats
53
} // namespace Envoy