summaryrefslogtreecommitdiff
path: root/src/util/statistics_stats.cpp
blob: 971c592ac99aa6a2bc3b8eed0c68640fde2852d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/******************************************************************************
 * Top contributors (to current version):
 *   Gereon Kremer
 *
 * This file is part of the cvc5 project.
 *
 * Copyright (c) 2009-2021 by the authors listed in the file AUTHORS
 * in the top-level source directory and their institutional affiliations.
 * All rights reserved.  See the file COPYING in the top-level source
 * directory for licensing information.
 * ****************************************************************************
 *
 * Basic statistics representation.
 */

#include "util/statistics_stats.h"

#include "base/check.h"
#include "util/statistics_value.h"

namespace cvc5 {

AverageStat& AverageStat::operator<<(double v)
{
  if constexpr (Configuration::isStatisticsBuild())
  {
    d_data->d_sum += v;
    d_data->d_count++;
  }
  return *this;
}

IntStat& IntStat::operator=(int64_t val)
{
  if constexpr (Configuration::isStatisticsBuild())
  {
    d_data->d_value = val;
  }
  return *this;
}

IntStat& IntStat::operator++()
{
  if constexpr (Configuration::isStatisticsBuild())
  {
    d_data->d_value++;
  }
  return *this;
}

IntStat& IntStat::operator++(int)
{
  if constexpr (Configuration::isStatisticsBuild())
  {
    d_data->d_value++;
  }
  return *this;
}

IntStat& IntStat::operator+=(int64_t val)
{
  if constexpr (Configuration::isStatisticsBuild())
  {
    d_data->d_value += val;
  }
  return *this;
}

void IntStat::maxAssign(int64_t val)
{
  if (d_data->d_value < val)
  {
    d_data->d_value = val;
  }
}

void IntStat::minAssign(int64_t val)
{
  if (d_data->d_value > val)
  {
    d_data->d_value = val;
  }
}

void TimerStat::start()
{
  if constexpr (Configuration::isStatisticsBuild())
  {
    Assert(!d_data->d_running) << "timer is already running";
    d_data->d_start = StatisticTimerValue::clock::now();
    d_data->d_running = true;
  }
}
void TimerStat::stop()
{
  if constexpr (Configuration::isStatisticsBuild())
  {
    Assert(d_data->d_running) << "timer is not running";
    d_data->d_duration += StatisticTimerValue::clock::now() - d_data->d_start;
    d_data->d_running = false;
  }
}
bool TimerStat::running() const
{
  if constexpr (Configuration::isStatisticsBuild())
  {
    return d_data->d_running;
  }
  return false;
}

CodeTimer::CodeTimer(TimerStat& timer, bool allow_reentrant)
    : d_timer(timer), d_reentrant(false)
{
  if constexpr (Configuration::isStatisticsBuild())
  {
    if (!allow_reentrant || !(d_reentrant = d_timer.running()))
    {
      d_timer.start();
    }
  }
}
CodeTimer::~CodeTimer()
{
  if constexpr (Configuration::isStatisticsBuild())
  {
    if (!d_reentrant)
    {
      d_timer.stop();
    }
  }
}

}  // namespace cvc5
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback