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 |
13198 |
StatisticsRegistry::StatisticsRegistry(bool registerPublic) |
26 |
|
{ |
27 |
13198 |
if (registerPublic) |
28 |
|
{ |
29 |
13196 |
registerPublicStatistics(*this); |
30 |
|
} |
31 |
13198 |
} |
32 |
|
|
33 |
39712 |
AverageStat StatisticsRegistry::registerAverage(const std::string& name, |
34 |
|
bool expert) |
35 |
|
{ |
36 |
39712 |
return registerStat<AverageStat>(name, expert); |
37 |
|
} |
38 |
3079865 |
IntStat StatisticsRegistry::registerInt(const std::string& name, bool expert) |
39 |
|
{ |
40 |
3079865 |
return registerStat<IntStat>(name, expert); |
41 |
|
} |
42 |
1130561 |
TimerStat StatisticsRegistry::registerTimer(const std::string& name, |
43 |
|
bool expert) |
44 |
|
{ |
45 |
1130561 |
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 |
29505 |
} // namespace cvc5 |