GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/util/statistics.cpp Lines: 12 70 17.1 %
Date: 2021-03-23 Branches: 3 62 4.8 %

Line Exec Source
1
/*********************                                                        */
2
/*! \file statistics.cpp
3
 ** \verbatim
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-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.\endverbatim
11
 **
12
 ** \brief [[ Add one-line brief description here ]]
13
 **
14
 ** [[ Add lengthier description here ]]
15
 ** \todo document this file
16
 **/
17
18
#include "util/statistics.h"
19
20
#include "util/safe_print.h"
21
#include "util/statistics_registry.h" // for details about class Stat
22
23
24
namespace CVC4 {
25
26
159328566
bool StatisticsBase::StatCmp::operator()(const Stat* s1, const Stat* s2) const {
27
159328566
  return s1->getName() < s2->getName();
28
}
29
30
76
StatisticsBase::iterator::value_type StatisticsBase::iterator::operator*() const {
31
76
  return std::make_pair((*d_it)->getName(), (*d_it)->getValue());
32
}
33
34
9622
StatisticsBase::StatisticsBase() :
35
9622
  d_stats() {
36
9622
}
37
38
StatisticsBase::StatisticsBase(const StatisticsBase& stats) :
39
  d_stats() {
40
}
41
42
StatisticsBase& StatisticsBase::operator=(const StatisticsBase& stats) {
43
  return *this;
44
}
45
46
void Statistics::copyFrom(const StatisticsBase& stats) {
47
  // This is ugly, but otherwise we have to introduce a "friend" relation for
48
  // Base to its derived class (really obnoxious).
49
  const StatisticsBase::const_iterator i_begin = stats.begin();
50
  const StatisticsBase::const_iterator i_end = stats.end();
51
  for(StatisticsBase::const_iterator i = i_begin; i != i_end; ++i) {
52
    SExprStat* p = new SExprStat((*i).first, (*i).second);
53
    d_stats.insert(p);
54
  }
55
}
56
57
void Statistics::clear() {
58
  for(StatSet::iterator i = d_stats.begin(); i != d_stats.end(); ++i) {
59
    delete *i;
60
  }
61
  d_stats.clear();
62
}
63
64
Statistics::Statistics(const StatisticsBase& stats) :
65
  StatisticsBase(stats) {
66
  copyFrom(stats);
67
}
68
69
Statistics::Statistics(const Statistics& stats) :
70
  StatisticsBase(stats) {
71
  copyFrom(stats);
72
}
73
74
Statistics::~Statistics() {
75
  clear();
76
}
77
78
Statistics& Statistics::operator=(const StatisticsBase& stats) {
79
  clear();
80
  this->StatisticsBase::operator=(stats);
81
  copyFrom(stats);
82
83
  return *this;
84
}
85
86
Statistics& Statistics::operator=(const Statistics& stats) {
87
  return this->operator=((const StatisticsBase&)stats);
88
}
89
90
1
StatisticsBase::const_iterator StatisticsBase::begin() const {
91
1
  return iterator(d_stats.begin());
92
}
93
94
39
StatisticsBase::const_iterator StatisticsBase::end() const {
95
39
  return iterator(d_stats.end());
96
}
97
98
void StatisticsBase::flushInformation(std::ostream &out) const {
99
#ifdef CVC4_STATISTICS_ON
100
  for(StatSet::iterator i = d_stats.begin();
101
      i != d_stats.end();
102
      ++i) {
103
    Stat* s = *i;
104
    out << s->getName() << ", ";
105
    s->flushInformation(out);
106
    out << std::endl;
107
  }
108
#endif /* CVC4_STATISTICS_ON */
109
}
110
111
void StatisticsBase::safeFlushInformation(int fd) const {
112
#ifdef CVC4_STATISTICS_ON
113
  for (StatSet::iterator i = d_stats.begin(); i != d_stats.end(); ++i) {
114
    Stat* s = *i;
115
    safe_print(fd, s->getName());
116
    safe_print(fd, ", ");
117
    s->safeFlushInformation(fd);
118
    safe_print(fd, "\n");
119
  }
120
#endif /* CVC4_STATISTICS_ON */
121
}
122
123
SExpr StatisticsBase::getStatistic(std::string name) const {
124
  SExpr value;
125
  IntStat s(name, 0);
126
  StatSet::iterator i = d_stats.find(&s);
127
  if(i != d_stats.end()) {
128
    return (*i)->getValue();
129
  } else {
130
    return SExpr();
131
  }
132
}
133
134
26685
}/* CVC4 namespace */