src/Utility/IpplStats.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 /***************************************************************************
00003  *
00004  * The IPPL Framework
00005  * 
00006  *
00007  * Visit http://people.web.psi.ch/adelmann/ for more details
00008  *
00009  ***************************************************************************/
00010 
00011 #ifndef IPPL_STATS_H
00012 #define IPPL_STATS_H
00013 
00014 /***************************************************************************
00015  * IpplStats keeps statistics about a given IPPL job, and can report on
00016  * a summary of these statistics when asked.
00017  *
00018  * To add a new type of statistic, do these steps:
00019  *   1. Add a new private variable to accumulate the stats
00020  *   2. Add a new public method to call to add values to the stat
00021  *   3. In the constructor, initialize the stats object with a name in the
00022  *      colon-initializer list.
00023  *   4. Add commands to the rest of ippl to change the stat as needed.
00024  *      Example:
00025  *                 #ifndef IPPL_NO_STATS
00026  *                 Ippl::Stats.incMessageSent();
00027  *                 #endif
00028  *
00029  * This interface is extensible ... you can add new types of statistics
00030  * by calling 'addStat(description, initval)' with a string description
00031  * of the stat, and the initial value it should have.  This will return a
00032  * unique integer identifier for that stat.  Then, you can modify the stat
00033  * by calling incStat(statindex, amount) and decStat(statindex, amount).
00034  * At the end, then, this statistic will be printed out just like all the
00035  * others.
00036  ***************************************************************************/
00037 
00038 // include files
00039 #include "Utility/IpplInfo.h"
00040 #include "Utility/Timer.h"
00041 #include "Utility/Inform.h"
00042 #include "Utility/Pstring.h"
00043 
00044 #ifdef IPPL_STDSTL
00045 #include <vector>
00046 using std::vector;
00047 #else
00048 #include <vector.h>
00049 #endif
00050 
00051 
00052 class IpplStats {
00053 
00054 public:
00055   // constructor: initialize statistics, and start run timer
00056   IpplStats();
00057 
00058   // destructor
00059   ~IpplStats();
00060 
00061   // print out the statistics to the given Inform object
00062   void print(Inform &);
00063 
00064   // add a statistics object to our list of stats ... return an integer
00065   // which is the index of the stat in our list, which can be used with
00066   // the 'incStat' and 'decStat' methods to change that statistic
00067   int addStat(const char *description, long initval = 0) {
00068     StatList.push_back(new StatData(description, initval, true));
00069     return (StatList.size() - 1);
00070   }
00071 
00072   // increment or decrement the statistic by the given value.  Return the
00073   // current value
00074   long incStat(int statindx, long val = 1) {
00075     StatList[statindx]->Value += val;
00076     return StatList[statindx]->Value;
00077   }
00078   long decStat(int statindx, long val = 1) {
00079     StatList[statindx]->Value -= val;
00080     return StatList[statindx]->Value;
00081   }
00082 
00083   //
00084   // general IPPL operation information
00085   //
00086 
00087   // return a ref to the timer, so that it can be turned on and off
00088   Timer &getTime() { return Time; }
00089 
00090   //
00091   // communication statistics operations
00092   //
00093 
00094   void incMessageSent() { ++MessagesSent.Value; }
00095   void incMessageSentToOthers() { ++MessagesSentToOthers.Value; }
00096   void incMessageSentToSelf() { ++MessagesSentToSelf.Value; }
00097   void incMessageReceived() { ++MessagesReceived.Value; }
00098   void incMessageReceivedFromNetwork() { ++MessagesReceivedFromNetwork.Value;}
00099   void incMessageReceivedFromQueue() { ++MessagesReceivedFromQueue.Value; }
00100   void incMessageReceiveChecks() { ++MessageReceiveChecks.Value; }
00101   void incMessageReceiveChecksFailed() { ++MessageReceiveChecksFailed.Value; }
00102   void incMessageBytesSent(long bytes) { BytesSent.Value += bytes; }
00103   void incMessageBytesReceived(long bytes) { BytesReceived.Value += bytes; }
00104   void incBarriers() { ++Barriers.Value; }
00105   void incReductions() { ++Reductions.Value; }
00106   void incScatters() { ++Scatters.Value; }
00107 
00108   //
00109   // BareField statistics operations
00110   //
00111 
00112   void incBareFields() { ++BareFields.Value; }
00113   void incLFields() { ++LFields.Value; }
00114   void incLFieldBytes(long bytes) { LFieldBytes.Value += bytes; }
00115   void incFieldLayouts() { ++FieldLayouts.Value; }
00116   void incRepartitions() { ++Repartitions.Value; }
00117   void incExpressions()            { ++Expressions.Value; }
00118   void incBFEqualsExpression()     { ++BFEqualsExpression.Value; }
00119   void incIBFEqualsExpression()    { ++IBFEqualsExpression.Value; }
00120   void incParensEqualsExpression() { ++ParensEqualsExpression.Value; }
00121   void incBFEqualsBF()             { ++BFEqualsBF.Value; }
00122   void incIBFEqualsIBF()           { ++IBFEqualsIBF.Value; }
00123   void incSubEqualsExpression()    { ++SubEqualsExpression.Value; }
00124   void incFFTs() { ++FFTs.Value; }
00125   void incGuardCellFills() { ++GuardCellFills.Value; }
00126   void incBoundaryConditions() { ++BoundaryConditions.Value; }
00127   void incCompresses() { ++Compresses.Value; }
00128   void incDecompresses() { ++Decompresses.Value; }
00129   void incCompressionCompares(long c) { CompressionCompares.Value += c; }
00130   void incCompressionCompareMax(long c) { CompressionCompareMax.Value += c; }
00131   void incBareFieldIterators() { ++BareFieldIterators.Value; }
00132   void incDefaultBareFieldIterators() { ++DefaultBareFieldIterators.Value; }
00133   void incBeginScalarCodes() { ++BeginScalarCodes.Value; }
00134   void incEndScalarCodes() { ++EndScalarCodes.Value; }
00135   //
00136   // Particle statistics operations
00137   //
00138 
00139   void incParticleAttribs() { ++ParticleAttribs.Value; }
00140   void incParticleBases() { ++ParticleBases.Value; }
00141   void incParticleUpdates() { ++ParticleUpdates.Value; }
00142   void incParticleExpressions() { ++ParticleExpressions.Value; }
00143   void incParticleGathers() { ++ParticleGathers.Value; }
00144   void incParticleScatters() { ++ParticleScatters.Value; }
00145   void incParticlesCreated(long num) { ParticlesCreated.Value += num; }
00146   void incParticlesDestroyed(long num) { ParticlesDestroyed.Value += num; }
00147   void incParticlesSwapped(long num) { ParticlesSwapped.Value += num; }
00148 
00149   //
00150   // I/O statistics
00151   //
00152 
00153   void incDiscReads() { ++DiscReads.Value; }
00154   void incDiscWrites() { ++DiscWrites.Value; }
00155   void incDiscFilesetReads(long f) { DiscFilesetReads.Value += f; }
00156   void incDiscFilesetWrites(long f) { DiscFilesetWrites.Value += f; }
00157   void incDiscBytesRead(long b) { DiscBytesRead.Value += b; }
00158   void incDiscBytesWritten(long b) { DiscBytesWritten.Value += b; }
00159 
00160 private:
00161   // a simple object used to accumulate a stat, with a name.
00162   struct StatData {
00163     // constructor
00164     StatData(vector<StatData *> &datalist, const char *nm, long initval = 0,
00165              bool needDelete = false)
00166       : Value(initval), Name(nm), NeedDelete(needDelete) {
00167       // add ourselves to the list of statistics objects
00168       datalist.push_back(this);
00169     }
00170 
00171     // another constructor, without the vector
00172     StatData(const char *nm, long initval = 0, bool needDelete = false)
00173       : Value(initval), Name(nm), NeedDelete(needDelete) { }
00174 
00175     // default constructor
00176     StatData() : Value(0), Name("") { }
00177 
00178     // destructor
00179     ~StatData() { }
00180 
00181     // value and name
00182     long   Value;
00183     string Name;
00184 
00185     // if this is true, we need to be deleted by the Stats class
00186     bool NeedDelete;
00187   };
00188 
00189   // a vector of statistics data objects, which will be used to print
00190   // out the results at the end.  All stats should be declared as StatData
00191   // variables below; in their constructor, they will put themselves in the
00192   // list of statistics objects.
00193   vector<StatData *> StatList;
00194 
00195   // a timer to time the whole program (although other timers may certainly be
00196   // created throughout the program)
00197   Timer Time;
00198 
00199   // build-in ippl statistics objects
00200   StatData MessagesSent;
00201   StatData MessagesSentToOthers;
00202   StatData MessagesSentToSelf;
00203   StatData MessagesReceived;
00204   StatData MessagesReceivedFromNetwork;
00205   StatData MessagesReceivedFromQueue;
00206   StatData MessageReceiveChecks;
00207   StatData MessageReceiveChecksFailed;
00208   StatData BytesSent;
00209   StatData BytesReceived;
00210   StatData Barriers;
00211   StatData Reductions;
00212   StatData Scatters;
00213 
00214   StatData BareFields;
00215   StatData LFields;
00216   StatData LFieldBytes;
00217   StatData FieldLayouts;
00218   StatData Repartitions;
00219   StatData Expressions;
00220   StatData BFEqualsExpression;
00221   StatData IBFEqualsExpression;
00222   StatData ParensEqualsExpression;
00223   StatData BFEqualsBF;
00224   StatData IBFEqualsIBF;
00225   StatData SubEqualsExpression;
00226   StatData FFTs;
00227   StatData GuardCellFills;
00228   StatData BoundaryConditions;
00229   StatData Compresses;
00230   StatData Decompresses;
00231   StatData CompressionCompares;
00232   StatData CompressionCompareMax;
00233   StatData BareFieldIterators;
00234   StatData DefaultBareFieldIterators;
00235   StatData BeginScalarCodes;
00236   StatData EndScalarCodes;
00237 
00238   StatData ParticleAttribs;
00239   StatData ParticleBases;
00240   StatData ParticleUpdates;
00241   StatData ParticleExpressions;
00242   StatData ParticleGathers;
00243   StatData ParticleScatters;
00244   StatData ParticlesCreated;
00245   StatData ParticlesDestroyed;
00246   StatData ParticlesSwapped;
00247 
00248   StatData DiscReads;
00249   StatData DiscWrites;
00250   StatData DiscFilesetReads;
00251   StatData DiscFilesetWrites;
00252   StatData DiscBytesRead;
00253   StatData DiscBytesWritten;
00254 };
00255 
00256 // simple macros used to increment a stat, which is turned on or off
00257 // by the IPPL_NO_STATS flag
00258 #ifndef IPPL_NO_STATS
00259 # define INCIPPLSTAT(stat)        Ippl::Stats->stat()
00260 # define ADDIPPLSTAT(stat,amount) Ippl::Stats->stat(amount)
00261 #else
00262 # define INCIPPLSTAT(stat)
00263 # define ADDIPPLSTAT(stat,amount)
00264 #endif
00265 
00266 #endif
00267   
00268 /***************************************************************************
00269  * $RCSfile: IpplStats.h,v $   $Author: adelmann $
00270  * $Revision: 1.1.1.1 $   $Date: 2003/01/23 07:40:33 $
00271  * IPPL_VERSION_ID: $Id: IpplStats.h,v 1.1.1.1 2003/01/23 07:40:33 adelmann Exp $ 
00272  ***************************************************************************/
00273 

Generated on Mon Jan 16 13:23:59 2006 for IPPL by  doxygen 1.4.6