info.hh revision 6129:05405c5b8c16
112027Sjungma@eit.uni-kl.de/*
212027Sjungma@eit.uni-kl.de * Copyright (c) 2003-2005 The Regents of The University of Michigan
312027Sjungma@eit.uni-kl.de * All rights reserved.
412027Sjungma@eit.uni-kl.de *
512027Sjungma@eit.uni-kl.de * Redistribution and use in source and binary forms, with or without
612027Sjungma@eit.uni-kl.de * modification, are permitted provided that the following conditions are
712027Sjungma@eit.uni-kl.de * met: redistributions of source code must retain the above copyright
812027Sjungma@eit.uni-kl.de * notice, this list of conditions and the following disclaimer;
912027Sjungma@eit.uni-kl.de * redistributions in binary form must reproduce the above copyright
1012027Sjungma@eit.uni-kl.de * notice, this list of conditions and the following disclaimer in the
1112027Sjungma@eit.uni-kl.de * documentation and/or other materials provided with the distribution;
1212027Sjungma@eit.uni-kl.de * neither the name of the copyright holders nor the names of its
1312027Sjungma@eit.uni-kl.de * contributors may be used to endorse or promote products derived from
1412027Sjungma@eit.uni-kl.de * this software without specific prior written permission.
1512027Sjungma@eit.uni-kl.de *
1612027Sjungma@eit.uni-kl.de * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1712027Sjungma@eit.uni-kl.de * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1812027Sjungma@eit.uni-kl.de * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1912027Sjungma@eit.uni-kl.de * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2012027Sjungma@eit.uni-kl.de * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2112027Sjungma@eit.uni-kl.de * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2212027Sjungma@eit.uni-kl.de * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2312027Sjungma@eit.uni-kl.de * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2412027Sjungma@eit.uni-kl.de * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2512027Sjungma@eit.uni-kl.de * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2612027Sjungma@eit.uni-kl.de * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2712027Sjungma@eit.uni-kl.de *
2812027Sjungma@eit.uni-kl.de * Authors: Nathan Binkert
2912027Sjungma@eit.uni-kl.de */
3012027Sjungma@eit.uni-kl.de
3112027Sjungma@eit.uni-kl.de#include "base/stats/flags.hh"
3212027Sjungma@eit.uni-kl.de#include "base/stats/types.hh"
3312027Sjungma@eit.uni-kl.de
3412027Sjungma@eit.uni-kl.denamespace Stats {
3512027Sjungma@eit.uni-kl.de
3612027Sjungma@eit.uni-kl.destruct StorageParams
3712027Sjungma@eit.uni-kl.de{
3812027Sjungma@eit.uni-kl.de    virtual ~StorageParams();
3912027Sjungma@eit.uni-kl.de};
4012027Sjungma@eit.uni-kl.de
4112027Sjungma@eit.uni-kl.destruct Visit;
4212027Sjungma@eit.uni-kl.de
4312027Sjungma@eit.uni-kl.declass Info
4412027Sjungma@eit.uni-kl.de{
4512027Sjungma@eit.uni-kl.de  public:
4612027Sjungma@eit.uni-kl.de    /** The name of the stat. */
4712027Sjungma@eit.uni-kl.de    std::string name;
4812027Sjungma@eit.uni-kl.de    /** The description of the stat. */
4912027Sjungma@eit.uni-kl.de    std::string desc;
5012027Sjungma@eit.uni-kl.de    /** The formatting flags. */
5112027Sjungma@eit.uni-kl.de    StatFlags flags;
5212027Sjungma@eit.uni-kl.de    /** The display precision. */
5312027Sjungma@eit.uni-kl.de    int precision;
5412027Sjungma@eit.uni-kl.de    /** A pointer to a prerequisite Stat. */
5512027Sjungma@eit.uni-kl.de    const Info *prereq;
5612027Sjungma@eit.uni-kl.de    /**
5712027Sjungma@eit.uni-kl.de     * A unique stat ID for each stat in the simulator.
5812027Sjungma@eit.uni-kl.de     * Can be used externally for lookups as well as for debugging.
5912027Sjungma@eit.uni-kl.de     */
6012027Sjungma@eit.uni-kl.de    static int id_count;
6112027Sjungma@eit.uni-kl.de    int id;
6212027Sjungma@eit.uni-kl.de
6312027Sjungma@eit.uni-kl.de  public:
6412027Sjungma@eit.uni-kl.de    const StorageParams *storageParams;
6512027Sjungma@eit.uni-kl.de
6612027Sjungma@eit.uni-kl.de  public:
6712027Sjungma@eit.uni-kl.de    Info();
6812027Sjungma@eit.uni-kl.de    virtual ~Info();
6912027Sjungma@eit.uni-kl.de
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