info.hh revision 9743
16145Snate@binkert.org/*
26145Snate@binkert.org * Copyright (c) 2003-2005 The Regents of The University of Michigan
36145Snate@binkert.org * All rights reserved.
46145Snate@binkert.org *
56145Snate@binkert.org * Redistribution and use in source and binary forms, with or without
66145Snate@binkert.org * modification, are permitted provided that the following conditions are
76145Snate@binkert.org * met: redistributions of source code must retain the above copyright
86145Snate@binkert.org * notice, this list of conditions and the following disclaimer;
96145Snate@binkert.org * redistributions in binary form must reproduce the above copyright
106145Snate@binkert.org * notice, this list of conditions and the following disclaimer in the
116145Snate@binkert.org * documentation and/or other materials provided with the distribution;
126145Snate@binkert.org * neither the name of the copyright holders nor the names of its
136145Snate@binkert.org * contributors may be used to endorse or promote products derived from
146145Snate@binkert.org * this software without specific prior written permission.
156145Snate@binkert.org *
166145Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
176145Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
186145Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
196145Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
206145Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
216145Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
226145Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
236145Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
246145Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
256145Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
266145Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
276145Snate@binkert.org *
286145Snate@binkert.org * Authors: Nathan Binkert
296145Snate@binkert.org */
306145Snate@binkert.org
316145Snate@binkert.org#ifndef __BASE_STATS_INFO_HH__
326145Snate@binkert.org#define __BASE_STATS_INFO_HH__
336145Snate@binkert.org
346145Snate@binkert.org#include "base/stats/types.hh"
356145Snate@binkert.org#include "base/flags.hh"
366145Snate@binkert.org
376145Snate@binkert.orgnamespace Stats {
386145Snate@binkert.org
396145Snate@binkert.orgtypedef uint16_t FlagsType;
406145Snate@binkert.orgtypedef ::Flags<FlagsType> Flags;
416145Snate@binkert.org
426154Snate@binkert.org/** Nothing extra to print. */
436154Snate@binkert.orgconst FlagsType none =          0x0000;
446145Snate@binkert.org/** This Stat is Initialized */
456145Snate@binkert.orgconst FlagsType init =          0x0001;
466145Snate@binkert.org/** Print this stat. */
476145Snate@binkert.orgconst FlagsType display =       0x0002;
486145Snate@binkert.org/** Print the total. */
496145Snate@binkert.orgconst FlagsType total =         0x0010;
506145Snate@binkert.org/** Print the percent of the total that this entry represents. */
516145Snate@binkert.orgconst FlagsType pdf =           0x0020;
526145Snate@binkert.org/** Print the cumulative percentage of total upto this entry. */
536145Snate@binkert.orgconst FlagsType cdf =           0x0040;
546145Snate@binkert.org/** Print the distribution. */
556145Snate@binkert.orgconst FlagsType dist =          0x0080;
566145Snate@binkert.org/** Don't print if this is zero. */
576145Snate@binkert.orgconst FlagsType nozero =        0x0100;
586145Snate@binkert.org/** Don't print if this is NAN */
596145Snate@binkert.orgconst FlagsType nonan =         0x0200;
606145Snate@binkert.org/** Print all values on a single line. Useful only for histograms. */
616145Snate@binkert.orgconst FlagsType oneline =       0x0400;
626145Snate@binkert.org
636145Snate@binkert.org/** Mask of flags that can't be set directly */
646145Snate@binkert.orgconst FlagsType __reserved =    init | display;
656145Snate@binkert.org
666145Snate@binkert.orgstruct StorageParams;
676145Snate@binkert.orgstruct Output;
686145Snate@binkert.org
696145Snate@binkert.orgclass Info
706145Snate@binkert.org{
716145Snate@binkert.org  public:
726145Snate@binkert.org    /** The name of the stat. */
736145Snate@binkert.org    std::string name;
746145Snate@binkert.org    /** The separator string used for vectors, dist, etc. */
756145Snate@binkert.org    static std::string separatorString;
766145Snate@binkert.org    /** The description of the stat. */
776145Snate@binkert.org    std::string desc;
786145Snate@binkert.org    /** The formatting flags. */
796145Snate@binkert.org    Flags flags;
806145Snate@binkert.org    /** The display precision. */
816145Snate@binkert.org    int precision;
826145Snate@binkert.org    /** A pointer to a prerequisite Stat. */
836145Snate@binkert.org    const Info *prereq;
846145Snate@binkert.org    /**
856145Snate@binkert.org     * A unique stat ID for each stat in the simulator.
866145Snate@binkert.org     * Can be used externally for lookups as well as for debugging.
876145Snate@binkert.org     */
886145Snate@binkert.org    static int id_count;
896145Snate@binkert.org    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    void setSeparator(std::string _sep) { separatorString = _sep;}
101
102    /**
103     * Check that this stat has been set up properly and is ready for
104     * use
105     * @return true for success
106     */
107    virtual bool check() const = 0;
108    bool baseCheck() const;
109
110    /**
111     * Enable the stat for use
112     */
113    virtual void enable();
114
115    /**
116     * Prepare the stat for dumping.
117     */
118    virtual void prepare() = 0;
119
120    /**
121     * Reset the stat to the default state.
122     */
123    virtual void reset() = 0;
124
125    /**
126     * @return true if this stat has a value and satisfies its
127     * requirement as a prereq
128     */
129    virtual bool zero() const = 0;
130
131    /**
132     * Visitor entry for outputing statistics data
133     */
134    virtual void visit(Output &visitor) = 0;
135
136    /**
137     * Checks if the first stat's name is alphabetically less than the second.
138     * This function breaks names up at periods and considers each subname
139     * separately.
140     * @param stat1 The first stat.
141     * @param stat2 The second stat.
142     * @return stat1's name is alphabetically before stat2's
143     */
144    static bool less(Info *stat1, Info *stat2);
145};
146
147class ScalarInfo : public Info
148{
149  public:
150    virtual Counter value() const = 0;
151    virtual Result result() const = 0;
152    virtual Result total() const = 0;
153};
154
155class VectorInfo : public Info
156{
157  public:
158    /** Names and descriptions of subfields. */
159    std::vector<std::string> subnames;
160    std::vector<std::string> subdescs;
161
162  public:
163    void enable();
164
165  public:
166    virtual size_type size() const = 0;
167    virtual const VCounter &value() const = 0;
168    virtual const VResult &result() const = 0;
169    virtual Result total() const = 0;
170};
171
172enum DistType { Deviation, Dist, Hist };
173
174struct DistData
175{
176    DistType type;
177    Counter min;
178    Counter max;
179    Counter bucket_size;
180
181    Counter min_val;
182    Counter max_val;
183    Counter underflow;
184    Counter overflow;
185    VCounter cvec;
186    Counter sum;
187    Counter squares;
188    Counter logs;
189    Counter samples;
190};
191
192class DistInfo : public Info
193{
194  public:
195    /** Local storage for the entry values, used for printing. */
196    DistData data;
197};
198
199class VectorDistInfo : public Info
200{
201  public:
202    std::vector<DistData> data;
203
204    /** Names and descriptions of subfields. */
205    std::vector<std::string> subnames;
206    std::vector<std::string> subdescs;
207    void enable();
208
209  protected:
210    /** Local storage for the entry values, used for printing. */
211    mutable VResult rvec;
212
213  public:
214    virtual size_type size() const = 0;
215};
216
217class Vector2dInfo : public Info
218{
219  public:
220    /** Names and descriptions of subfields. */
221    std::vector<std::string> subnames;
222    std::vector<std::string> subdescs;
223    std::vector<std::string> y_subnames;
224
225    size_type x;
226    size_type y;
227
228    /** Local storage for the entry values, used for printing. */
229    mutable VCounter cvec;
230
231    void enable();
232};
233
234class FormulaInfo : public VectorInfo
235{
236  public:
237    virtual std::string str() const = 0;
238};
239
240/** Data structure of sparse histogram */
241struct SparseHistData
242{
243    MCounter cmap;
244    Counter samples;
245};
246
247
248class SparseHistInfo : public Info
249{
250  public:
251    /** Local storage for the entry values, used for printing. */
252    SparseHistData data;
253};
254
255} // namespace Stats
256
257#endif // __BASE_STATS_INFO_HH__
258