LCOV - code coverage report
Current view: top level - source/common/stats - null_counter.h (source / functions) Hit Total Coverage
Test: coverage.dat Lines: 6 19 31.6 %
Date: 2024-01-05 06:35:25 Functions: 4 13 30.8 %

          Line data    Source code
       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       21423 :       : MetricImpl<Counter>(symbol_table), symbol_table_(symbol_table) {}
      18       21423 :   ~NullCounterImpl() override {
      19           0 :     // MetricImpl must be explicitly cleared() before destruction, otherwise it
      20           0 :     // will not be able to access the SymbolTable& to free the symbols. An RAII
      21           0 :     // alternative would be to store the SymbolTable reference in the
      22           0 :     // MetricImpl, costing 8 bytes per stat.
      23       21423 :     MetricImpl::clear(symbol_table_);
      24       21423 :   }
      25             : 
      26           0 :   void add(uint64_t) override {}
      27           0 :   void inc() override {}
      28           0 :   uint64_t latch() override { return 0; }
      29           0 :   void reset() override {}
      30           0 :   uint64_t value() const override { return 0; }
      31             : 
      32             :   // Metric
      33           0 :   bool used() const override { return false; }
      34           0 :   bool hidden() const override { return false; }
      35           0 :   SymbolTable& symbolTable() override { return symbol_table_; }
      36             : 
      37             :   // RefcountInterface
      38       21325 :   void incRefCount() override { refcount_helper_.incRefCount(); }
      39       21325 :   bool decRefCount() override { return refcount_helper_.decRefCount(); }
      40           0 :   uint32_t use_count() const override { return refcount_helper_.use_count(); }
      41             : 
      42             : private:
      43             :   RefcountHelper refcount_helper_;
      44             :   SymbolTable& symbol_table_;
      45             : };
      46             : 
      47             : } // namespace Stats
      48             : } // namespace Envoy

Generated by: LCOV version 1.15