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