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