00001
00023 #ifndef GALOIS_STATISTIC_H
00024 #define GALOIS_STATISTIC_H
00025
00026 #include "Galois/Runtime/Support.h"
00027 #include "Galois/Runtime/PerThreadStorage.h"
00028 #include "Galois/Runtime/Sampling.h"
00029 #include "Galois/Timer.h"
00030
00031 #include "boost/utility.hpp"
00032
00033 #include <list>
00034
00035 namespace Galois {
00036
00037 class Statistic {
00038 std::string statname;
00039 std::string loopname;
00040 GaloisRuntime::PerThreadStorage<unsigned long> val;
00041 bool valid;
00042
00043 public:
00044 Statistic(const std::string& _sn, unsigned long v, const std::string& _ln = "(NULL)"): statname(_sn), loopname(_ln), valid(true) {
00045 *val.getLocal() = v;
00046 }
00047
00048 Statistic(const std::string& _sn, const std::string& _ln = "(NULL)"): statname(_sn), loopname(_ln), valid(true) { }
00049
00050 ~Statistic() {
00051 report();
00052 }
00053
00055 void report() {
00056 if (valid)
00057 GaloisRuntime::reportStat(this);
00058 valid = false;
00059 }
00060
00061 unsigned long getValue(unsigned tid) {
00062 return *val.getRemote(tid);
00063 }
00064
00065 std::string& getLoopname() {
00066 return loopname;
00067 }
00068
00069 std::string& getStatname() {
00070 return statname;
00071 }
00072
00073 Statistic& operator+=(unsigned long v) {
00074 *val.getLocal() += v;
00075 return *this;
00076 }
00077 };
00078
00080 class StatManager: private boost::noncopyable {
00081 std::list<Statistic*> stats;
00082
00083 public:
00084 ~StatManager() {
00085 for (std::list<Statistic*>::iterator ii = stats.begin(), ei = stats.end(); ii != ei; ++ii) {
00086 (*ii)->report();
00087 }
00088 GaloisRuntime::printStats();
00089 }
00090
00092 void push(Statistic& s) {
00093 stats.push_back(&s);
00094 }
00095 };
00096
00098 class StatTimer : public Timer {
00099 const char* name;
00100 const char* loopname;
00101 bool main;
00102
00103 public:
00104 StatTimer(): name("Time"), loopname(0), main(true) { }
00105 StatTimer(const char* n, const char* l = 0): name(n), loopname(l), main(false) { }
00106 ~StatTimer() {
00107 GaloisRuntime::reportStat(loopname, name, get());
00108 if (main)
00109 GaloisRuntime::reportSampling(loopname);
00110 }
00111
00112 void start() {
00113 if (main)
00114 GaloisRuntime::beginSampling();
00115 Timer::start();
00116 }
00117
00118 void stop() {
00119 Timer::stop();
00120 if (main)
00121 GaloisRuntime::endSampling();
00122 }
00123 };
00124
00125 }
00126
00127 #endif