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