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