GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/util/statistics_stats.cpp Lines: 45 45 100.0 %
Date: 2021-08-06 Branches: 17 50 34.0 %

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