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

Generated by: LCOV version 1.14