GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/util/statistics_registry.cpp Lines: 16 62 25.8 %
Date: 2021-09-15 Branches: 7 178 3.9 %

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
 * Central statistics registry.
14
 *
15
 * The StatisticsRegistry that issues statistic proxy objects.
16
 */
17
18
#include "util/statistics_registry.h"
19
20
#include "options/base_options.h"
21
#include "util/statistics_public.h"
22
23
namespace cvc5 {
24
25
13225
StatisticsRegistry::StatisticsRegistry(Env& env, bool registerPublic)
26
13225
    : EnvObj(env)
27
{
28
13225
  if (registerPublic)
29
  {
30
13223
    registerPublicStatistics(*this);
31
  }
32
13225
}
33
34
39774
AverageStat StatisticsRegistry::registerAverage(const std::string& name,
35
                                                bool expert)
36
{
37
39774
  return registerStat<AverageStat>(name, expert);
38
}
39
3084492
IntStat StatisticsRegistry::registerInt(const std::string& name, bool expert)
40
{
41
3084492
  return registerStat<IntStat>(name, expert);
42
}
43
1132387
TimerStat StatisticsRegistry::registerTimer(const std::string& name,
44
                                            bool expert)
45
{
46
1132387
  return registerStat<TimerStat>(name, expert);
47
}
48
49
void StatisticsRegistry::storeSnapshot()
50
{
51
  if constexpr (Configuration::isStatisticsBuild())
52
  {
53
    d_lastSnapshot = std::make_unique<Snapshot>();
54
    for (const auto& s : d_stats)
55
    {
56
      if (!options().base.statisticsExpert && s.second->d_expert) continue;
57
      if (!options().base.statisticsAll && s.second->isDefault()) continue;
58
      d_lastSnapshot->emplace(
59
          s.first,
60
          s.second->getViewer());
61
    }
62
  }
63
}
64
65
20
StatisticBaseValue* StatisticsRegistry::get(const std::string& name) const
66
{
67
  if constexpr (Configuration::isStatisticsBuild())
68
  {
69
20
    auto it = d_stats.find(name);
70
20
    if (it == d_stats.end()) return nullptr;
71
20
    return it->second.get();
72
  }
73
  return nullptr;
74
}
75
76
void StatisticsRegistry::print(std::ostream& os) const
77
{
78
  if constexpr (Configuration::isStatisticsBuild())
79
  {
80
    for (const auto& s : d_stats)
81
    {
82
      if (!options().base.statisticsExpert && s.second->d_expert) continue;
83
      if (!options().base.statisticsAll && s.second->isDefault()) continue;
84
      os << s.first << " = " << *s.second << std::endl;
85
    }
86
  }
87
}
88
89
void StatisticsRegistry::printSafe(int fd) const
90
{
91
  if constexpr (Configuration::isStatisticsBuild())
92
  {
93
    for (const auto& s : d_stats)
94
    {
95
      if (!options().base.statisticsExpert && s.second->d_expert) continue;
96
      if (!options().base.statisticsAll && s.second->isDefault()) continue;
97
98
      safe_print(fd, s.first);
99
      safe_print(fd, " = ");
100
      s.second->printSafe(fd);
101
      safe_print(fd, "\n");
102
    }
103
  }
104
}
105
void StatisticsRegistry::printDiff(std::ostream& os) const
106
{
107
  if constexpr (Configuration::isStatisticsBuild())
108
  {
109
    if (!d_lastSnapshot)
110
    {
111
      // we have no snapshot, print as usual
112
      print(os);
113
      return;
114
    }
115
    for (const auto& s : d_stats)
116
    {
117
      if (!options().base.statisticsExpert && s.second->d_expert) continue;
118
      if (!options().base.statisticsAll && s.second->isDefault())
119
      {
120
        auto oldit = d_lastSnapshot->find(s.first);
121
        if (oldit != d_lastSnapshot->end() && oldit->second != s.second->getViewer())
122
        {
123
          // present in the snapshot, now defaulted
124
          os << s.first << " = " << *s.second << " (was ";
125
          detail::print(os, oldit->second);
126
          os << ")" << std::endl;
127
        }
128
      }
129
      else
130
      {
131
        auto oldit = d_lastSnapshot->find(s.first);
132
        if (oldit == d_lastSnapshot->end())
133
        {
134
          // not present in the snapshot
135
          os << s.first << " = " << *s.second << " (was <default>)"
136
             << std::endl;
137
        }
138
        else if (oldit->second != s.second->getViewer())
139
        {
140
          // present in the snapshot, print old value
141
          os << s.first << " = " << *s.second << " (was ";
142
          detail::print(os, oldit->second);
143
          os << ")" << std::endl;
144
        }
145
      }
146
    }
147
  }
148
}
149
150
std::ostream& operator<<(std::ostream& os, const StatisticsRegistry& sr)
151
{
152
  sr.print(os);
153
  return os;
154
}
155
156
29577
}  // namespace cvc5