stats.h

Go to the documentation of this file.
00001 /*
00002  * See the dyninst/COPYRIGHT file for copyright information.
00003  * 
00004  * We provide the Paradyn Tools (below described as "Paradyn")
00005  * on an AS IS basis, and do not warrant its validity or performance.
00006  * We reserve the right to update, modify, or discontinue this
00007  * software at any time.  We shall have no obligation to supply such
00008  * updates or modifications or any other form of support to you.
00009  * 
00010  * By your use of Paradyn, you understand and agree that we (or any
00011  * other person or entity with proprietary rights in Paradyn) are
00012  * under no obligation to provide either maintenance services,
00013  * update services, notices of latent defects, or correction of
00014  * defects for Paradyn.
00015  * 
00016  * This library is free software; you can redistribute it and/or
00017  * modify it under the terms of the GNU Lesser General Public
00018  * License as published by the Free Software Foundation; either
00019  * version 2.1 of the License, or (at your option) any later version.
00020  * 
00021  * This library is distributed in the hope that it will be useful,
00022  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00023  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00024  * Lesser General Public License for more details.
00025  * 
00026  * You should have received a copy of the GNU Lesser General Public
00027  * License along with this library; if not, write to the Free Software
00028  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00029  */
00030 
00031 // $Id: stats.h,v 1.3 2008/09/03 06:08:43 jaw Exp $
00032 
00033 #ifndef STATS_H
00034 #define STATS_H
00035 
00036 #include <string>
00037 //#include "Dictionary.h"
00038 #include "Timer.h"
00039 #include "dynutil/h/util.h"
00040 
00041 #if 0
00042 extern void printDyninstStats();
00043 
00044 class CntStatistic;
00045 
00046 extern CntStatistic insnGenerated;
00047 extern CntStatistic totalMiniTramps;
00048 extern CntStatistic trampBytes;
00049 extern CntStatistic ptraceOps;
00050 extern CntStatistic ptraceOtherOps;
00051 extern CntStatistic ptraceBytes;
00052 extern CntStatistic pointsUsed;
00053 
00054 #endif
00055 class StatContainer;  // All your class declarations are forward. 
00056 
00057 class COMMON_EXPORT Statistic  {
00058  public:
00059     virtual bool is_count()  { return false; }
00060     virtual bool is_timer()  { return false; }
00061     /* ... etc. */
00062 
00063     // dynamic_casts are a pain in the neck
00064     virtual long int value() { return 0; }
00065     virtual double usecs()  { return 0; }
00066     virtual double ssecs() { return 0; }
00067     virtual double wsecs() { return 0; }
00068 
00069 
00070  protected:
00071     Statistic(StatContainer *c) : 
00072         container_(c)
00073     { }
00074     virtual ~Statistic() {}; // Avoid warnings
00075 
00076     StatContainer *container_;
00077 
00078     // 
00079     bool valid;
00080 };
00081 
00082 class COMMON_EXPORT CntStatistic : public Statistic {
00083  friend class StatContainer;
00084 
00085  protected:
00086     // Constructor with which a StatContainer provides
00087     // this statistic with an up-pointer to itself
00088     CntStatistic(StatContainer *c) :
00089         Statistic(c),
00090         cnt_(0)
00091     { }
00092 
00093  public:
00094     CntStatistic() : 
00095         Statistic(NULL),
00096         cnt_(0)
00097     { }
00098 
00099     // respond appropriately to type-of-stat requests
00100     bool is_count() { return true; }
00101 
00102     /** overloaded operators **/
00103     CntStatistic operator++( int );
00104     CntStatistic& operator++();
00105 
00106     CntStatistic operator--( int );
00107     CntStatistic& operator--();  
00108 
00109     CntStatistic& operator=( long int );
00110     CntStatistic& operator=( CntStatistic &);
00111 
00112     CntStatistic& operator+=( long int );
00113     CntStatistic& operator+=( CntStatistic &);
00114     
00115     CntStatistic& operator-=( long int );
00116     CntStatistic& operator-=(  CntStatistic &);
00117 
00118     // Return the value of this statistic
00119     long int operator*();
00120     long int value();
00121 
00122  private:
00123     long int cnt_;
00124 };
00125 
00126 /* Wraps the timer class */
00127 class COMMON_EXPORT TimeStatistic : public Statistic {
00128  friend class StatContainer;
00129 
00130  protected:
00131     TimeStatistic(StatContainer *c) :
00132         Statistic(c)
00133     {}
00134 
00135  public:
00136     TimeStatistic() :
00137         Statistic(NULL)
00138     {}
00139 
00140     bool is_timer()  { return true; }
00141 
00142     TimeStatistic& operator=( TimeStatistic &);
00143     TimeStatistic& operator+=( TimeStatistic &);
00144     TimeStatistic& operator+( TimeStatistic &) ;
00145 
00146     void clear();
00147     void start();
00148     void stop();
00149 
00150     double usecs() ;
00151     double ssecs() ;
00152     double wsecs() ;
00153 
00154     bool is_running() ;
00155 
00156  private:
00157 
00158     timer t_;
00159 };
00160 
00161 typedef enum {
00162     CountStat,
00163     TimerStat
00164 } StatType;
00165 
00166 
00167 /* A container for a group of (one expects) mutually related statistics. */
00168 class StatContainer {
00169  public:
00170     COMMON_EXPORT StatContainer(); 
00171 
00172     /* Access or create a statistic indexed by the provided name.
00173      *
00174      * This operator may return null if the named statistic does
00175      * not exist.
00176      */
00177     COMMON_EXPORT Statistic * operator[](std::string &);
00178     COMMON_EXPORT Statistic * operator[](const char *s) {
00179        std::string namestr(s);
00180        return (*this)[namestr];
00181     }
00182 
00183     // Create a new statistic of the given type indexed by name.
00184     // **This will replace any existing stat with the same index
00185     //   within this container**
00186     COMMON_EXPORT void add(std::string name, StatType type);
00187 
00188     // Access all of the existing statistics
00189     COMMON_EXPORT dyn_hash_map< std::string, Statistic * > &
00190        allStats() { return stats_; }
00191 
00192     // And some pass-through methods, encapsulated for
00193     // ease of use
00194     COMMON_EXPORT void startTimer(std::string);
00195     COMMON_EXPORT void stopTimer(std::string);
00196     COMMON_EXPORT void incrementCounter(std::string);
00197     COMMON_EXPORT void decrementCounter(std::string);
00198     COMMON_EXPORT void addCounter(std::string, int);
00199 
00200  private:
00201     dyn_hash_map< std::string, Statistic * > stats_;
00202 
00203 };
00204 #endif
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 12 Jul 2013 for SymtabAPI by  doxygen 1.6.1