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 counter implementation.
12
 * No-ops on all calls and requires no underlying metric or data.
13
 */
14
class NullCounterImpl : public MetricImpl<Counter> {
15
public:
16
  explicit NullCounterImpl(SymbolTable& symbol_table)
17
1836581
      : MetricImpl<Counter>(symbol_table), symbol_table_(symbol_table) {}
18
1836519
  ~NullCounterImpl() 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
35
  void add(uint64_t) override {}
27
32
  void inc() override {}
28
1
  uint64_t latch() override { return 0; }
29
1
  void reset() override {}
30
11
  uint64_t value() const override { return 0; }
31

            
32
  // Metric
33
1
  bool used() const override { return false; }
34
  void markUnused() override {}
35
  bool hidden() const override { return false; }
36
31
  SymbolTable& symbolTable() override { return symbol_table_; }
37

            
38
  // RefcountInterface
39
  void incRefCount() override { refcount_helper_.incRefCount(); }
40
  bool decRefCount() override { return refcount_helper_.decRefCount(); }
41
1
  uint32_t use_count() const override { return refcount_helper_.use_count(); }
42

            
43
private:
44
  RefcountHelper refcount_helper_;
45
  SymbolTable& symbol_table_;
46
};
47

            
48
} // namespace Stats
49
} // namespace Envoy