00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifdef __GNUC__
00029 #pragma interface
00030 #endif
00031
00032 #ifndef _util_misc_regtime_h
00033 #define _util_misc_regtime_h
00034
00035 #include <iostream>
00036 #include <string>
00037 #include <util/class/class.h>
00038
00039 namespace sc {
00040
00041 class TimedRegion {
00042 private:
00043 char *name_;
00044 TimedRegion *up_;
00045 TimedRegion *subregions_;
00046 TimedRegion *next_;
00047 TimedRegion *prev_;
00048 double cpu_time_;
00049 double wall_time_;
00050 double cpu_enter_;
00051 double wall_enter_;
00052 double flops_;
00053 double flops_enter_;
00054
00055 TimedRegion *insert_after(const char *name);
00056 TimedRegion *insert_before(const char *name);
00057 public:
00058 TimedRegion(const char *name);
00059 ~TimedRegion();
00060 const char *name() const { return name_; }
00061 TimedRegion *findinsubregion(const char *);
00062 void cpu_enter(double);
00063 void wall_enter(double);
00064 void flops_enter(double);
00065 void cpu_exit(double);
00066 void wall_exit(double);
00067 void flops_exit(double);
00068 void cpu_add(double t) { cpu_time_ += t; }
00069 void wall_add(double t) { wall_time_ += t; }
00070 void flops_add(double t) { flops_ += t; }
00071 TimedRegion *up() const { return up_; }
00072 TimedRegion *subregions() const { return subregions_; }
00073 TimedRegion *next() const { return next_; }
00074 TimedRegion *prev() const { return prev_; }
00075
00076 int nregion();
00077 void get_region_names(const char *names[]);
00078 void get_wall_times(double *);
00079 void get_cpu_times(double *);
00080 void get_flops(double *);
00081 void get_depth(int *, int depth = 0);
00082 };
00083
00089 class RegionTimer: public DescribedClass {
00090 protected:
00091 int wall_time_;
00092 int cpu_time_;
00093 int flops_;
00094
00095 TimedRegion *top_;
00096 TimedRegion *current_;
00097 TimedRegion *default_;
00098
00099 public:
00100 RegionTimer(const char *topname = "total",
00101 int cpu_time = 0, int wall_time = 1);
00102 RegionTimer(const Ref<KeyVal> &);
00103 ~RegionTimer();
00104 void enter(const char * = 0);
00105 void change(const char *newname, const char * oldname = 0);
00106 void exit(const char * = 0, bool do_not_throw = false);
00107 void set_default(const char *);
00108 void unset_default();
00109 void enter_default();
00110 void exit_default();
00111 virtual void print(std::ostream& = ExEnv::out0()) const;
00112
00113 void update_top() const;
00114
00115 int nregion() const;
00116 void get_region_names(const char *names[]) const;
00117 void get_wall_times(double *) const;
00118 void get_cpu_times(double *) const;
00119 void get_flops(double *) const;
00120 void get_depth(int *) const;
00121
00122 double get_wall_time() const;
00123 double get_cpu_time() const;
00124 double get_flops() const;
00125
00126 void add_wall_time(const char *, double);
00127 void add_cpu_time(const char *, double);
00128 void add_flops(const char *, double);
00129
00130 static RegionTimer *default_regiontimer();
00131 static void set_default_regiontimer(const Ref<RegionTimer> &);
00132 };
00133
00140 class Timer {
00141 Ref<RegionTimer> timer_;
00142 std::string name_;
00143 bool active_;
00144 public:
00148 Timer(const char *name);
00151 Timer(const Ref<RegionTimer> &, const char *name);
00153 ~Timer();
00157 void reset(const char * = 0);
00158 };
00159
00160 }
00161
00162 #endif
00163
00164
00165
00166
00167