LCOV - code coverage report
Current view: top level - root/contrail/src/contrail-common/database - gendb_statistics.h (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 20 20 100.0 %
Date: 2026-08-03 02:19:58 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //
       2             : // Copyright (c) 2014 Juniper Networks, Inc. All rights reserved.
       3             : //
       4             : 
       5             : #ifndef GENDB_GENDB_STATISTICS_H__
       6             : #define GENDB_GENDB_STATISTICS_H__
       7             : 
       8             : #include <boost/ptr_container/ptr_map.hpp>
       9             : #include "gendb_types.h"
      10             : 
      11             : namespace GenDb {
      12             : 
      13             : class DbTableStatistics {
      14             :  public:
      15        3678 :     DbTableStatistics() {
      16        3678 :     }
      17             :     void Update(const std::string &table_name, bool write, bool fail,
      18             :         bool back_pressure, uint64_t num);
      19             :     void GetDiffs(std::vector<GenDb::DbTableInfo> *vdbti);
      20             :     void GetCumulative(std::vector<GenDb::DbTableInfo> *vdbti) const;
      21             : 
      22             :  private:
      23             :     struct TableStats {
      24         359 :         TableStats() :
      25         359 :             num_reads_(0),
      26         359 :             num_read_fails_(0),
      27         359 :             num_writes_(0),
      28         359 :             num_write_fails_(0),
      29         359 :             num_write_back_pressure_fails_(0) {
      30         359 :         }
      31             :         void Update(bool write, bool fail, bool back_pressure, uint64_t num);
      32             :         void Get(const std::string &table_name,
      33             :             GenDb::DbTableInfo *dbti) const;
      34             : 
      35             :         uint64_t num_reads_;
      36             :         uint64_t num_read_fails_;
      37             :         uint64_t num_writes_;
      38             :         uint64_t num_write_fails_;
      39             :         uint64_t num_write_back_pressure_fails_;
      40             :     };
      41             : 
      42             :     typedef boost::ptr_map<const std::string, TableStats> TableStatsMap;
      43             :     TableStatsMap table_stats_map_;
      44             :     // cumulative stats for introspect purpose
      45             :     TableStatsMap table_stats_cumulative_map_;
      46             :     void GetInternal(std::vector<GenDb::DbTableInfo> *vdbti,
      47             :         bool cumulative) const;
      48             : };
      49             : 
      50             : class IfErrors {
      51             :  public:
      52        7460 :     IfErrors() :
      53        7460 :         write_tablespace_fails_(0),
      54        7460 :         read_tablespace_fails_(0),
      55        7460 :         write_column_family_fails_(0),
      56        7460 :         read_column_family_fails_(0),
      57        7460 :         write_column_fails_(0),
      58        7460 :         write_batch_column_fails_(0),
      59        7460 :         read_column_fails_(0) {
      60        7460 :     }
      61             :     enum Type {
      62             :         ERR_NO_ERROR,
      63             :         ERR_WRITE_TABLESPACE,
      64             :         ERR_READ_TABLESPACE,
      65             :         ERR_WRITE_COLUMN_FAMILY,
      66             :         ERR_READ_COLUMN_FAMILY,
      67             :         ERR_WRITE_COLUMN,
      68             :         ERR_WRITE_BATCH_COLUMN,
      69             :         ERR_READ_COLUMN,
      70             :     };
      71             :     void GetDiffs(GenDb::DbErrors *dbe);
      72             :     void GetCumulative(GenDb::DbErrors *dbe) const;
      73             :     void Clear();
      74             :     void Increment(Type type);
      75             : 
      76             :  private:
      77             :     uint64_t write_tablespace_fails_;
      78             :     uint64_t read_tablespace_fails_;
      79             :     uint64_t write_column_family_fails_;
      80             :     uint64_t read_column_family_fails_;
      81             :     uint64_t write_column_fails_;
      82             :     uint64_t write_batch_column_fails_;
      83             :     uint64_t read_column_fails_;
      84             :     void GetInternal(GenDb::DbErrors *dbe) const;
      85             : };
      86             : 
      87             : class GenDbIfStats {
      88             :  public:
      89        3730 :     GenDbIfStats() {
      90        3730 :     }
      91             :     enum TableOp {
      92             :         TABLE_OP_NONE,
      93             :         TABLE_OP_WRITE,
      94             :         TABLE_OP_WRITE_FAIL,
      95             :         TABLE_OP_WRITE_BACK_PRESSURE_FAIL,
      96             :         TABLE_OP_READ,
      97             :         TABLE_OP_READ_FAIL,
      98             :     };
      99             :     void IncrementErrors(IfErrors::Type type);
     100             :     void IncrementTableStats(TableOp op, const std::string &table_name);
     101             :     void IncrementTableWrite(const std::string &table_name);
     102             :     void IncrementTableWrite(const std::string &table_name, uint64_t num_writes);
     103             :     void IncrementTableWriteFail(const std::string &table_name);
     104             :     void IncrementTableWriteBackPressureFail(const std::string &table_name);
     105             :     void IncrementTableWriteFail(const std::string &table_name, uint64_t num_writes);
     106             :     void IncrementTableRead(const std::string &table_name);
     107             :     void IncrementTableRead(const std::string &table_name, uint64_t num_reads);
     108             :     void IncrementTableReadFail(const std::string &table_name);
     109             :     void IncrementTableReadFail(const std::string &table_name, uint64_t num_reads);
     110             :     void IncrementTableReadBackPressureFail(const std::string &table_name);
     111             :     void GetDiffs(std::vector<GenDb::DbTableInfo> *vdbti, GenDb::DbErrors *dbe);
     112             :     void GetCumulative(std::vector<GenDb::DbTableInfo> *vdbti,
     113             :         GenDb::DbErrors *dbe) const;
     114             : 
     115             :  private:
     116             :     void IncrementTableStatsInternal(const std::string &table_name, bool write,
     117             :         bool fail, bool back_pressure, uint64_t num);
     118             : 
     119             :     GenDb::DbTableStatistics table_stats_;
     120             :     IfErrors errors_;
     121             :     IfErrors cumulative_errors_;
     122             : };
     123             : 
     124             : }  // namespace GenDb
     125             : 
     126             : #endif  // GENDB_GENDB_STATISTICS_H__

Generated by: LCOV version 1.14