info.hh (8243:63e849f0f341) info.hh (8296:be7f03723412)
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 * Authors: Nathan Binkert
29 */
30
31#ifndef __BASE_STATS_INFO_HH__
32#define __BASE_STATS_INFO_HH__
33
34#include "base/stats/types.hh"
35#include "base/flags.hh"
36
37namespace Stats {
38
39typedef uint16_t FlagsType;
40typedef ::Flags<FlagsType> Flags;
41
42/** Nothing extra to print. */
43const FlagsType none = 0x0000;
44/** This Stat is Initialized */
45const FlagsType init = 0x0001;
46/** Print this stat. */
47const FlagsType display = 0x0002;
48/** Print the total. */
49const FlagsType total = 0x0010;
50/** Print the percent of the total that this entry represents. */
51const FlagsType pdf = 0x0020;
52/** Print the cumulative percentage of total upto this entry. */
53const FlagsType cdf = 0x0040;
54/** Print the distribution. */
55const FlagsType dist = 0x0080;
56/** Don't print if this is zero. */
57const FlagsType nozero = 0x0100;
58/** Don't print if this is NAN */
59const FlagsType nonan = 0x0200;
60
61/** Mask of flags that can't be set directly */
62const FlagsType __reserved = init | display;
63
64struct StorageParams;
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 * Authors: Nathan Binkert
29 */
30
31#ifndef __BASE_STATS_INFO_HH__
32#define __BASE_STATS_INFO_HH__
33
34#include "base/stats/types.hh"
35#include "base/flags.hh"
36
37namespace Stats {
38
39typedef uint16_t FlagsType;
40typedef ::Flags<FlagsType> Flags;
41
42/** Nothing extra to print. */
43const FlagsType none = 0x0000;
44/** This Stat is Initialized */
45const FlagsType init = 0x0001;
46/** Print this stat. */
47const FlagsType display = 0x0002;
48/** Print the total. */
49const FlagsType total = 0x0010;
50/** Print the percent of the total that this entry represents. */
51const FlagsType pdf = 0x0020;
52/** Print the cumulative percentage of total upto this entry. */
53const FlagsType cdf = 0x0040;
54/** Print the distribution. */
55const FlagsType dist = 0x0080;
56/** Don't print if this is zero. */
57const FlagsType nozero = 0x0100;
58/** Don't print if this is NAN */
59const FlagsType nonan = 0x0200;
60
61/** Mask of flags that can't be set directly */
62const FlagsType __reserved = init | display;
63
64struct StorageParams;
65struct Visit;
65struct Output;
66
67class Info
68{
69 public:
70 /** The name of the stat. */
71 std::string name;
72 /** The separator string used for vectors, dist, etc. */
73 static std::string separatorString;
74 /** The description of the stat. */
75 std::string desc;
76 /** The formatting flags. */
77 Flags flags;
78 /** The display precision. */
79 int precision;
80 /** A pointer to a prerequisite Stat. */
81 const Info *prereq;
82 /**
83 * A unique stat ID for each stat in the simulator.
84 * Can be used externally for lookups as well as for debugging.
85 */
86 static int id_count;
87 int id;
88
89 public:
90 const StorageParams *storageParams;
91
92 public:
93 Info();
94 virtual ~Info();
95
96 /** Set the name of this statistic */
97 void setName(const std::string &name);
98 void setSeparator(std::string _sep) { separatorString = _sep;}
99
100 /**
101 * Check that this stat has been set up properly and is ready for
102 * use
103 * @return true for success
104 */
105 virtual bool check() const = 0;
106 bool baseCheck() const;
107
108 /**
109 * Enable the stat for use
110 */
111 virtual void enable();
112
113 /**
114 * Prepare the stat for dumping.
115 */
116 virtual void prepare() = 0;
117
118 /**
119 * Reset the stat to the default state.
120 */
121 virtual void reset() = 0;
122
123 /**
124 * @return true if this stat has a value and satisfies its
125 * requirement as a prereq
126 */
127 virtual bool zero() const = 0;
128
129 /**
130 * Visitor entry for outputing statistics data
131 */
66
67class Info
68{
69 public:
70 /** The name of the stat. */
71 std::string name;
72 /** The separator string used for vectors, dist, etc. */
73 static std::string separatorString;
74 /** The description of the stat. */
75 std::string desc;
76 /** The formatting flags. */
77 Flags flags;
78 /** The display precision. */
79 int precision;
80 /** A pointer to a prerequisite Stat. */
81 const Info *prereq;
82 /**
83 * A unique stat ID for each stat in the simulator.
84 * Can be used externally for lookups as well as for debugging.
85 */
86 static int id_count;
87 int id;
88
89 public:
90 const StorageParams *storageParams;
91
92 public:
93 Info();
94 virtual ~Info();
95
96 /** Set the name of this statistic */
97 void setName(const std::string &name);
98 void setSeparator(std::string _sep) { separatorString = _sep;}
99
100 /**
101 * Check that this stat has been set up properly and is ready for
102 * use
103 * @return true for success
104 */
105 virtual bool check() const = 0;
106 bool baseCheck() const;
107
108 /**
109 * Enable the stat for use
110 */
111 virtual void enable();
112
113 /**
114 * Prepare the stat for dumping.
115 */
116 virtual void prepare() = 0;
117
118 /**
119 * Reset the stat to the default state.
120 */
121 virtual void reset() = 0;
122
123 /**
124 * @return true if this stat has a value and satisfies its
125 * requirement as a prereq
126 */
127 virtual bool zero() const = 0;
128
129 /**
130 * Visitor entry for outputing statistics data
131 */
132 virtual void visit(Visit &visitor) = 0;
132 virtual void visit(Output &visitor) = 0;
133
134 /**
135 * Checks if the first stat's name is alphabetically less than the second.
136 * This function breaks names up at periods and considers each subname
137 * separately.
138 * @param stat1 The first stat.
139 * @param stat2 The second stat.
140 * @return stat1's name is alphabetically before stat2's
141 */
142 static bool less(Info *stat1, Info *stat2);
143};
144
145class ScalarInfo : public Info
146{
147 public:
148 virtual Counter value() const = 0;
149 virtual Result result() const = 0;
150 virtual Result total() const = 0;
151};
152
153class VectorInfo : public Info
154{
155 public:
156 /** Names and descriptions of subfields. */
157 std::vector<std::string> subnames;
158 std::vector<std::string> subdescs;
159
160 public:
161 void enable();
162
163 public:
164 virtual size_type size() const = 0;
165 virtual const VCounter &value() const = 0;
166 virtual const VResult &result() const = 0;
167 virtual Result total() const = 0;
168};
169
170enum DistType { Deviation, Dist, Hist };
171
172struct DistData
173{
174 DistType type;
175 Counter min;
176 Counter max;
177 Counter bucket_size;
178
179 Counter min_val;
180 Counter max_val;
181 Counter underflow;
182 Counter overflow;
183 VCounter cvec;
184 Counter sum;
185 Counter squares;
186 Counter samples;
187};
188
189class DistInfo : public Info
190{
191 public:
192 /** Local storage for the entry values, used for printing. */
193 DistData data;
194};
195
196class VectorDistInfo : public Info
197{
198 public:
199 std::vector<DistData> data;
200
201 /** Names and descriptions of subfields. */
202 std::vector<std::string> subnames;
203 std::vector<std::string> subdescs;
204 void enable();
205
206 protected:
207 /** Local storage for the entry values, used for printing. */
208 mutable VResult rvec;
209
210 public:
211 virtual size_type size() const = 0;
212};
213
214class Vector2dInfo : public Info
215{
216 public:
217 /** Names and descriptions of subfields. */
218 std::vector<std::string> subnames;
219 std::vector<std::string> subdescs;
220 std::vector<std::string> y_subnames;
221
222 size_type x;
223 size_type y;
224
225 /** Local storage for the entry values, used for printing. */
226 mutable VCounter cvec;
227
228 void enable();
229};
230
231class FormulaInfo : public VectorInfo
232{
233 public:
234 virtual std::string str() const = 0;
235};
236
237
238} // namespace Stats
239
240#endif // __BASE_STATS_INFO_HH__
133
134 /**
135 * Checks if the first stat's name is alphabetically less than the second.
136 * This function breaks names up at periods and considers each subname
137 * separately.
138 * @param stat1 The first stat.
139 * @param stat2 The second stat.
140 * @return stat1's name is alphabetically before stat2's
141 */
142 static bool less(Info *stat1, Info *stat2);
143};
144
145class ScalarInfo : public Info
146{
147 public:
148 virtual Counter value() const = 0;
149 virtual Result result() const = 0;
150 virtual Result total() const = 0;
151};
152
153class VectorInfo : public Info
154{
155 public:
156 /** Names and descriptions of subfields. */
157 std::vector<std::string> subnames;
158 std::vector<std::string> subdescs;
159
160 public:
161 void enable();
162
163 public:
164 virtual size_type size() const = 0;
165 virtual const VCounter &value() const = 0;
166 virtual const VResult &result() const = 0;
167 virtual Result total() const = 0;
168};
169
170enum DistType { Deviation, Dist, Hist };
171
172struct DistData
173{
174 DistType type;
175 Counter min;
176 Counter max;
177 Counter bucket_size;
178
179 Counter min_val;
180 Counter max_val;
181 Counter underflow;
182 Counter overflow;
183 VCounter cvec;
184 Counter sum;
185 Counter squares;
186 Counter samples;
187};
188
189class DistInfo : public Info
190{
191 public:
192 /** Local storage for the entry values, used for printing. */
193 DistData data;
194};
195
196class VectorDistInfo : public Info
197{
198 public:
199 std::vector<DistData> data;
200
201 /** Names and descriptions of subfields. */
202 std::vector<std::string> subnames;
203 std::vector<std::string> subdescs;
204 void enable();
205
206 protected:
207 /** Local storage for the entry values, used for printing. */
208 mutable VResult rvec;
209
210 public:
211 virtual size_type size() const = 0;
212};
213
214class Vector2dInfo : public Info
215{
216 public:
217 /** Names and descriptions of subfields. */
218 std::vector<std::string> subnames;
219 std::vector<std::string> subdescs;
220 std::vector<std::string> y_subnames;
221
222 size_type x;
223 size_type y;
224
225 /** Local storage for the entry values, used for printing. */
226 mutable VCounter cvec;
227
228 void enable();
229};
230
231class FormulaInfo : public VectorInfo
232{
233 public:
234 virtual std::string str() const = 0;
235};
236
237
238} // namespace Stats
239
240#endif // __BASE_STATS_INFO_HH__