GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/util/statistics_stats.cpp Lines: 45 45 100.0 %
Date: 2021-05-24 Branches: 14 50 28.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
1334861
AverageStat& AverageStat::operator<<(double v)
24
{
25
  if constexpr (Configuration::isStatisticsBuild())
26
  {
27
1334861
    d_data->d_sum += v;
28
1334861
    d_data->d_count++;
29
  }
30
1334861
  return *this;
31
}
32
33
14308
IntStat& IntStat::operator=(int64_t val)
34
{
35
  if constexpr (Configuration::isStatisticsBuild())
36
  {
37
14308
    d_data->d_value = val;
38
  }
39
14308
  return *this;
40
}
41
42
165933519
IntStat& IntStat::operator++()
43
{
44
  if constexpr (Configuration::isStatisticsBuild())
45
  {
46
165933519
    d_data->d_value++;
47
  }
48
165933519
  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
4785
IntStat& IntStat::operator+=(int64_t val)
61
{
62
  if constexpr (Configuration::isStatisticsBuild())
63
  {
64
4785
    d_data->d_value += val;
65
  }
66
4785
  return *this;
67
}
68
69
10920
void IntStat::maxAssign(int64_t val)
70
{
71
  if constexpr (Configuration::isStatisticsBuild())
72
  {
73
10920
    if (d_data->d_value < val)
74
    {
75
468
      d_data->d_value = val;
76
    }
77
  }
78
10920
}
79
80
13061
void IntStat::minAssign(int64_t val)
81
{
82
  if constexpr (Configuration::isStatisticsBuild())
83
  {
84
13061
    if (d_data->d_value > val)
85
    {
86
1682
      d_data->d_value = val;
87
    }
88
  }
89
13061
}
90
91
11050708
void TimerStat::start()
92
{
93
  if constexpr (Configuration::isStatisticsBuild())
94
  {
95
11050708
    Assert(!d_data->d_running) << "timer is already running";
96
11050708
    d_data->d_start = StatisticTimerValue::clock::now();
97
11050708
    d_data->d_running = true;
98
  }
99
11050708
}
100
11050708
void TimerStat::stop()
101
{
102
  if constexpr (Configuration::isStatisticsBuild())
103
  {
104
11050708
    Assert(d_data->d_running) << "timer is not running";
105
11050708
    d_data->d_duration += StatisticTimerValue::clock::now() - d_data->d_start;
106
11050708
    d_data->d_running = false;
107
  }
108
11050708
}
109
749108
bool TimerStat::running() const
110
{
111
  if constexpr (Configuration::isStatisticsBuild())
112
  {
113
749108
    return d_data->d_running;
114
  }
115
  return false;
116
}
117
118
11050708
CodeTimer::CodeTimer(TimerStat& timer, bool allow_reentrant)
119
11050708
    : d_timer(timer), d_reentrant(false)
120
{
121
  if constexpr (Configuration::isStatisticsBuild())
122
  {
123
11050708
    if (!allow_reentrant || !(d_reentrant = d_timer.running()))
124
    {
125
11050708
      d_timer.start();
126
    }
127
  }
128
11050708
}
129
22101416
CodeTimer::~CodeTimer()
130
{
131
  if constexpr (Configuration::isStatisticsBuild())
132
  {
133
11050708
    if (!d_reentrant)
134
    {
135
11050708
      d_timer.stop();
136
    }
137
  }
138
11050708
}
139
140
}  // namespace cvc5