GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/util/stats_base.cpp Lines: 29 36 80.6 %
Date: 2021-03-23 Branches: 8 26 30.8 %

Line Exec Source
1
/*********************                                                        */
2
/*! \file stats_base.cpp
3
 ** \verbatim
4
 ** Top contributors (to current version):
5
 **   Gereon Kremer
6
 ** This file is part of the CVC4 project.
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.\endverbatim
11
 **
12
 ** \brief Base statistic classes
13
 **
14
 ** Base statistic classes
15
 **/
16
17
#include "util/stats_base.h"
18
19
#include "util/statistics_registry.h"
20
21
namespace CVC4 {
22
23
4810218
Stat::Stat(const std::string& name) : d_name(name)
24
{
25
  if (CVC4_USE_STATISTICS)
26
  {
27
4810218
    CheckArgument(d_name.find(", ") == std::string::npos,
28
                  name,
29
                  "Statistics names cannot include a comma (',')");
30
  }
31
4810218
}
32
33
3066943
IntStat::IntStat(const std::string& name, int64_t init)
34
3066943
    : BackedStat<int64_t>(name, init)
35
{
36
3066943
}
37
38
/** Increment the underlying integer statistic. */
39
297364997
IntStat& IntStat::operator++()
40
{
41
  if (CVC4_USE_STATISTICS)
42
  {
43
297364997
    ++d_data;
44
  }
45
297364997
  return *this;
46
}
47
/** Increment the underlying integer statistic. */
48
IntStat& IntStat::operator++(int)
49
{
50
  if (CVC4_USE_STATISTICS)
51
  {
52
    ++d_data;
53
  }
54
  return *this;
55
}
56
57
/** Increment the underlying integer statistic by the given amount. */
58
1284
IntStat& IntStat::operator+=(int64_t val)
59
{
60
  if (CVC4_USE_STATISTICS)
61
  {
62
1284
    d_data += val;
63
  }
64
1284
  return *this;
65
}
66
67
/** Keep the maximum of the current statistic value and the given one. */
68
13866
void IntStat::maxAssign(int64_t val)
69
{
70
  if (CVC4_USE_STATISTICS)
71
  {
72
13866
    if (d_data < val)
73
    {
74
181
      d_data = val;
75
    }
76
  }
77
13866
}
78
79
/** Keep the minimum of the current statistic value and the given one. */
80
6612
void IntStat::minAssign(int64_t val)
81
{
82
  if (CVC4_USE_STATISTICS)
83
  {
84
6612
    if (d_data > val)
85
    {
86
563
      d_data = val;
87
    }
88
  }
89
6612
}
90
91
46801
AverageStat::AverageStat(const std::string& name)
92
46801
    : BackedStat<double>(name, 0.0)
93
{
94
46801
}
95
96
/** Add an entry to the running-average calculation. */
97
1841639
AverageStat& AverageStat::operator<<(double e)
98
{
99
  if (CVC4_USE_STATISTICS)
100
  {
101
1841639
    ++d_count;
102
1841639
    d_sum += e;
103
1841639
    set(d_sum / d_count);
104
  }
105
1841639
  return *this;
106
}
107
108
SExpr AverageStat::getValue() const
109
{
110
  std::stringstream ss;
111
  ss << std::fixed << std::setprecision(8) << d_data;
112
  return SExpr(Rational::fromDecimal(ss.str()));
113
}
114
115
26685
}  // namespace CVC4