info.hh revision 6130
11689SN/A/*
29444SAndreas.Sandberg@ARM.com * Copyright (c) 2003-2005 The Regents of The University of Michigan
39444SAndreas.Sandberg@ARM.com * All rights reserved.
49444SAndreas.Sandberg@ARM.com *
59444SAndreas.Sandberg@ARM.com * Redistribution and use in source and binary forms, with or without
69444SAndreas.Sandberg@ARM.com * modification, are permitted provided that the following conditions are
79444SAndreas.Sandberg@ARM.com * met: redistributions of source code must retain the above copyright
89444SAndreas.Sandberg@ARM.com * notice, this list of conditions and the following disclaimer;
99444SAndreas.Sandberg@ARM.com * redistributions in binary form must reproduce the above copyright
109444SAndreas.Sandberg@ARM.com * notice, this list of conditions and the following disclaimer in the
119444SAndreas.Sandberg@ARM.com * documentation and/or other materials provided with the distribution;
129444SAndreas.Sandberg@ARM.com * neither the name of the copyright holders nor the names of its
139444SAndreas.Sandberg@ARM.com * contributors may be used to endorse or promote products derived from
142329SN/A * this software without specific prior written permission.
151689SN/A *
161689SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
171689SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
181689SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
191689SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
201689SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
211689SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
221689SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
231689SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
241689SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
251689SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
261689SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
271689SN/A *
281689SN/A * Authors: Nathan Binkert
291689SN/A */
301689SN/A
311689SN/A#include "base/flags.hh"
321689SN/A#include "base/stats/types.hh"
331689SN/A
341689SN/Anamespace Stats {
351689SN/A
361689SN/Atypedef uint16_t FlagsType;
371689SN/Atypedef ::Flags<FlagsType> Flags;
381689SN/A
392665Ssaidi@eecs.umich.edu/** Nothing extra to print. */
402665Ssaidi@eecs.umich.educonst FlagsType none =          0x0000;
411689SN/A/** This Stat is Initialized */
421060SN/Aconst FlagsType init =          0x0001;
432292SN/A/** Print this stat. */
442292SN/Aconst FlagsType print =         0x0002;
451060SN/A/** Print the total. */
461060SN/Aconst FlagsType total =         0x0010;
471060SN/A/** Print the percent of the total that this entry represents. */
481461SN/Aconst FlagsType pdf =           0x0020;
497813Ssteve.reinhardt@amd.com/** Print the cumulative percentage of total upto this entry. */
501060SN/Aconst FlagsType cdf =           0x0040;
518737Skoansin.tan@gmail.com/** Print the distribution. */
525529Snate@binkert.orgconst FlagsType dist =          0x0080;
532292SN/A/** Don't print if this is zero. */
542329SN/Aconst FlagsType nozero =        0x0100;
552329SN/A/** Don't print if this is NAN */
562329SN/Aconst FlagsType nonan =         0x0200;
572329SN/A/** Used for SS compatability. */
582329SN/Aconst FlagsType __substat =     0x8000;
592292SN/A
601060SN/A/** Mask of flags that can't be set directly */
612292SN/Aconst FlagsType __reserved =    init | print | __substat;
621060SN/A
631060SN/Astruct StorageParams
641060SN/A{
652733Sktlim@umich.edu    virtual ~StorageParams();
661061SN/A};
671061SN/A
681060SN/Astruct Visit;
691061SN/A
701061SN/Aclass Info
711061SN/A{
721061SN/A  public:
731060SN/A    /** The name of the stat. */
741060SN/A    std::string name;
752292SN/A    /** The description of the stat. */
762292SN/A    std::string desc;
772292SN/A    /** The formatting flags. */
782292SN/A    Flags flags;
792292SN/A    /** The display precision. */
802292SN/A    int precision;
812292SN/A    /** A pointer to a prerequisite Stat. */
822292SN/A    const Info *prereq;
832292SN/A    /**
842292SN/A     * A unique stat ID for each stat in the simulator.
851060SN/A     * Can be used externally for lookups as well as for debugging.
861060SN/A     */
872292SN/A    static int id_count;
881060SN/A    int id;
891060SN/A
901060SN/A  public:
911060SN/A    const StorageParams *storageParams;
921060SN/A
931060SN/A  public:
942292SN/A    Info();
952292SN/A    virtual ~Info();
962292SN/A
972292SN/A    /** Set the name of this statistic */
982292SN/A    void setName(const std::string &name);
991060SN/A
1001060SN/A    /**
1012292SN/A     * Check that this stat has been set up properly and is ready for
1025529Snate@binkert.org     * use
1031060SN/A     * @return true for success
1049444SAndreas.Sandberg@ARM.com     */
1059444SAndreas.Sandberg@ARM.com    virtual bool check() const = 0;
1069444SAndreas.Sandberg@ARM.com    bool baseCheck() const;
1072292SN/A
1082292SN/A    /**
1092292SN/A     * Enable the stat for use
1102292SN/A     */
1111062SN/A    virtual void enable();
1121062SN/A
1132292SN/A    /**
1141060SN/A     * Prepare the stat for dumping.
1151060SN/A     */
1162292SN/A    virtual void prepare() = 0;
1171060SN/A
1181060SN/A    /**
1192292SN/A     * Reset the stat to the default state.
1201060SN/A     */
1211060SN/A    virtual void reset() = 0;
1222292SN/A
1236221Snate@binkert.org    /**
1242292SN/A     * @return true if this stat has a value and satisfies its
1259444SAndreas.Sandberg@ARM.com     * requirement as a prereq
1269444SAndreas.Sandberg@ARM.com     */
1272843Sktlim@umich.edu    virtual bool zero() const = 0;
1289444SAndreas.Sandberg@ARM.com
1299444SAndreas.Sandberg@ARM.com    /**
1302307SN/A     * Visitor entry for outputing statistics data
1312348SN/A     */
1329444SAndreas.Sandberg@ARM.com    virtual void visit(Visit &visitor) = 0;
1332348SN/A
1342292SN/A    /**
1352292SN/A     * Checks if the first stat's name is alphabetically less than the second.
1362292SN/A     * This function breaks names up at periods and considers each subname
1371060SN/A     * separately.
1381060SN/A     * @param stat1 The first stat.
1392292SN/A     * @param stat2 The second stat.
1402292SN/A     * @return stat1's name is alphabetically before stat2's
1412292SN/A     */
1422292SN/A    static bool less(Info *stat1, Info *stat2);
1432292SN/A};
1446221Snate@binkert.org
1452292SN/Aclass ScalarInfo : public Info
1462292SN/A{
1472292SN/A  public:
1482292SN/A    virtual Counter value() const = 0;
1492292SN/A    virtual Result result() const = 0;
1502292SN/A    virtual Result total() const = 0;
1516221Snate@binkert.org};
1521060SN/A
1531060SN/Aclass VectorInfo : public Info
1542292SN/A{
1552292SN/A  public:
1562292SN/A    /** Names and descriptions of subfields. */
1576221Snate@binkert.org    std::vector<std::string> subnames;
1582292SN/A    std::vector<std::string> subdescs;
1592292SN/A
1602292SN/A  public:
1612292SN/A    void enable();
1622292SN/A
1632292SN/A  public:
1642292SN/A    virtual size_type size() const = 0;
1652292SN/A    virtual const VCounter &value() const = 0;
1662292SN/A    virtual const VResult &result() const = 0;
1672292SN/A    virtual Result total() const = 0;
1682292SN/A};
1692292SN/A
1702292SN/Astruct DistData
1716221Snate@binkert.org{
1722292SN/A    Counter min_val;
1732292SN/A    Counter max_val;
1746221Snate@binkert.org    Counter underflow;
1752292SN/A    Counter overflow;
1762292SN/A    VCounter cvec;
1776221Snate@binkert.org    Counter sum;
1782292SN/A    Counter squares;
1792292SN/A    Counter samples;
1801681SN/A};
1811681SN/A
1822292SN/Astruct DistParams : public StorageParams
1832292SN/A{
1842292SN/A    const bool fancy;
1852292SN/A
1866221Snate@binkert.org    /** The minimum value to track. */
1871060SN/A    Counter min;
1882292SN/A    /** The maximum value to track. */
1892292SN/A    Counter max;
1902292SN/A    /** The number of entries in each bucket. */
1912292SN/A    Counter bucket_size;
1926221Snate@binkert.org    /** The number of buckets. Equal to (max-min)/bucket_size. */
1931060SN/A    size_type buckets;
1942292SN/A
1952292SN/A    explicit DistParams(bool f) : fancy(f) {}
1962292SN/A};
1976221Snate@binkert.org
1981060SN/Aclass DistInfo : public Info
1991684SN/A{
2002292SN/A  public:
2012292SN/A    /** Local storage for the entry values, used for printing. */
2022292SN/A    DistData data;
2036221Snate@binkert.org};
2041681SN/A
2051684SN/Aclass VectorDistInfo : public Info
2061060SN/A{
2071060SN/A  public:
2082733Sktlim@umich.edu    std::vector<DistData> data;
2091060SN/A
2101060SN/A    /** Names and descriptions of subfields. */
2111060SN/A    std::vector<std::string> subnames;
2121060SN/A    std::vector<std::string> subdescs;
2131060SN/A    void enable();
2141060SN/A
2151060SN/A  protected:
2161060SN/A    /** Local storage for the entry values, used for printing. */
2171060SN/A    mutable VResult rvec;
2181060SN/A
2191060SN/A  public:
2201060SN/A    virtual size_type size() const = 0;
2211060SN/A};
2221060SN/A
2231060SN/Aclass Vector2dInfo : public Info
2241060SN/A{
2251060SN/A  public:
2261060SN/A    /** Names and descriptions of subfields. */
2271060SN/A    std::vector<std::string> subnames;
2281060SN/A    std::vector<std::string> subdescs;
2291060SN/A    std::vector<std::string> y_subnames;
2301060SN/A
2311060SN/A    size_type x;
2321060SN/A    size_type y;
2331060SN/A
2341060SN/A    /** Local storage for the entry values, used for printing. */
2351060SN/A    mutable VCounter cvec;
2361060SN/A
2371060SN/A    void enable();
2382292SN/A};
2392292SN/A
2402292SN/Aclass FormulaInfo : public VectorInfo
2411060SN/A{
2422292SN/A  public:
2431060SN/A    virtual std::string str() const = 0;
2442292SN/A};
2452292SN/A
2462292SN/A
2472292SN/A/* namespace Stats */ }
2482292SN/A