summaryrefslogtreecommitdiff
path: root/src/util/statistics_reg.cpp
blob: efb564c740267445687a94196874e7f5b24b7fd0 (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
135
136
137
138
139
140
141
142
143
/*********************                                                        */
/*! \file statistics_reg.cpp
 ** \verbatim
 ** Top contributors (to current version):
 **   Gereon Kremer
 ** This file is part of the CVC4 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.\endverbatim
 **
 ** \brief Central statistics registry.
 **
 ** The StatisticsRegistry that issues statistic proxy objects.
 **/

#include "util/statistics_reg.h"

#include "options/base_options.h"
#include "util/statistics_public.h"

namespace cvc5 {

StatisticsRegistry::StatisticsRegistry(bool registerPublic)
{
  if (registerPublic)
  {
    registerPublicStatistics(*this);
  }
}

AverageStat StatisticsRegistry::registerAverage(const std::string& name,
                                                bool expert)
{
  return registerStat<AverageStat>(name, expert);
}
IntStat StatisticsRegistry::registerInt(const std::string& name, bool expert)
{
  return registerStat<IntStat>(name, expert);
}
TimerStat StatisticsRegistry::registerTimer(const std::string& name,
                                            bool expert)
{
  return registerStat<TimerStat>(name, expert);
}

void StatisticsRegistry::storeSnapshot()
{
  if constexpr (Configuration::isStatisticsBuild())
  {
    d_lastSnapshot = std::make_unique<Snapshot>();
    for (const auto& s : d_stats)
    {
      if (!options::statisticsExpert() && s.second->d_expert) continue;
      if (!options::statisticsUnset() && !s.second->hasValue()) continue;
      d_lastSnapshot->emplace(
          s.first,
          s.second->hasValue() ? s.second->getViewer() : StatExportData{});
    }
  }
}

StatisticBaseValue* StatisticsRegistry::get(const std::string& name) const
{
  if constexpr (Configuration::isStatisticsBuild())
  {
    auto it = d_stats.find(name);
    if (it == d_stats.end()) return nullptr;
    return it->second.get();
  }
  return nullptr;
}

void StatisticsRegistry::print(std::ostream& os) const
{
  if constexpr (Configuration::isStatisticsBuild())
  {
    for (const auto& s : d_stats)
    {
      if (!options::statisticsExpert() && s.second->d_expert) continue;
      if (!options::statisticsUnset() && !s.second->hasValue()) continue;
      os << s.first << " = " << *s.second << std::endl;
    }
  }
}

void StatisticsRegistry::printSafe(int fd) const
{
  if constexpr (Configuration::isStatisticsBuild())
  {
    for (const auto& s : d_stats)
    {
      if (!options::statisticsExpert() && s.second->d_expert) continue;
      if (!options::statisticsUnset() && !s.second->hasValue()) continue;

      safe_print(fd, s.first);
      safe_print(fd, " = ");
      if (s.second->hasValue())
        s.second->printSafe(fd);
      else
        safe_print(fd, "<unset>");
      safe_print(fd, '\n');
    }
  }
}
void StatisticsRegistry::printDiff(std::ostream& os) const
{
  if constexpr (Configuration::isStatisticsBuild())
  {
    if (!d_lastSnapshot)
    {
      // we have no snapshot, print as usual
      print(os);
      return;
    }
    for (const auto& s : d_stats)
    {
      if (!options::statisticsExpert() && s.second->d_expert) continue;
      if (!options::statisticsUnset() && !s.second->hasValue()) continue;
      auto oldit = d_lastSnapshot->find(s.first);
      if (oldit == d_lastSnapshot->end())
      {
        // not present in the snapshot
        os << s.first << " = " << *s.second << " (was <unset>)" << std::endl;
      }
      else if (oldit->second != s.second->getViewer())
      {
        // present in the snapshow, print old value
        os << s.first << " = " << *s.second << " (was ";
        detail::print(os, oldit->second);
        os << ")" << std::endl;
      }
    }
  }
}

std::ostream& operator<<(std::ostream& os, const StatisticsRegistry& sr)
{
  sr.print(os);
  return os;
}

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