1 /********************* */
2 /*! \file statistics.cpp
4 ** Top contributors (to current version):
5 ** Morgan Deters, Andres Noetzli, Tim King
6 ** This file is part of the CVC4 project.
7 ** Copyright (c) 2009-2019 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.\endverbatim
12 ** \brief [[ Add one-line brief description here ]]
14 ** [[ Add lengthier description here ]]
15 ** \todo document this file
18 #include "util/statistics.h"
22 #include "util/safe_print.h"
23 #include "util/statistics_registry.h" // for details about class Stat
28 std::string
StatisticsBase::s_regDelim("::");
30 bool StatisticsBase::StatCmp::operator()(const Stat
* s1
, const Stat
* s2
) const {
31 return s1
->getName() < s2
->getName();
34 StatisticsBase::iterator::value_type
StatisticsBase::iterator::operator*() const {
35 return std::make_pair((*d_it
)->getName(), (*d_it
)->getValue());
38 StatisticsBase::StatisticsBase() :
43 StatisticsBase::StatisticsBase(const StatisticsBase
& stats
) :
44 d_prefix(stats
.d_prefix
),
48 StatisticsBase
& StatisticsBase::operator=(const StatisticsBase
& stats
) {
49 d_prefix
= stats
.d_prefix
;
53 void Statistics::copyFrom(const StatisticsBase
& stats
) {
54 // This is ugly, but otherwise we have to introduce a "friend" relation for
55 // Base to its derived class (really obnoxious).
56 const StatisticsBase::const_iterator i_begin
= stats
.begin();
57 const StatisticsBase::const_iterator i_end
= stats
.end();
58 for(StatisticsBase::const_iterator i
= i_begin
; i
!= i_end
; ++i
) {
59 SExprStat
* p
= new SExprStat((*i
).first
, (*i
).second
);
64 void Statistics::clear() {
65 for(StatSet::iterator i
= d_stats
.begin(); i
!= d_stats
.end(); ++i
) {
71 Statistics::Statistics(const StatisticsBase
& stats
) :
72 StatisticsBase(stats
) {
76 Statistics::Statistics(const Statistics
& stats
) :
77 StatisticsBase(stats
) {
81 Statistics::~Statistics() {
85 Statistics
& Statistics::operator=(const StatisticsBase
& stats
) {
87 this->StatisticsBase::operator=(stats
);
93 Statistics
& Statistics::operator=(const Statistics
& stats
) {
94 return this->operator=((const StatisticsBase
&)stats
);
97 StatisticsBase::const_iterator
StatisticsBase::begin() const {
98 return iterator(d_stats
.begin());
101 StatisticsBase::const_iterator
StatisticsBase::end() const {
102 return iterator(d_stats
.end());
105 void StatisticsBase::flushInformation(std::ostream
&out
) const {
106 #ifdef CVC4_STATISTICS_ON
107 for(StatSet::iterator i
= d_stats
.begin();
112 out
<< d_prefix
<< s_regDelim
;
117 #endif /* CVC4_STATISTICS_ON */
120 void StatisticsBase::safeFlushInformation(int fd
) const {
121 #ifdef CVC4_STATISTICS_ON
122 for (StatSet::iterator i
= d_stats
.begin(); i
!= d_stats
.end(); ++i
) {
124 if (d_prefix
.size() != 0) {
125 safe_print(fd
, d_prefix
);
126 safe_print(fd
, s_regDelim
);
128 s
->safeFlushStat(fd
);
129 safe_print(fd
, "\n");
131 #endif /* CVC4_STATISTICS_ON */
134 SExpr
StatisticsBase::getStatistic(std::string name
) const {
137 StatSet::iterator i
= d_stats
.find(&s
);
138 if(i
!= d_stats
.end()) {
139 return (*i
)->getValue();
145 void StatisticsBase::setPrefix(const std::string
& prefix
) {
149 }/* CVC4 namespace */