info.hh revision 7811
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/flags.hh"
35#include "base/stats/types.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;
66
67class Info
68{
69  public:
70    /** The name of the stat. */
71    std::string name;
72    /** The description of the stat. */
73    std::string desc;
74    /** The formatting flags. */
75    Flags flags;
76    /** The display precision. */
77    int precision;
78    /** A pointer to a prerequisite Stat. */
79    const Info *prereq;
80    /**
81     * A unique stat ID for each stat in the simulator.
82     * Can be used externally for lookups as well as for debugging.
83     */
84    static int id_count;
85    int id;
86
87  public:
88    const StorageParams *storageParams;
89
90  public:
91    Info();
92    virtual ~Info();
93
94    /** Set the name of this statistic */
95    void setName(const std::string &name);
96
97    /**
98     * Check that this stat has been set up properly and is ready for
99     * use
100     * @return true for success
101     */
102    virtual bool check() const = 0;
103    bool baseCheck() const;
104
105    /**
106     * Enable the stat for use
107     */
108    virtual void enable();
109
110    /**
111     * Prepare the stat for dumping.
112     */
113    virtual void prepare() = 0;
114
115    /**
116     * Reset the stat to the default state.
117     */
118    virtual void reset() = 0;
119
120    /**
121     * @return true if this stat has a value and satisfies its
122     * requirement as a prereq
123     */
124    virtual bool zero() const = 0;
125
126    /**
127     * Visitor entry for outputing statistics data
128     */
129    virtual void visit(Visit &visitor) = 0;
130
131    /**
132     * Checks if the first stat's name is alphabetically less than the second.
133     * This function breaks names up at periods and considers each subname
134     * separately.
135     * @param stat1 The first stat.
136     * @param stat2 The second stat.
137     * @return stat1's name is alphabetically before stat2's
138     */
139    static bool less(Info *stat1, Info *stat2);
140};
141
142class ScalarInfo : public Info
143{
144  public:
145    virtual Counter value() const = 0;
146    virtual Result result() const = 0;
147    virtual Result total() const = 0;
148};
149
150class VectorInfo : public Info
151{
152  public:
153    /** Names and descriptions of subfields. */
154    std::vector<std::string> subnames;
155    std::vector<std::string> subdescs;
156
157  public:
158    void enable();
159
160  public:
161    virtual size_type size() const = 0;
162    virtual const VCounter &value() const = 0;
163    virtual const VResult &result() const = 0;
164    virtual Result total() const = 0;
165};
166
167enum DistType { Deviation, Dist };
168
169struct DistData
170{
171    DistType type;
172    Counter min;
173    Counter max;
174    Counter bucket_size;
175
176    Counter min_val;
177    Counter max_val;
178    Counter underflow;
179    Counter overflow;
180    VCounter cvec;
181    Counter sum;
182    Counter squares;
183    Counter samples;
184};
185
186class DistInfo : public Info
187{
188  public:
189    /** Local storage for the entry values, used for printing. */
190    DistData data;
191};
192
193class VectorDistInfo : public Info
194{
195  public:
196    std::vector<DistData> data;
197
198    /** Names and descriptions of subfields. */
199    std::vector<std::string> subnames;
200    std::vector<std::string> subdescs;
201    void enable();
202
203  protected:
204    /** Local storage for the entry values, used for printing. */
205    mutable VResult rvec;
206
207  public:
208    virtual size_type size() const = 0;
209};
210
211class Vector2dInfo : public Info
212{
213  public:
214    /** Names and descriptions of subfields. */
215    std::vector<std::string> subnames;
216    std::vector<std::string> subdescs;
217    std::vector<std::string> y_subnames;
218
219    size_type x;
220    size_type y;
221
222    /** Local storage for the entry values, used for printing. */
223    mutable VCounter cvec;
224
225    void enable();
226};
227
228class FormulaInfo : public VectorInfo
229{
230  public:
231    virtual std::string str() const = 0;
232};
233
234
235} // namespace Stats
236
237#endif // __BASE_STATS_INFO_HH__
238