base: Move Stats::Info functions to its own source file
[gem5.git] / src / base / stats / info.hh
1 /*
2 * Copyright (c) 2003-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #ifndef __BASE_STATS_INFO_HH__
30 #define __BASE_STATS_INFO_HH__
31
32 #include "base/stats/types.hh"
33 #include "base/flags.hh"
34
35 namespace Stats {
36
37 class Group;
38
39 typedef uint16_t FlagsType;
40 typedef ::Flags<FlagsType> Flags;
41
42 /** Nothing extra to print. */
43 const FlagsType none = 0x0000;
44 /** This Stat is Initialized */
45 const FlagsType init = 0x0001;
46 /** Print this stat. */
47 const FlagsType display = 0x0002;
48 /** Print the total. */
49 const FlagsType total = 0x0010;
50 /** Print the percent of the total that this entry represents. */
51 const FlagsType pdf = 0x0020;
52 /** Print the cumulative percentage of total upto this entry. */
53 const FlagsType cdf = 0x0040;
54 /** Print the distribution. */
55 const FlagsType dist = 0x0080;
56 /** Don't print if this is zero. */
57 const FlagsType nozero = 0x0100;
58 /** Don't print if this is NAN */
59 const FlagsType nonan = 0x0200;
60 /** Print all values on a single line. Useful only for histograms. */
61 const FlagsType oneline = 0x0400;
62
63 /** Mask of flags that can't be set directly */
64 const FlagsType __reserved = init | display;
65
66 struct StorageParams;
67 struct Output;
68
69 class Info
70 {
71 public:
72 /** The name of the stat. */
73 std::string name;
74 /** The separator string used for vectors, dist, etc. */
75 static std::string separatorString;
76 /** The description of the stat. */
77 std::string desc;
78 /** The formatting flags. */
79 Flags flags;
80 /** The display precision. */
81 int precision;
82 /** A pointer to a prerequisite Stat. */
83 const Info *prereq;
84 /**
85 * A unique stat ID for each stat in the simulator.
86 * Can be used externally for lookups as well as for debugging.
87 */
88 static int id_count;
89 int id;
90
91 public:
92 const StorageParams *storageParams;
93
94 public:
95 Info();
96 virtual ~Info();
97
98 /** Set the name of this statistic */
99 void setName(const std::string &name);
100 void setName(const Group *parent, const std::string &name);
101 void setSeparator(std::string _sep) { separatorString = _sep;}
102
103 /**
104 * Check that this stat has been set up properly and is ready for
105 * use
106 * @return true for success
107 */
108 virtual bool check() const = 0;
109 bool baseCheck() const;
110
111 /**
112 * Enable the stat for use
113 */
114 virtual void enable();
115
116 /**
117 * Prepare the stat for dumping.
118 */
119 virtual void prepare() = 0;
120
121 /**
122 * Reset the stat to the default state.
123 */
124 virtual void reset() = 0;
125
126 /**
127 * @return true if this stat has a value and satisfies its
128 * requirement as a prereq
129 */
130 virtual bool zero() const = 0;
131
132 /**
133 * Visitor entry for outputing statistics data
134 */
135 virtual void visit(Output &visitor) = 0;
136
137 /**
138 * Checks if the first stat's name is alphabetically less than the second.
139 * This function breaks names up at periods and considers each subname
140 * separately.
141 * @param stat1 The first stat.
142 * @param stat2 The second stat.
143 * @return stat1's name is alphabetically before stat2's
144 */
145 static bool less(Info *stat1, Info *stat2);
146 };
147
148 class ScalarInfo : public Info
149 {
150 public:
151 virtual Counter value() const = 0;
152 virtual Result result() const = 0;
153 virtual Result total() const = 0;
154 };
155
156 class VectorInfo : public Info
157 {
158 public:
159 /** Names and descriptions of subfields. */
160 std::vector<std::string> subnames;
161 std::vector<std::string> subdescs;
162
163 public:
164 void enable();
165
166 public:
167 virtual size_type size() const = 0;
168 virtual const VCounter &value() const = 0;
169 virtual const VResult &result() const = 0;
170 virtual Result total() const = 0;
171 };
172
173 enum DistType { Deviation, Dist, Hist };
174
175 struct DistData
176 {
177 DistType type;
178 Counter min;
179 Counter max;
180 Counter bucket_size;
181
182 Counter min_val;
183 Counter max_val;
184 Counter underflow;
185 Counter overflow;
186 VCounter cvec;
187 Counter sum;
188 Counter squares;
189 Counter logs;
190 Counter samples;
191 };
192
193 class DistInfo : public Info
194 {
195 public:
196 /** Local storage for the entry values, used for printing. */
197 DistData data;
198 };
199
200 class VectorDistInfo : public Info
201 {
202 public:
203 std::vector<DistData> data;
204
205 /** Names and descriptions of subfields. */
206 std::vector<std::string> subnames;
207 std::vector<std::string> subdescs;
208 void enable();
209
210 protected:
211 /** Local storage for the entry values, used for printing. */
212 mutable VResult rvec;
213
214 public:
215 virtual size_type size() const = 0;
216 };
217
218 class Vector2dInfo : public Info
219 {
220 public:
221 /** Names and descriptions of subfields. */
222 std::vector<std::string> subnames;
223 std::vector<std::string> subdescs;
224 std::vector<std::string> y_subnames;
225
226 size_type x;
227 size_type y;
228
229 /** Local storage for the entry values, used for printing. */
230 mutable VCounter cvec;
231
232 void enable();
233
234 virtual Result total() const = 0;
235 };
236
237 class FormulaInfo : public VectorInfo
238 {
239 public:
240 virtual std::string str() const = 0;
241 };
242
243 /** Data structure of sparse histogram */
244 struct SparseHistData
245 {
246 MCounter cmap;
247 Counter samples;
248 };
249
250
251 class SparseHistInfo : public Info
252 {
253 public:
254 /** Local storage for the entry values, used for printing. */
255 SparseHistData data;
256 };
257
258 typedef std::map<std::string, Info *> NameMapType;
259 NameMapType &nameMap();
260
261 } // namespace Stats
262
263 #endif // __BASE_STATS_INFO_HH__