info.hh revision 7462
15390SN/A/*
25446SN/A * Copyright (c) 2003-2005 The Regents of The University of Michigan
35390SN/A * All rights reserved.
45390SN/A *
55390SN/A * Redistribution and use in source and binary forms, with or without
65390SN/A * modification, are permitted provided that the following conditions are
75390SN/A * met: redistributions of source code must retain the above copyright
85390SN/A * notice, this list of conditions and the following disclaimer;
95390SN/A * redistributions in binary form must reproduce the above copyright
105390SN/A * notice, this list of conditions and the following disclaimer in the
115390SN/A * documentation and/or other materials provided with the distribution;
125390SN/A * neither the name of the copyright holders nor the names of its
135390SN/A * contributors may be used to endorse or promote products derived from
145390SN/A * this software without specific prior written permission.
155390SN/A *
165390SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
175390SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
185390SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
195390SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
205390SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
215390SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
225390SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
235390SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
245390SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
255390SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
265390SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
275390SN/A *
285390SN/A * Authors: Nathan Binkert
295390SN/A */
305390SN/A
315637Sgblack@eecs.umich.edu#ifndef __BASE_STATS_INFO_HH__
325637Sgblack@eecs.umich.edu#define __BASE_STATS_INFO_HH__
335390SN/A
345636SN/A#include "base/flags.hh"
355390SN/A#include "base/stats/types.hh"
365390SN/A
375636SN/Anamespace Stats {
385636SN/A
395636SN/Atypedef uint16_t FlagsType;
405636SN/Atypedef ::Flags<FlagsType> Flags;
415636SN/A
425636SN/A/** Nothing extra to print. */
435643Sgblack@eecs.umich.educonst FlagsType none =          0x0000;
445636SN/A/** This Stat is Initialized */
455636SN/Aconst FlagsType init =          0x0001;
465636SN/A/** Print this stat. */
475390SN/Aconst FlagsType display =       0x0002;
485390SN/A/** Print the total. */
495636SN/Aconst FlagsType total =         0x0010;
505446SN/A/** Print the percent of the total that this entry represents. */
515446SN/Aconst FlagsType pdf =           0x0020;
525636SN/A/** Print the cumulative percentage of total upto this entry. */
535636SN/Aconst FlagsType cdf =           0x0040;
545636SN/A/** Print the distribution. */
555636SN/Aconst FlagsType dist =          0x0080;
565636SN/A/** Don't print if this is zero. */
575643Sgblack@eecs.umich.educonst FlagsType nozero =        0x0100;
585390SN/A/** Don't print if this is NAN */
595446SN/Aconst FlagsType nonan =         0x0200;
605390SN/A
615390SN/A/** Mask of flags that can't be set directly */
625390SN/Aconst FlagsType __reserved =    init | display;
635390SN/A
645390SN/Astruct StorageParams
655390SN/A{
665390SN/A    virtual ~StorageParams();
675390SN/A};
685390SN/A
695390SN/Astruct Visit;
705637Sgblack@eecs.umich.edu
71class Info
72{
73  public:
74    /** The name of the stat. */
75    std::string name;
76    /** The description of the stat. */
77    std::string desc;
78    /** The formatting flags. */
79    Flags flags;
80    /** The display precision. */
81    int precision;
82    /** A pointer to a prerequisite Stat. */
83    const Info *prereq;
84    /**
85     * A unique stat ID for each stat in the simulator.
86     * Can be used externally for lookups as well as for debugging.
87     */
88    static int id_count;
89    int id;
90
91  public:
92    const StorageParams *storageParams;
93
94  public:
95    Info();
96    virtual ~Info();
97
98    /** Set the name of this statistic */
99    void setName(const std::string &name);
100
101    /**
102     * Check that this stat has been set up properly and is ready for
103     * use
104     * @return true for success
105     */
106    virtual bool check() const = 0;
107    bool baseCheck() const;
108
109    /**
110     * Enable the stat for use
111     */
112    virtual void enable();
113
114    /**
115     * Prepare the stat for dumping.
116     */
117    virtual void prepare() = 0;
118
119    /**
120     * Reset the stat to the default state.
121     */
122    virtual void reset() = 0;
123
124    /**
125     * @return true if this stat has a value and satisfies its
126     * requirement as a prereq
127     */
128    virtual bool zero() const = 0;
129
130    /**
131     * Visitor entry for outputing statistics data
132     */
133    virtual void visit(Visit &visitor) = 0;
134
135    /**
136     * Checks if the first stat's name is alphabetically less than the second.
137     * This function breaks names up at periods and considers each subname
138     * separately.
139     * @param stat1 The first stat.
140     * @param stat2 The second stat.
141     * @return stat1's name is alphabetically before stat2's
142     */
143    static bool less(Info *stat1, Info *stat2);
144};
145
146class ScalarInfo : public Info
147{
148  public:
149    virtual Counter value() const = 0;
150    virtual Result result() const = 0;
151    virtual Result total() const = 0;
152};
153
154class VectorInfo : public Info
155{
156  public:
157    /** Names and descriptions of subfields. */
158    std::vector<std::string> subnames;
159    std::vector<std::string> subdescs;
160
161  public:
162    void enable();
163
164  public:
165    virtual size_type size() const = 0;
166    virtual const VCounter &value() const = 0;
167    virtual const VResult &result() const = 0;
168    virtual Result total() const = 0;
169};
170
171struct DistData
172{
173    Counter min_val;
174    Counter max_val;
175    Counter underflow;
176    Counter overflow;
177    VCounter cvec;
178    Counter sum;
179    Counter squares;
180    Counter samples;
181};
182
183enum DistType { Deviation, Dist };
184
185struct DistParams : public StorageParams
186{
187    const DistType type;
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(DistType t) : type(t) {}
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