2 * Copyright (c) 2003-2005 The Regents of The University of Michigan
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.
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.
28 * Authors: Nathan Binkert
31 #ifndef __BASE_STATS_INFO_HH__
32 #define __BASE_STATS_INFO_HH__
34 #include "base/flags.hh"
35 #include "base/stats/types.hh"
39 typedef uint16_t FlagsType;
40 typedef ::Flags<FlagsType> Flags;
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 print = 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;
61 /** Mask of flags that can't be set directly */
62 const FlagsType __reserved = init | print;
66 virtual ~StorageParams();
74 /** The name of the stat. */
76 /** The description of the stat. */
78 /** The formatting flags. */
80 /** The display precision. */
82 /** A pointer to a prerequisite Stat. */
85 * A unique stat ID for each stat in the simulator.
86 * Can be used externally for lookups as well as for debugging.
92 const StorageParams *storageParams;
98 /** Set the name of this statistic */
99 void setName(const std::string &name);
102 * Check that this stat has been set up properly and is ready for
104 * @return true for success
106 virtual bool check() const = 0;
107 bool baseCheck() const;
110 * Enable the stat for use
112 virtual void enable();
115 * Prepare the stat for dumping.
117 virtual void prepare() = 0;
120 * Reset the stat to the default state.
122 virtual void reset() = 0;
125 * @return true if this stat has a value and satisfies its
126 * requirement as a prereq
128 virtual bool zero() const = 0;
131 * Visitor entry for outputing statistics data
133 virtual void visit(Visit &visitor) = 0;
136 * Checks if the first stat's name is alphabetically less than the second.
137 * This function breaks names up at periods and considers each subname
139 * @param stat1 The first stat.
140 * @param stat2 The second stat.
141 * @return stat1's name is alphabetically before stat2's
143 static bool less(Info *stat1, Info *stat2);
146 class ScalarInfo : public Info
149 virtual Counter value() const = 0;
150 virtual Result result() const = 0;
151 virtual Result total() const = 0;
154 class VectorInfo : public Info
157 /** Names and descriptions of subfields. */
158 std::vector<std::string> subnames;
159 std::vector<std::string> subdescs;
165 virtual size_type size() const = 0;
166 virtual const VCounter &value() const = 0;
167 virtual const VResult &result() const = 0;
168 virtual Result total() const = 0;
183 struct DistParams : public StorageParams
187 /** The minimum value to track. */
189 /** The maximum value to track. */
191 /** The number of entries in each bucket. */
193 /** The number of buckets. Equal to (max-min)/bucket_size. */
196 explicit DistParams(bool f) : fancy(f) {}
199 class DistInfo : public Info
202 /** Local storage for the entry values, used for printing. */
206 class VectorDistInfo : public Info
209 std::vector<DistData> data;
211 /** Names and descriptions of subfields. */
212 std::vector<std::string> subnames;
213 std::vector<std::string> subdescs;
217 /** Local storage for the entry values, used for printing. */
218 mutable VResult rvec;
221 virtual size_type size() const = 0;
224 class Vector2dInfo : public Info
227 /** Names and descriptions of subfields. */
228 std::vector<std::string> subnames;
229 std::vector<std::string> subdescs;
230 std::vector<std::string> y_subnames;
235 /** Local storage for the entry values, used for printing. */
236 mutable VCounter cvec;
241 class FormulaInfo : public VectorInfo
244 virtual std::string str() const = 0;
248 /* namespace Stats */ }
250 #endif // __BASE_STATS_INFO_HH__