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#include "base/stats/flags.hh"
31#include "base/flags.hh"
32#include "base/stats/types.hh"
33
34namespace Stats {
35
36typedef uint16_t FlagsType;
37typedef ::Flags<FlagsType> Flags;
38
39/** Nothing extra to print. */
40const FlagsType none = 0x0000;
41/** This Stat is Initialized */
42const FlagsType init = 0x0001;
43/** Print this stat. */
44const FlagsType print = 0x0002;
45/** Print the total. */
46const FlagsType total = 0x0010;
47/** Print the percent of the total that this entry represents. */
48const FlagsType pdf = 0x0020;
49/** Print the cumulative percentage of total upto this entry. */
50const FlagsType cdf = 0x0040;
51/** Print the distribution. */
52const FlagsType dist = 0x0080;
53/** Don't print if this is zero. */
54const FlagsType nozero = 0x0100;
55/** Don't print if this is NAN */
56const FlagsType nonan = 0x0200;
57/** Used for SS compatability. */
58const FlagsType __substat = 0x8000;
59
60/** Mask of flags that can't be set directly */
61const FlagsType __reserved = init | print | __substat;
62
63struct StorageParams
64{
65 virtual ~StorageParams();
66};
67
68struct Visit;
69
70class Info
71{
72 public:
73 /** The name of the stat. */
74 std::string name;
75 /** The description of the stat. */
76 std::string desc;
77 /** The formatting flags. */
51 StatFlags flags;
78 Flags flags;
79 /** The display precision. */
80 int precision;
81 /** A pointer to a prerequisite Stat. */
82 const Info *prereq;
83 /**
84 * A unique stat ID for each stat in the simulator.
85 * Can be used externally for lookups as well as for debugging.
86 */
87 static int id_count;
88 int id;
89
90 public:
91 const StorageParams *storageParams;
92
93 public:
94 Info();
95 virtual ~Info();
96
97 /** Set the name of this statistic */
98 void setName(const std::string &name);
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;
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
170struct DistData
171{
172 Counter min_val;
173 Counter max_val;
174 Counter underflow;
175 Counter overflow;
176 VCounter cvec;
177 Counter sum;
178 Counter squares;
179 Counter samples;
180};
181
182struct DistParams : public StorageParams
183{
184 const bool fancy;
185
186 /** The minimum value to track. */
187 Counter min;
188 /** The maximum value to track. */
189 Counter max;
190 /** The number of entries in each bucket. */
191 Counter bucket_size;
192 /** The number of buckets. Equal to (max-min)/bucket_size. */
193 size_type buckets;
194
195 explicit DistParams(bool f) : fancy(f) {}
196};
197
198class DistInfo : public Info
199{
200 public:
201 /** Local storage for the entry values, used for printing. */
202 DistData data;
203};
204
205class VectorDistInfo : public Info
206{
207 public:
208 std::vector<DistData> data;
209
210 /** Names and descriptions of subfields. */
211 std::vector<std::string> subnames;
212 std::vector<std::string> subdescs;
213 void enable();
214
215 protected:
216 /** Local storage for the entry values, used for printing. */
217 mutable VResult rvec;
218
219 public:
220 virtual size_type size() const = 0;
221};
222
223class Vector2dInfo : public Info
224{
225 public:
226 /** Names and descriptions of subfields. */
227 std::vector<std::string> subnames;
228 std::vector<std::string> subdescs;
229 std::vector<std::string> y_subnames;
230
231 size_type x;
232 size_type y;
233
234 /** Local storage for the entry values, used for printing. */
235 mutable VCounter cvec;
236
237 void enable();
238};
239
240class FormulaInfo : public VectorInfo
241{
242 public:
243 virtual std::string str() const = 0;
244};
245
246
247/* namespace Stats */ }