info.hh revision 11565
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/** Print all values on a single line. Useful only for histograms. */
61const FlagsType oneline =       0x0400;
62
63/** Mask of flags that can't be set directly */
64const FlagsType __reserved =    init | display;
65
66struct StorageParams;
67struct Output;
68
69class 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 setSeparator(std::string _sep) { separatorString = _sep;}
101
102    /**
103     * Check that this stat has been set up properly and is ready for
104     * use
105     * @return true for success
106     */
107    virtual bool check() const = 0;
108    bool baseCheck() const;
109
110    /**
111     * Enable the stat for use
112     */
113    virtual void enable();
114
115    /**
116     * Prepare the stat for dumping.
117     */
118    virtual void prepare() = 0;
119
120    /**
121     * Reset the stat to the default state.
122     */
123    virtual void reset() = 0;
124
125    /**
126     * @return true if this stat has a value and satisfies its
127     * requirement as a prereq
128     */
129    virtual bool zero() const = 0;
130
131    /**
132     * Visitor entry for outputing statistics data
133     */
134    virtual void visit(Output &visitor) = 0;
135
136    /**
137     * Checks if the first stat's name is alphabetically less than the second.
138     * This function breaks names up at periods and considers each subname
139     * separately.
140     * @param stat1 The first stat.
141     * @param stat2 The second stat.
142     * @return stat1's name is alphabetically before stat2's
143     */
144    static bool less(Info *stat1, Info *stat2);
145};
146
147class ScalarInfo : public Info
148{
149  public:
150    virtual Counter value() const = 0;
151    virtual Result result() const = 0;
152    virtual Result total() const = 0;
153};
154
155class VectorInfo : public Info
156{
157  public:
158    /** Names and descriptions of subfields. */
159    std::vector<std::string> subnames;
160    std::vector<std::string> subdescs;
161
162  public:
163    void enable();
164
165  public:
166    virtual size_type size() const = 0;
167    virtual const VCounter &value() const = 0;
168    virtual const VResult &result() const = 0;
169    virtual Result total() const = 0;
170};
171
172enum DistType { Deviation, Dist, Hist };
173
174struct DistData
175{
176    DistType type;
177    Counter min;
178    Counter max;
179    Counter bucket_size;
180
181    Counter min_val;
182    Counter max_val;
183    Counter underflow;
184    Counter overflow;
185    VCounter cvec;
186    Counter sum;
187    Counter squares;
188    Counter logs;
189    Counter samples;
190};
191
192class DistInfo : public Info
193{
194  public:
195    /** Local storage for the entry values, used for printing. */
196    DistData data;
197};
198
199class VectorDistInfo : public Info
200{
201  public:
202    std::vector<DistData> data;
203
204    /** Names and descriptions of subfields. */
205    std::vector<std::string> subnames;
206    std::vector<std::string> subdescs;
207    void enable();
208
209  protected:
210    /** Local storage for the entry values, used for printing. */
211    mutable VResult rvec;
212
213  public:
214    virtual size_type size() const = 0;
215};
216
217class Vector2dInfo : public Info
218{
219  public:
220    /** Names and descriptions of subfields. */
221    std::vector<std::string> subnames;
222    std::vector<std::string> subdescs;
223    std::vector<std::string> y_subnames;
224
225    size_type x;
226    size_type y;
227
228    /** Local storage for the entry values, used for printing. */
229    mutable VCounter cvec;
230
231    void enable();
232
233    virtual Result total() const = 0;
234};
235
236class FormulaInfo : public VectorInfo
237{
238  public:
239    virtual std::string str() const = 0;
240};
241
242/** Data structure of sparse histogram */
243struct SparseHistData
244{
245    MCounter cmap;
246    Counter samples;
247};
248
249
250class SparseHistInfo : public Info
251{
252  public:
253    /** Local storage for the entry values, used for printing. */
254    SparseHistData data;
255};
256
257} // namespace Stats
258
259#endif // __BASE_STATS_INFO_HH__
260