LCOV - code coverage report
Current view: top level - source/common/stats - isolated_store_impl.cc (source / functions) Hit Total Coverage
Test: coverage.dat Lines: 45 48 93.8 %
Date: 2024-01-05 06:35:25 Functions: 13 14 92.9 %

          Line data    Source code
       1             : #include "source/common/stats/isolated_store_impl.h"
       2             : 
       3             : #include <algorithm>
       4             : #include <cstring>
       5             : #include <string>
       6             : 
       7             : #include "source/common/common/utility.h"
       8             : #include "source/common/stats/histogram_impl.h"
       9             : #include "source/common/stats/utility.h"
      10             : 
      11             : namespace Envoy {
      12             : namespace Stats {
      13             : 
      14        2582 : IsolatedStoreImpl::IsolatedStoreImpl() : IsolatedStoreImpl(std::make_unique<SymbolTableImpl>()) {}
      15             : 
      16             : IsolatedStoreImpl::IsolatedStoreImpl(std::unique_ptr<SymbolTable>&& symbol_table)
      17        2582 :     : IsolatedStoreImpl(*symbol_table) {
      18        2582 :   symbol_table_storage_ = std::move(symbol_table);
      19        2582 : }
      20             : 
      21      301506 : static StatNameTagVector tagVectorFromOpt(StatNameTagVectorOptConstRef tags) {
      22      301506 :   return tags ? tags->get() : StatNameTagVector{};
      23      301506 : }
      24             : 
      25             : IsolatedStoreImpl::IsolatedStoreImpl(SymbolTable& symbol_table)
      26             :     : alloc_(symbol_table),
      27             :       counters_([this](const TagUtility::TagStatNameJoiner& joiner,
      28      222662 :                        StatNameTagVectorOptConstRef tags) -> CounterSharedPtr {
      29      222662 :         return alloc_.makeCounter(joiner.nameWithTags(), joiner.tagExtractedName(),
      30      222662 :                                   tagVectorFromOpt(tags));
      31      222662 :       }),
      32             :       gauges_([this](const TagUtility::TagStatNameJoiner& joiner, StatNameTagVectorOptConstRef tags,
      33       59920 :                      Gauge::ImportMode import_mode) -> GaugeSharedPtr {
      34       59920 :         return alloc_.makeGauge(joiner.nameWithTags(), joiner.tagExtractedName(),
      35       59920 :                                 tagVectorFromOpt(tags), import_mode);
      36       59920 :       }),
      37             :       histograms_([this](const TagUtility::TagStatNameJoiner& joiner,
      38             :                          StatNameTagVectorOptConstRef tags,
      39       18922 :                          Histogram::Unit unit) -> HistogramSharedPtr {
      40       18922 :         return {new HistogramImpl(joiner.nameWithTags(), unit, *this, joiner.tagExtractedName(),
      41       18922 :                                   tagVectorFromOpt(tags))};
      42       18922 :       }),
      43             :       text_readouts_([this](const TagUtility::TagStatNameJoiner& joiner,
      44             :                             StatNameTagVectorOptConstRef tags,
      45           2 :                             TextReadout::Type) -> TextReadoutSharedPtr {
      46           2 :         return alloc_.makeTextReadout(joiner.nameWithTags(), joiner.tagExtractedName(),
      47           2 :                                       tagVectorFromOpt(tags));
      48           2 :       }),
      49             :       null_counter_(new NullCounterImpl(symbol_table)),
      50       21325 :       null_gauge_(new NullGaugeImpl(symbol_table)) {}
      51             : 
      52       57430 : ScopeSharedPtr IsolatedStoreImpl::rootScope() {
      53       57430 :   if (lazy_default_scope_ == nullptr) {
      54       19586 :     StatNameManagedStorage name_storage("", symbolTable());
      55       19586 :     lazy_default_scope_ = makeScope(name_storage.statName());
      56       19586 :   }
      57       57430 :   return lazy_default_scope_;
      58       57430 : }
      59             : 
      60           0 : ConstScopeSharedPtr IsolatedStoreImpl::constRootScope() const {
      61           0 :   return const_cast<IsolatedStoreImpl*>(this)->rootScope();
      62           0 : }
      63             : 
      64       21325 : IsolatedStoreImpl::~IsolatedStoreImpl() = default;
      65             : 
      66        3950 : ScopeSharedPtr IsolatedScopeImpl::createScope(const std::string& name) {
      67        3950 :   StatNameManagedStorage stat_name_storage(Utility::sanitizeStatsName(name), symbolTable());
      68        3950 :   return scopeFromStatName(stat_name_storage.statName());
      69        3950 : }
      70             : 
      71        5127 : ScopeSharedPtr IsolatedScopeImpl::scopeFromStatName(StatName name) {
      72        5127 :   SymbolTable::StoragePtr prefix_name_storage = symbolTable().join({prefix(), name});
      73        5127 :   ScopeSharedPtr scope = store_.makeScope(StatName(prefix_name_storage.get()));
      74        5127 :   addScopeToStore(scope);
      75        5127 :   return scope;
      76        5127 : }
      77             : 
      78        5301 : ScopeSharedPtr IsolatedStoreImpl::makeScope(StatName name) {
      79        5301 :   return std::make_shared<IsolatedScopeImpl>(name, *this);
      80        5301 : }
      81             : 
      82             : } // namespace Stats
      83             : } // namespace Envoy

Generated by: LCOV version 1.15