info.hh revision 8229:78bf55f23338
114039Sstacze01@arm.com/*
214039Sstacze01@arm.com * Copyright (c) 2003-2005 The Regents of The University of Michigan
314039Sstacze01@arm.com * All rights reserved.
414039Sstacze01@arm.com *
514039Sstacze01@arm.com * Redistribution and use in source and binary forms, with or without
614039Sstacze01@arm.com * modification, are permitted provided that the following conditions are
714039Sstacze01@arm.com * met: redistributions of source code must retain the above copyright
814039Sstacze01@arm.com * notice, this list of conditions and the following disclaimer;
914039Sstacze01@arm.com * redistributions in binary form must reproduce the above copyright
1014039Sstacze01@arm.com * notice, this list of conditions and the following disclaimer in the
1114039Sstacze01@arm.com * documentation and/or other materials provided with the distribution;
1214039Sstacze01@arm.com * neither the name of the copyright holders nor the names of its
1314039Sstacze01@arm.com * contributors may be used to endorse or promote products derived from
1414039Sstacze01@arm.com * this software without specific prior written permission.
1514039Sstacze01@arm.com *
1614039Sstacze01@arm.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1714039Sstacze01@arm.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1814039Sstacze01@arm.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1914039Sstacze01@arm.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2014039Sstacze01@arm.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2114039Sstacze01@arm.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2214039Sstacze01@arm.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2314039Sstacze01@arm.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2414039Sstacze01@arm.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2514039Sstacze01@arm.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2614039Sstacze01@arm.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2714039Sstacze01@arm.com *
2814039Sstacze01@arm.com * Authors: Nathan Binkert
2914039Sstacze01@arm.com */
3014039Sstacze01@arm.com
3114039Sstacze01@arm.com#ifndef __BASE_STATS_INFO_HH__
3214039Sstacze01@arm.com#define __BASE_STATS_INFO_HH__
3314039Sstacze01@arm.com
3414039Sstacze01@arm.com#include "base/stats/types.hh"
3514039Sstacze01@arm.com#include "base/flags.hh"
3614039Sstacze01@arm.com
3714039Sstacze01@arm.comnamespace Stats {
3814039Sstacze01@arm.com
3914039Sstacze01@arm.comtypedef uint16_t FlagsType;
4014039Sstacze01@arm.comtypedef ::Flags<FlagsType> Flags;
4114039Sstacze01@arm.com
4214039Sstacze01@arm.com/** Nothing extra to print. */
4314039Sstacze01@arm.comconst FlagsType none =          0x0000;
4414039Sstacze01@arm.com/** This Stat is Initialized */
4514039Sstacze01@arm.comconst FlagsType init =          0x0001;
4614039Sstacze01@arm.com/** Print this stat. */
4714039Sstacze01@arm.comconst FlagsType display =       0x0002;
4814039Sstacze01@arm.com/** Print the total. */
4914039Sstacze01@arm.comconst FlagsType total =         0x0010;
5014039Sstacze01@arm.com/** Print the percent of the total that this entry represents. */
5114039Sstacze01@arm.comconst FlagsType pdf =           0x0020;
5214039Sstacze01@arm.com/** Print the cumulative percentage of total upto this entry. */
5314039Sstacze01@arm.comconst FlagsType cdf =           0x0040;
5414039Sstacze01@arm.com/** Print the distribution. */
5514039Sstacze01@arm.comconst FlagsType dist =          0x0080;
5614039Sstacze01@arm.com/** Don't print if this is zero. */
5714039Sstacze01@arm.comconst FlagsType nozero =        0x0100;
5814039Sstacze01@arm.com/** Don't print if this is NAN */
5914039Sstacze01@arm.comconst FlagsType nonan =         0x0200;
6014039Sstacze01@arm.com
6114039Sstacze01@arm.com/** Mask of flags that can't be set directly */
6214039Sstacze01@arm.comconst FlagsType __reserved =    init | display;
6314039Sstacze01@arm.com
6414039Sstacze01@arm.comstruct StorageParams;
6514039Sstacze01@arm.comstruct Visit;
6614039Sstacze01@arm.com
6714039Sstacze01@arm.comclass Info
6814039Sstacze01@arm.com{
6914039Sstacze01@arm.com  public:
7014086Sgiacomo.travaglini@arm.com    /** The name of the stat. */
7114039Sstacze01@arm.com    std::string name;
7214039Sstacze01@arm.com    /** The description of the stat. */
7314039Sstacze01@arm.com    std::string desc;
7414039Sstacze01@arm.com    /** The formatting flags. */
7514039Sstacze01@arm.com    Flags flags;
7614039Sstacze01@arm.com    /** The display precision. */
7714039Sstacze01@arm.com    int precision;
7814039Sstacze01@arm.com    /** A pointer to a prerequisite Stat. */
7914039Sstacze01@arm.com    const Info *prereq;
8014039Sstacze01@arm.com    /**
8114039Sstacze01@arm.com     * A unique stat ID for each stat in the simulator.
8214039Sstacze01@arm.com     * Can be used externally for lookups as well as for debugging.
8314039Sstacze01@arm.com     */
8414039Sstacze01@arm.com    static int id_count;
8514039Sstacze01@arm.com    int id;
8614039Sstacze01@arm.com
8714039Sstacze01@arm.com  public:
8814039Sstacze01@arm.com    const StorageParams *storageParams;
8914039Sstacze01@arm.com
9014039Sstacze01@arm.com  public:
9114039Sstacze01@arm.com    Info();
9214039Sstacze01@arm.com    virtual ~Info();
9314039Sstacze01@arm.com
9414039Sstacze01@arm.com    /** Set the name of this statistic */
9514039Sstacze01@arm.com    void setName(const std::string &name);
9614039Sstacze01@arm.com
9714039Sstacze01@arm.com    /**
9814039Sstacze01@arm.com     * Check that this stat has been set up properly and is ready for
9914039Sstacze01@arm.com     * use
10014039Sstacze01@arm.com     * @return true for success
10114039Sstacze01@arm.com     */
10214039Sstacze01@arm.com    virtual bool check() const = 0;
10314039Sstacze01@arm.com    bool baseCheck() const;
10414039Sstacze01@arm.com
10514039Sstacze01@arm.com    /**
10614039Sstacze01@arm.com     * Enable the stat for use
10714039Sstacze01@arm.com     */
10814039Sstacze01@arm.com    virtual void enable();
10914039Sstacze01@arm.com
11014039Sstacze01@arm.com    /**
11114039Sstacze01@arm.com     * Prepare the stat for dumping.
11214039Sstacze01@arm.com     */
11314039Sstacze01@arm.com    virtual void prepare() = 0;
11414039Sstacze01@arm.com
11514039Sstacze01@arm.com    /**
11614039Sstacze01@arm.com     * Reset the stat to the default state.
11714039Sstacze01@arm.com     */
11814039Sstacze01@arm.com    virtual void reset() = 0;
11914039Sstacze01@arm.com
12014039Sstacze01@arm.com    /**
12114039Sstacze01@arm.com     * @return true if this stat has a value and satisfies its
12214039Sstacze01@arm.com     * requirement as a prereq
12314039Sstacze01@arm.com     */
12414039Sstacze01@arm.com    virtual bool zero() const = 0;
12514039Sstacze01@arm.com
12614039Sstacze01@arm.com    /**
12714039Sstacze01@arm.com     * Visitor entry for outputing statistics data
12814039Sstacze01@arm.com     */
12914039Sstacze01@arm.com    virtual void visit(Visit &visitor) = 0;
13014039Sstacze01@arm.com
13114039Sstacze01@arm.com    /**
13214039Sstacze01@arm.com     * Checks if the first stat's name is alphabetically less than the second.
13314039Sstacze01@arm.com     * This function breaks names up at periods and considers each subname
13414039Sstacze01@arm.com     * separately.
13514039Sstacze01@arm.com     * @param stat1 The first stat.
13614039Sstacze01@arm.com     * @param stat2 The second stat.
13714039Sstacze01@arm.com     * @return stat1's name is alphabetically before stat2's
13814039Sstacze01@arm.com     */
13914039Sstacze01@arm.com    static bool less(Info *stat1, Info *stat2);
14014039Sstacze01@arm.com};
14114039Sstacze01@arm.com
14214039Sstacze01@arm.comclass ScalarInfo : public Info
14314039Sstacze01@arm.com{
14414039Sstacze01@arm.com  public:
14514039Sstacze01@arm.com    virtual Counter value() const = 0;
14614039Sstacze01@arm.com    virtual Result result() const = 0;
14714039Sstacze01@arm.com    virtual Result total() const = 0;
14814039Sstacze01@arm.com};
14914039Sstacze01@arm.com
15014039Sstacze01@arm.comclass VectorInfo : public Info
15114039Sstacze01@arm.com{
15214039Sstacze01@arm.com  public:
15314039Sstacze01@arm.com    /** Names and descriptions of subfields. */
15414039Sstacze01@arm.com    std::vector<std::string> subnames;
15514039Sstacze01@arm.com    std::vector<std::string> subdescs;
15614039Sstacze01@arm.com
15714039Sstacze01@arm.com  public:
15814039Sstacze01@arm.com    void enable();
15914039Sstacze01@arm.com
16014039Sstacze01@arm.com  public:
16114039Sstacze01@arm.com    virtual size_type size() const = 0;
16214039Sstacze01@arm.com    virtual const VCounter &value() const = 0;
16314039Sstacze01@arm.com    virtual const VResult &result() const = 0;
16414039Sstacze01@arm.com    virtual Result total() const = 0;
16514039Sstacze01@arm.com};
16614039Sstacze01@arm.com
16714039Sstacze01@arm.comenum DistType { Deviation, Dist, Hist };
16814039Sstacze01@arm.com
16914039Sstacze01@arm.comstruct DistData
17014039Sstacze01@arm.com{
17114039Sstacze01@arm.com    DistType type;
17214039Sstacze01@arm.com    Counter min;
17314039Sstacze01@arm.com    Counter max;
17414039Sstacze01@arm.com    Counter bucket_size;
17514039Sstacze01@arm.com
17614039Sstacze01@arm.com    Counter min_val;
17714039Sstacze01@arm.com    Counter max_val;
17814039Sstacze01@arm.com    Counter underflow;
17914039Sstacze01@arm.com    Counter overflow;
18014039Sstacze01@arm.com    VCounter cvec;
18114039Sstacze01@arm.com    Counter sum;
18214039Sstacze01@arm.com    Counter squares;
18314039Sstacze01@arm.com    Counter samples;
18414039Sstacze01@arm.com};
18514039Sstacze01@arm.com
18614039Sstacze01@arm.comclass DistInfo : public Info
18714039Sstacze01@arm.com{
18814039Sstacze01@arm.com  public:
18914039Sstacze01@arm.com    /** Local storage for the entry values, used for printing. */
19014039Sstacze01@arm.com    DistData data;
19114039Sstacze01@arm.com};
19214039Sstacze01@arm.com
19314039Sstacze01@arm.comclass VectorDistInfo : public Info
19414039Sstacze01@arm.com{
19514039Sstacze01@arm.com  public:
19614039Sstacze01@arm.com    std::vector<DistData> data;
19714039Sstacze01@arm.com
19814039Sstacze01@arm.com    /** Names and descriptions of subfields. */
19914039Sstacze01@arm.com    std::vector<std::string> subnames;
20014039Sstacze01@arm.com    std::vector<std::string> subdescs;
20114039Sstacze01@arm.com    void enable();
20214039Sstacze01@arm.com
20314039Sstacze01@arm.com  protected:
20414039Sstacze01@arm.com    /** Local storage for the entry values, used for printing. */
20514039Sstacze01@arm.com    mutable VResult rvec;
20614039Sstacze01@arm.com
20714039Sstacze01@arm.com  public:
20814039Sstacze01@arm.com    virtual size_type size() const = 0;
20914039Sstacze01@arm.com};
21014039Sstacze01@arm.com
21114039Sstacze01@arm.comclass Vector2dInfo : public Info
21214039Sstacze01@arm.com{
21314039Sstacze01@arm.com  public:
21414039Sstacze01@arm.com    /** Names and descriptions of subfields. */
21514039Sstacze01@arm.com    std::vector<std::string> subnames;
21614039Sstacze01@arm.com    std::vector<std::string> subdescs;
21714039Sstacze01@arm.com    std::vector<std::string> y_subnames;
21814039Sstacze01@arm.com
21914039Sstacze01@arm.com    size_type x;
22014039Sstacze01@arm.com    size_type y;
22114039Sstacze01@arm.com
22214039Sstacze01@arm.com    /** Local storage for the entry values, used for printing. */
22314039Sstacze01@arm.com    mutable VCounter cvec;
22414039Sstacze01@arm.com
22514039Sstacze01@arm.com    void enable();
22614039Sstacze01@arm.com};
22714039Sstacze01@arm.com
22814039Sstacze01@arm.comclass FormulaInfo : public VectorInfo
22914039Sstacze01@arm.com{
23014039Sstacze01@arm.com  public:
23114039Sstacze01@arm.com    virtual std::string str() const = 0;
23214039Sstacze01@arm.com};
23314039Sstacze01@arm.com
23414039Sstacze01@arm.com
23514039Sstacze01@arm.com} // namespace Stats
23614039Sstacze01@arm.com
23714039Sstacze01@arm.com#endif // __BASE_STATS_INFO_HH__
23814039Sstacze01@arm.com