IpplStats.h 8.66 KB
Newer Older
gsell's avatar
gsell committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
// -*- C++ -*-
/***************************************************************************
 *
 * The IPPL Framework
 * 
 *
 * Visit http://people.web.psi.ch/adelmann/ for more details
 *
 ***************************************************************************/

#ifndef IPPL_STATS_H
#define IPPL_STATS_H

/***************************************************************************
 * IpplStats keeps statistics about a given IPPL job, and can report on
 * a summary of these statistics when asked.
 *
 * To add a new type of statistic, do these steps:
 *   1. Add a new private variable to accumulate the stats
 *   2. Add a new public method to call to add values to the stat
 *   3. In the constructor, initialize the stats object with a name in the
 *      colon-initializer list.
 *   4. Add commands to the rest of ippl to change the stat as needed.
 *      Example:
 *                 #ifndef IPPL_NO_STATS
 *                 Ippl::Stats.incMessageSent();
 *                 #endif
 *
 * This interface is extensible ... you can add new types of statistics
 * by calling 'addStat(description, initval)' with a string description
 * of the stat, and the initial value it should have.  This will return a
 * unique integer identifier for that stat.  Then, you can modify the stat
 * by calling incStat(statindex, amount) and decStat(statindex, amount).
 * At the end, then, this statistic will be printed out just like all the
 * others.
 ***************************************************************************/

// include files
#include "Utility/IpplInfo.h"
#include "Utility/Timer.h"

#include <vector>

44 45
class Inform;

gsell's avatar
gsell committed
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
class IpplStats {

public:
  // constructor: initialize statistics, and start run timer
  IpplStats();

  // destructor
  ~IpplStats();

  // print out the statistics to the given Inform object
  void print(Inform &);

  // add a statistics object to our list of stats ... return an integer
  // which is the index of the stat in our list, which can be used with
  // the 'incStat' and 'decStat' methods to change that statistic
  int addStat(const char *description, long initval = 0) {
    StatList.push_back(new StatData(description, initval, true));
    return (StatList.size() - 1);
  }

  // increment or decrement the statistic by the given value.  Return the
  // current value
  long incStat(int statindx, long val = 1) {
    StatList[statindx]->Value += val;
    return StatList[statindx]->Value;
  }
  long decStat(int statindx, long val = 1) {
    StatList[statindx]->Value -= val;
    return StatList[statindx]->Value;
  }

  //
  // general IPPL operation information
  //

  // return a ref to the timer, so that it can be turned on and off
  Timer &getTime() { return Time; }

  //
  // communication statistics operations
  //

  void incMessageSent() { ++MessagesSent.Value; }
  void incMessageSentToOthers() { ++MessagesSentToOthers.Value; }
  void incMessageSentToSelf() { ++MessagesSentToSelf.Value; }
  void incMessageReceived() { ++MessagesReceived.Value; }
  void incMessageReceivedFromNetwork() { ++MessagesReceivedFromNetwork.Value;}
  void incMessageReceivedFromQueue() { ++MessagesReceivedFromQueue.Value; }
  void incMessageReceiveChecks() { ++MessageReceiveChecks.Value; }
  void incMessageReceiveChecksFailed() { ++MessageReceiveChecksFailed.Value; }
  void incMessageBytesSent(long bytes) { BytesSent.Value += bytes; }
  void incMessageBytesReceived(long bytes) { BytesReceived.Value += bytes; }
  void incBarriers() { ++Barriers.Value; }
  void incReductions() { ++Reductions.Value; }
  void incScatters() { ++Scatters.Value; }

  //
  // BareField statistics operations
  //

  void incBareFields() { ++BareFields.Value; }
  void incLFields() { ++LFields.Value; }
  void incLFieldBytes(long bytes) { LFieldBytes.Value += bytes; }
  void incFieldLayouts() { ++FieldLayouts.Value; }
  void incRepartitions() { ++Repartitions.Value; }
  void incExpressions()            { ++Expressions.Value; }
  void incBFEqualsExpression()     { ++BFEqualsExpression.Value; }
  void incIBFEqualsExpression()    { ++IBFEqualsExpression.Value; }
  void incParensEqualsExpression() { ++ParensEqualsExpression.Value; }
  void incBFEqualsBF()             { ++BFEqualsBF.Value; }
  void incIBFEqualsIBF()           { ++IBFEqualsIBF.Value; }
  void incSubEqualsExpression()    { ++SubEqualsExpression.Value; }
  void incFFTs() { ++FFTs.Value; }
  void incGuardCellFills() { ++GuardCellFills.Value; }
  void incBoundaryConditions() { ++BoundaryConditions.Value; }
  void incCompresses() { ++Compresses.Value; }
  void incDecompresses() { ++Decompresses.Value; }
  void incCompressionCompares(long c) { CompressionCompares.Value += c; }
  void incCompressionCompareMax(long c) { CompressionCompareMax.Value += c; }
  void incBareFieldIterators() { ++BareFieldIterators.Value; }
  void incDefaultBareFieldIterators() { ++DefaultBareFieldIterators.Value; }
  void incBeginScalarCodes() { ++BeginScalarCodes.Value; }
  void incEndScalarCodes() { ++EndScalarCodes.Value; }
  //
  // Particle statistics operations
  //

  void incParticleAttribs() { ++ParticleAttribs.Value; }
134
  void incIpplParticleBases() { ++IpplParticleBases.Value; }
gsell's avatar
gsell committed
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
  void incParticleUpdates() { ++ParticleUpdates.Value; }
  void incParticleExpressions() { ++ParticleExpressions.Value; }
  void incParticleGathers() { ++ParticleGathers.Value; }
  void incParticleScatters() { ++ParticleScatters.Value; }
  void incParticlesCreated(long num) { ParticlesCreated.Value += num; }
  void incParticlesDestroyed(long num) { ParticlesDestroyed.Value += num; }
  void incParticlesSwapped(long num) { ParticlesSwapped.Value += num; }

private:
  // a simple object used to accumulate a stat, with a name.
  struct StatData {
    // constructor
    StatData(std::vector<StatData *> &datalist, const char *nm, long initval = 0,
	     bool needDelete = false)
      : Value(initval), Name(nm), NeedDelete(needDelete) {
      // add ourselves to the list of statistics objects
      datalist.push_back(this);
    }

    // another constructor, without the vector
    StatData(const char *nm, long initval = 0, bool needDelete = false)
      : Value(initval), Name(nm), NeedDelete(needDelete) { }

    // default constructor
    StatData() : Value(0), Name("") { }

    // destructor
    ~StatData() { }

    // value and name
    long   Value;
    std::string Name;

    // if this is true, we need to be deleted by the Stats class
    bool NeedDelete;
  };

  // a vector of statistics data objects, which will be used to print
  // out the results at the end.  All stats should be declared as StatData
  // variables below; in their constructor, they will put themselves in the
  // list of statistics objects.
  std::vector<StatData *> StatList;

  // a timer to time the whole program (although other timers may certainly be
  // created throughout the program)
  Timer Time;

  // build-in ippl statistics objects
  StatData MessagesSent;
  StatData MessagesSentToOthers;
  StatData MessagesSentToSelf;
  StatData MessagesReceived;
  StatData MessagesReceivedFromNetwork;
  StatData MessagesReceivedFromQueue;
  StatData MessageReceiveChecks;
  StatData MessageReceiveChecksFailed;
  StatData BytesSent;
  StatData BytesReceived;
  StatData Barriers;
  StatData Reductions;
  StatData Scatters;

  StatData BareFields;
  StatData LFields;
  StatData LFieldBytes;
  StatData FieldLayouts;
  StatData Repartitions;
  StatData Expressions;
  StatData BFEqualsExpression;
  StatData IBFEqualsExpression;
  StatData ParensEqualsExpression;
  StatData BFEqualsBF;
  StatData IBFEqualsIBF;
  StatData SubEqualsExpression;
  StatData FFTs;
  StatData GuardCellFills;
  StatData BoundaryConditions;
  StatData Compresses;
  StatData Decompresses;
  StatData CompressionCompares;
  StatData CompressionCompareMax;
  StatData BareFieldIterators;
  StatData DefaultBareFieldIterators;
  StatData BeginScalarCodes;
  StatData EndScalarCodes;

  StatData ParticleAttribs;
222
  StatData IpplParticleBases;
gsell's avatar
gsell committed
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
  StatData ParticleUpdates;
  StatData ParticleExpressions;
  StatData ParticleGathers;
  StatData ParticleScatters;
  StatData ParticlesCreated;
  StatData ParticlesDestroyed;
  StatData ParticlesSwapped;

};

// simple macros used to increment a stat, which is turned on or off
// by the IPPL_NO_STATS flag
#ifndef IPPL_NO_STATS
# define INCIPPLSTAT(stat)        Ippl::Stats->stat()
# define ADDIPPLSTAT(stat,amount) Ippl::Stats->stat(amount)
#else
# define INCIPPLSTAT(stat)
# define ADDIPPLSTAT(stat,amount)
#endif

#endif
  
/***************************************************************************
 * $RCSfile: IpplStats.h,v $   $Author: adelmann $
 * $Revision: 1.1.1.1 $   $Date: 2003/01/23 07:40:33 $
 * IPPL_VERSION_ID: $Id: IpplStats.h,v 1.1.1.1 2003/01/23 07:40:33 adelmann Exp $ 
 ***************************************************************************/