LCOV - code coverage report
Current view: top level - buildbot/coverage/build/src/util - statistics_stats.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 50 50 100.0 %
Date: 2026-04-17 10:42:04 Functions: 13 13 100.0 %
Branches: 20 28 71.4 %

           Branch data     Line data    Source code
       1                 :            : /******************************************************************************
       2                 :            :  * This file is part of the cvc5 project.
       3                 :            :  *
       4                 :            :  * Copyright (c) 2009-2026 by the authors listed in the file AUTHORS
       5                 :            :  * in the top-level source directory and their institutional affiliations.
       6                 :            :  * All rights reserved.  See the file COPYING in the top-level source
       7                 :            :  * directory for licensing information.
       8                 :            :  * ****************************************************************************
       9                 :            :  *
      10                 :            :  * Basic statistics representation.
      11                 :            :  */
      12                 :            : 
      13                 :            : #include "util/statistics_stats.h"
      14                 :            : 
      15                 :            : #include "base/check.h"
      16                 :            : #include "util/statistics_value.h"
      17                 :            : 
      18                 :            : namespace cvc5::internal {
      19                 :            : 
      20                 :    3423439 : AverageStat& AverageStat::operator<<(double v)
      21                 :            : {
      22                 :            :   if constexpr (configuration::isStatisticsBuild())
      23                 :            :   {
      24                 :    3423439 :     d_data->d_sum += v;
      25                 :    3423439 :     d_data->d_count++;
      26                 :            :   }
      27                 :    3423439 :   return *this;
      28                 :            : }
      29                 :            : 
      30                 :      50387 : IntStat& IntStat::operator=(int64_t val)
      31                 :            : {
      32                 :            :   if constexpr (configuration::isStatisticsBuild())
      33                 :            :   {
      34                 :      50387 :     d_data->d_value = val;
      35                 :            :   }
      36                 :      50387 :   return *this;
      37                 :            : }
      38                 :            : 
      39                 :  331367954 : IntStat& IntStat::operator++()
      40                 :            : {
      41                 :            :   if constexpr (configuration::isStatisticsBuild())
      42                 :            :   {
      43                 :  331367954 :     d_data->d_value++;
      44                 :            :   }
      45                 :  331367954 :   return *this;
      46                 :            : }
      47                 :            : 
      48                 :   12512933 : IntStat& IntStat::operator++(int)
      49                 :            : {
      50                 :            :   if constexpr (configuration::isStatisticsBuild())
      51                 :            :   {
      52                 :   12512933 :     d_data->d_value++;
      53                 :            :   }
      54                 :   12512933 :   return *this;
      55                 :            : }
      56                 :            : 
      57                 :      91793 : IntStat& IntStat::operator+=(int64_t val)
      58                 :            : {
      59                 :            :   if constexpr (configuration::isStatisticsBuild())
      60                 :            :   {
      61                 :      91793 :     d_data->d_value += val;
      62                 :            :   }
      63                 :      91793 :   return *this;
      64                 :            : }
      65                 :            : 
      66                 :    5517566 : void IntStat::maxAssign(int64_t val)
      67                 :            : {
      68                 :            :   if constexpr (configuration::isStatisticsBuild())
      69                 :            :   {
      70         [ +  + ]:    5517566 :     if (d_data->d_value < val)
      71                 :            :     {
      72                 :     628330 :       d_data->d_value = val;
      73                 :            :     }
      74                 :            :   }
      75                 :    5517566 : }
      76                 :            : 
      77                 :       2882 : void IntStat::minAssign(int64_t val)
      78                 :            : {
      79                 :            :   if constexpr (configuration::isStatisticsBuild())
      80                 :            :   {
      81         [ +  + ]:       2882 :     if (d_data->d_value > val)
      82                 :            :     {
      83                 :        469 :       d_data->d_value = val;
      84                 :            :     }
      85                 :            :   }
      86                 :       2882 : }
      87                 :            : 
      88                 :   38133317 : void TimerStat::start()
      89                 :            : {
      90                 :            :   if constexpr (configuration::isStatisticsBuild())
      91                 :            :   {
      92 [ -  + ][ -  + ]:   38133317 :     Assert(!d_data->d_running) << "timer is already running";
                 [ -  - ]
      93                 :   38133317 :     d_data->d_start = StatisticTimerValue::clock::now();
      94                 :   38133317 :     d_data->d_running = true;
      95                 :            :   }
      96                 :   38133317 : }
      97                 :   38057633 : void TimerStat::stop()
      98                 :            : {
      99                 :            :   if constexpr (configuration::isStatisticsBuild())
     100                 :            :   {
     101 [ -  + ][ -  + ]:   38057633 :     Assert(d_data->d_running) << "timer is not running";
                 [ -  - ]
     102                 :   38057633 :     d_data->d_duration += StatisticTimerValue::clock::now() - d_data->d_start;
     103                 :   38057633 :     d_data->d_running = false;
     104                 :            :   }
     105                 :   38057633 : }
     106                 :    9399722 : bool TimerStat::running() const
     107                 :            : {
     108                 :            :   if constexpr (configuration::isStatisticsBuild())
     109                 :            :   {
     110                 :    9399722 :     return d_data->d_running;
     111                 :            :   }
     112                 :            :   return false;
     113                 :            : }
     114                 :            : 
     115                 :   38112191 : CodeTimer::CodeTimer(TimerStat& timer, bool allow_reentrant)
     116                 :   38112191 :     : CodeTimer(&timer, allow_reentrant)
     117                 :            : {
     118                 :   38112191 : }
     119                 :            : 
     120                 :   38118430 : CodeTimer::CodeTimer(TimerStat* timer, bool allow_reentrant)
     121                 :   38118430 :     : d_timer(timer), d_reentrant(false)
     122                 :            : {
     123                 :            :   if constexpr (configuration::isStatisticsBuild())
     124                 :            :   {
     125         [ +  + ]:   38118430 :     if (d_timer)
     126                 :            :     {
     127 [ +  + ][ +  + ]:   38116839 :       if (!allow_reentrant || !(d_reentrant = d_timer->running()))
                 [ +  + ]
     128                 :            :       {
     129                 :   38057633 :         d_timer->start();
     130                 :            :       }
     131                 :            :     }
     132                 :            :   }
     133                 :   38118430 : }
     134                 :   38118430 : CodeTimer::~CodeTimer()
     135                 :            : {
     136                 :            :   if constexpr (configuration::isStatisticsBuild())
     137                 :            :   {
     138         [ +  + ]:   38118430 :     if (d_timer)
     139                 :            :     {
     140         [ +  + ]:   38116839 :       if (!d_reentrant)
     141                 :            :       {
     142                 :   38057633 :         d_timer->stop();
     143                 :            :       }
     144                 :            :     }
     145                 :            :   }
     146                 :   38118430 : }
     147                 :            : 
     148                 :            : }  // namespace cvc5::internal

Generated by: LCOV version 1.14