klee
Statistics.h
Go to the documentation of this file.
1//===-- Statistics.h --------------------------------------------*- C++ -*-===//
2//
3// The KLEE Symbolic Virtual Machine
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef KLEE_STATISTICS_H
11#define KLEE_STATISTICS_H
12
13#include "Statistic.h"
14
15#include <vector>
16#include <string>
17#include <string.h>
18
19namespace klee {
20 class Statistic;
22 friend class StatisticManager;
23
24 private:
25 uint64_t *data;
26
27 public:
30 ~StatisticRecord() { delete[] data; }
31
32 void zero();
33
34 uint64_t getValue(const Statistic &s) const;
35 void incrementValue(const Statistic &s, uint64_t addend) const;
38 };
39
41 private:
42 bool enabled;
43 std::vector<Statistic*> stats;
44 uint64_t *globalStats;
45 uint64_t *indexedStats;
47 unsigned index;
48
49 public:
52
53 void useIndexedStats(unsigned totalIndices);
54
56 void setContext(StatisticRecord *sr); /* null to reset */
57
58 void setIndex(unsigned i) { index = i; }
59 unsigned getIndex() { return index; }
60 unsigned getNumStatistics() { return stats.size(); }
61 Statistic &getStatistic(unsigned i) { return *stats[i]; }
62
64 void incrementStatistic(Statistic &s, uint64_t addend);
65 uint64_t getValue(const Statistic &s) const;
66 void incrementIndexedValue(const Statistic &s, unsigned index,
67 uint64_t addend) const;
68 uint64_t getIndexedValue(const Statistic &s, unsigned index) const;
69 void setIndexedValue(const Statistic &s, unsigned index, uint64_t value);
70 int getStatisticID(const std::string &name) const;
71 Statistic *getStatisticByName(const std::string &name) const;
72 };
73
74 extern StatisticManager *theStatisticManager;
75
77 uint64_t addend) {
78 if (enabled) {
79 globalStats[s.id] += addend;
80 if (indexedStats) {
81 indexedStats[index*stats.size() + s.id] += addend;
82 if (contextStats)
83 contextStats->data[s.id] += addend;
84 }
85 }
86 }
87
89 return contextStats;
90 }
92 contextStats = sr;
93 }
94
95 inline void StatisticRecord::zero() {
96 ::memset(data, 0, sizeof(*data)*theStatisticManager->getNumStatistics());
97 }
98
100 : data(new uint64_t[theStatisticManager->getNumStatistics()]) {
101 zero();
102 }
103
105 : data(new uint64_t[theStatisticManager->getNumStatistics()]) {
106 ::memcpy(data, s.data,
108 }
109
111 ::memcpy(data, s.data,
113 return *this;
114 }
115
117 uint64_t addend) const {
118 data[s.id] += addend;
119 }
120 inline uint64_t StatisticRecord::getValue(const Statistic &s) const {
121 return data[s.id];
122 }
123
124 inline StatisticRecord &
126 unsigned nStats = theStatisticManager->getNumStatistics();
127 for (unsigned i=0; i<nStats; i++)
128 data[i] += sr.data[i];
129 return *this;
130 }
131
132 inline uint64_t StatisticManager::getValue(const Statistic &s) const {
133 return globalStats[s.id];
134 }
135
137 unsigned index,
138 uint64_t addend) const {
139 indexedStats[index*stats.size() + s.id] += addend;
140 }
141
143 unsigned index) const {
144 return indexedStats[index*stats.size() + s.id];
145 }
146
148 unsigned index,
149 uint64_t value) {
150 indexedStats[index*stats.size() + s.id] = value;
151 }
152}
153
154#endif /* KLEE_STATISTICS_H */
StatisticRecord * contextStats
Definition: Statistics.h:46
std::vector< Statistic * > stats
Definition: Statistics.h:43
void setIndexedValue(const Statistic &s, unsigned index, uint64_t value)
Definition: Statistics.h:147
Statistic & getStatistic(unsigned i)
Definition: Statistics.h:61
int getStatisticID(const std::string &name) const
Definition: Statistics.cpp:43
uint64_t * indexedStats
Definition: Statistics.h:45
uint64_t * globalStats
Definition: Statistics.h:44
void setIndex(unsigned i)
Definition: Statistics.h:58
void incrementStatistic(Statistic &s, uint64_t addend)
Definition: Statistics.h:76
Statistic * getStatisticByName(const std::string &name) const
Definition: Statistics.cpp:50
void useIndexedStats(unsigned totalIndices)
Definition: Statistics.cpp:29
uint64_t getIndexedValue(const Statistic &s, unsigned index) const
Definition: Statistics.h:142
void registerStatistic(Statistic &s)
Definition: Statistics.cpp:35
uint64_t getValue(const Statistic &s) const
Definition: Statistics.h:132
void incrementIndexedValue(const Statistic &s, unsigned index, uint64_t addend) const
Definition: Statistics.h:136
void setContext(StatisticRecord *sr)
Definition: Statistics.h:91
unsigned getNumStatistics()
Definition: Statistics.h:60
StatisticRecord * getContext()
Definition: Statistics.h:88
StatisticRecord & operator=(const StatisticRecord &s)
Definition: Statistics.h:110
StatisticRecord & operator+=(const StatisticRecord &sr)
Definition: Statistics.h:125
uint64_t getValue(const Statistic &s) const
Definition: Statistics.h:120
void incrementValue(const Statistic &s, uint64_t addend) const
Definition: Statistics.h:116
std::uint32_t id
Definition: Statistic.h:31
Definition: main.cpp:291
StatisticManager * theStatisticManager
Definition: Statistics.cpp:57