00001
00002
00003
00004
00005
00006 #ifndef __OSL_GL_STATS_H
00007 #define __OSL_GL_STATS_H
00008
00009 #if CMK_LIVEVIZ3D_CLIENT
00010 # include "osl/osl.h"
00011 #else
00012 # include "charm.h"
00013 #endif
00014
00019 namespace stats {
00020
00021 #if CMK_LIVEVIZ3D_CLIENT
00023 inline double time(void) {return osl::time();}
00024 #else
00026 inline double time(void) {return CkWallTimer();}
00027 #endif
00028
00032 class op_t {
00033 public:
00034 int idx;
00035 };
00036
00038 enum {op_null=0, op_max=100};
00039
00041 extern int op_len;
00042
00047 op_t time_op(const char *shortName,const char *desc);
00048 op_t count_op(const char *shortName,const char *desc,const char *units);
00049
00053 class stats {
00054 public:
00056 double t[op_max];
00057
00058 stats() {zero();}
00059
00061 void zero(void) {
00062 for (int op=0;op<op_len;op++) t[op]=0.0;
00063 }
00065 void add(double val,op_t op) {t[op.idx]+=val;}
00066
00068 double get(op_t op) const {return t[op.idx];}
00069 void set(double val,op_t op) {t[op.idx]=val;}
00070
00072 void add(const stats &s,double scale=1.0) {
00073 for (int op=0;op<op_len;op++) t[op]+=s.t[op]*scale;
00074 }
00075
00077 void print(FILE *f,const char *what,double scale=1.0,double thresh=0.001) const;
00078 };
00079
00081 stats *get(void);
00082
00084 op_t swap(op_t op);
00085
00088 class op_sentry {
00089 op_t prev_op, op;
00090 public:
00091 op_sentry(op_t op_) :op(op_)
00092 {
00093 prev_op=swap(op);
00094 }
00095 ~op_sentry() {
00096 swap(prev_op);
00097 }
00098 };
00099 };
00100
00101
00102 #endif