info.hh revision 11565
15389Sgblack@eecs.umich.edu/*
25446Sgblack@eecs.umich.edu * Copyright (c) 2003-2005 The Regents of The University of Michigan
35389Sgblack@eecs.umich.edu * All rights reserved.
45389Sgblack@eecs.umich.edu *
55389Sgblack@eecs.umich.edu * Redistribution and use in source and binary forms, with or without
65389Sgblack@eecs.umich.edu * modification, are permitted provided that the following conditions are
75389Sgblack@eecs.umich.edu * met: redistributions of source code must retain the above copyright
85389Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer;
95389Sgblack@eecs.umich.edu * redistributions in binary form must reproduce the above copyright
105389Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the
115389Sgblack@eecs.umich.edu * documentation and/or other materials provided with the distribution;
125389Sgblack@eecs.umich.edu * neither the name of the copyright holders nor the names of its
135389Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from
145389Sgblack@eecs.umich.edu * this software without specific prior written permission.
155389Sgblack@eecs.umich.edu *
165389Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
175389Sgblack@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
185389Sgblack@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
195389Sgblack@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
205389Sgblack@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
215389Sgblack@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
225389Sgblack@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
235389Sgblack@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
245389Sgblack@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
255389Sgblack@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
265389Sgblack@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
275389Sgblack@eecs.umich.edu *
285389Sgblack@eecs.umich.edu * Authors: Nathan Binkert
295389Sgblack@eecs.umich.edu */
305389Sgblack@eecs.umich.edu
315389Sgblack@eecs.umich.edu#ifndef __BASE_STATS_INFO_HH__
325389Sgblack@eecs.umich.edu#define __BASE_STATS_INFO_HH__
335389Sgblack@eecs.umich.edu
345389Sgblack@eecs.umich.edu#include "base/stats/types.hh"
3511793Sbrandon.potter@amd.com#include "base/flags.hh"
3611793Sbrandon.potter@amd.com
375389Sgblack@eecs.umich.edunamespace Stats {
385389Sgblack@eecs.umich.edu
395389Sgblack@eecs.umich.edutypedef uint16_t FlagsType;
405389Sgblack@eecs.umich.edutypedef ::Flags<FlagsType> Flags;
415654Sgblack@eecs.umich.edu
425389Sgblack@eecs.umich.edu/** Nothing extra to print. */
436658Snate@binkert.orgconst FlagsType none =          0x0000;
445389Sgblack@eecs.umich.edu/** This Stat is Initialized */
4511793Sbrandon.potter@amd.comconst FlagsType init =          0x0001;
465643Sgblack@eecs.umich.edu/** Print this stat. */
475636Sgblack@eecs.umich.educonst FlagsType display =       0x0002;
485830Sgblack@eecs.umich.edu/** Print the total. */
495637Sgblack@eecs.umich.educonst FlagsType total =         0x0010;
505389Sgblack@eecs.umich.edu/** Print the percent of the total that this entry represents. */
515389Sgblack@eecs.umich.educonst FlagsType pdf =           0x0020;
525389Sgblack@eecs.umich.edu/** Print the cumulative percentage of total upto this entry. */
535389Sgblack@eecs.umich.educonst FlagsType cdf =           0x0040;
545389Sgblack@eecs.umich.edu/** Print the distribution. */
555638Sgblack@eecs.umich.educonst FlagsType dist =          0x0080;
565389Sgblack@eecs.umich.edu/** Don't print if this is zero. */
575389Sgblack@eecs.umich.educonst FlagsType nozero =        0x0100;
585446Sgblack@eecs.umich.edu/** Don't print if this is NAN */
595389Sgblack@eecs.umich.educonst FlagsType nonan =         0x0200;
605389Sgblack@eecs.umich.edu/** Print all values on a single line. Useful only for histograms. */
615446Sgblack@eecs.umich.educonst FlagsType oneline =       0x0400;
625638Sgblack@eecs.umich.edu
635446Sgblack@eecs.umich.edu/** Mask of flags that can't be set directly */
645446Sgblack@eecs.umich.educonst FlagsType __reserved =    init | display;
655643Sgblack@eecs.umich.edu
665643Sgblack@eecs.umich.edustruct StorageParams;
675643Sgblack@eecs.umich.edustruct Output;
685643Sgblack@eecs.umich.edu
695636Sgblack@eecs.umich.educlass Info
705446Sgblack@eecs.umich.edu{
715446Sgblack@eecs.umich.edu  public:
725446Sgblack@eecs.umich.edu    /** The name of the stat. */
735446Sgblack@eecs.umich.edu    std::string name;
745446Sgblack@eecs.umich.edu    /** The separator string used for vectors, dist, etc. */
755635Sgblack@eecs.umich.edu    static std::string separatorString;
765635Sgblack@eecs.umich.edu    /** The description of the stat. */
775643Sgblack@eecs.umich.edu    std::string desc;
785643Sgblack@eecs.umich.edu    /** The formatting flags. */
795643Sgblack@eecs.umich.edu    Flags flags;
805643Sgblack@eecs.umich.edu    /** The display precision. */
815643Sgblack@eecs.umich.edu    int precision;
825643Sgblack@eecs.umich.edu    /** A pointer to a prerequisite Stat. */
835654Sgblack@eecs.umich.edu    const Info *prereq;
845643Sgblack@eecs.umich.edu    /**
855643Sgblack@eecs.umich.edu     * A unique stat ID for each stat in the simulator.
865643Sgblack@eecs.umich.edu     * Can be used externally for lookups as well as for debugging.
875829Sgblack@eecs.umich.edu     */
885829Sgblack@eecs.umich.edu    static int id_count;
895829Sgblack@eecs.umich.edu    int id;
905829Sgblack@eecs.umich.edu
915829Sgblack@eecs.umich.edu  public:
925829Sgblack@eecs.umich.edu    const StorageParams *storageParams;
935829Sgblack@eecs.umich.edu
945829Sgblack@eecs.umich.edu  public:
955829Sgblack@eecs.umich.edu    Info();
965829Sgblack@eecs.umich.edu    virtual ~Info();
975829Sgblack@eecs.umich.edu
985829Sgblack@eecs.umich.edu    /** Set the name of this statistic */
995829Sgblack@eecs.umich.edu    void setName(const std::string &name);
1005829Sgblack@eecs.umich.edu    void setSeparator(std::string _sep) { separatorString = _sep;}
1015829Sgblack@eecs.umich.edu
1025829Sgblack@eecs.umich.edu    /**
1035829Sgblack@eecs.umich.edu     * Check that this stat has been set up properly and is ready for
1045843Sgblack@eecs.umich.edu     * use
1055843Sgblack@eecs.umich.edu     * @return true for success
1065843Sgblack@eecs.umich.edu     */
1075843Sgblack@eecs.umich.edu    virtual bool check() const = 0;
1085843Sgblack@eecs.umich.edu    bool baseCheck() const;
1095843Sgblack@eecs.umich.edu
1106073Sgblack@eecs.umich.edu    /**
1116073Sgblack@eecs.umich.edu     * Enable the stat for use
1126073Sgblack@eecs.umich.edu     */
1136073Sgblack@eecs.umich.edu    virtual void enable();
1146073Sgblack@eecs.umich.edu
1156073Sgblack@eecs.umich.edu    /**
1166073Sgblack@eecs.umich.edu     * Prepare the stat for dumping.
1175446Sgblack@eecs.umich.edu     */
1185446Sgblack@eecs.umich.edu    virtual void prepare() = 0;
1195389Sgblack@eecs.umich.edu
1205638Sgblack@eecs.umich.edu    /**
1215389Sgblack@eecs.umich.edu     * Reset the stat to the default state.
1225830Sgblack@eecs.umich.edu     */
1235830Sgblack@eecs.umich.edu    virtual void reset() = 0;
1245389Sgblack@eecs.umich.edu
1255389Sgblack@eecs.umich.edu    /**
1265389Sgblack@eecs.umich.edu     * @return true if this stat has a value and satisfies its
1275638Sgblack@eecs.umich.edu     * requirement as a prereq
1285389Sgblack@eecs.umich.edu     */
1295389Sgblack@eecs.umich.edu    virtual bool zero() const = 0;
1305389Sgblack@eecs.umich.edu
1315389Sgblack@eecs.umich.edu    /**
1325389Sgblack@eecs.umich.edu     * Visitor entry for outputing statistics data
1335389Sgblack@eecs.umich.edu     */
1345638Sgblack@eecs.umich.edu    virtual void visit(Output &visitor) = 0;
1355389Sgblack@eecs.umich.edu
1365842Sgblack@eecs.umich.edu    /**
1375389Sgblack@eecs.umich.edu     * Checks if the first stat's name is alphabetically less than the second.
1385389Sgblack@eecs.umich.edu     * This function breaks names up at periods and considers each subname
1395389Sgblack@eecs.umich.edu     * separately.
1405638Sgblack@eecs.umich.edu     * @param stat1 The first stat.
1415389Sgblack@eecs.umich.edu     * @param stat2 The second stat.
1425842Sgblack@eecs.umich.edu     * @return stat1's name is alphabetically before stat2's
1435389Sgblack@eecs.umich.edu     */
1445389Sgblack@eecs.umich.edu    static bool less(Info *stat1, Info *stat2);
1455638Sgblack@eecs.umich.edu};
1465638Sgblack@eecs.umich.edu
1475389Sgblack@eecs.umich.educlass ScalarInfo : public Info
1485638Sgblack@eecs.umich.edu{
1495389Sgblack@eecs.umich.edu  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    virtual Result total() const = 0;
234};
235
236class FormulaInfo : public VectorInfo
237{
238  public:
239    virtual std::string str() const = 0;
240};
241
242/** Data structure of sparse histogram */
243struct SparseHistData
244{
245    MCounter cmap;
246    Counter samples;
247};
248
249
250class SparseHistInfo : public Info
251{
252  public:
253    /** Local storage for the entry values, used for printing. */
254    SparseHistData data;
255};
256
257} // namespace Stats
258
259#endif // __BASE_STATS_INFO_HH__
260