00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef O2SCL_TIMER_H
00024 #define O2SCL_TIMER_H
00025
00026 #include <iostream>
00027 #include <string>
00028 #include <o2scl/string_conv.h>
00029 #include <o2scl/misc.h>
00030 #include <sys/time.h>
00031
00032 #ifndef DOXYGENP
00033 namespace o2scl {
00034 #endif
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 class timer_gettod {
00045 public:
00046
00047 #ifdef NEVER_DEFINED
00048
00049
00050 struct timeval {
00051
00052 time_t tv_sec;
00053
00054 suseconds_t tv_usec;
00055 };
00056
00057
00058 struct timezone {
00059
00060 int tz_minuteswest;
00061
00062 int tz_dsttime;
00063 };
00064
00065 #endif
00066
00067 timer_gettod() { reset(); }
00068
00069
00070 int reset() { return gettimeofday(&zero,&tz); }
00071
00072
00073 int set() { return gettimeofday(&mark,&tz); }
00074
00075
00076 double seconds_elapsed();
00077
00078
00079 int time_elapsed(int &d, int &h, int &m, int &s, int &usec);
00080
00081
00082 int time_remaining(int n, int ntot,
00083 int &d, int &h, int &m, int &s, int &usec);
00084
00085
00086 std::string time_remaining(int n, int ntot);
00087
00088
00089 std::string interval_to_string(int d, int h, int m, int s, int usec);
00090
00091 protected:
00092
00093 #ifndef DOXYGEN_INTERNAL
00094
00095
00096 struct timeval zero;
00097
00098
00099 struct timeval mark;
00100
00101
00102 struct timezone tz;
00103
00104 #endif
00105
00106 };
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116 class timer_clock {
00117
00118 public:
00119 timer_clock();
00120
00121
00122 double time_since();
00123
00124
00125
00126
00127
00128 void time_since(int &d, int &h, int &m, int &s, double &f);
00129
00130
00131 void time_remaining(int n, int tot, int &d, int &h, int &m, int &s,
00132 double &f);
00133
00134
00135 std::string interval_to_string(int d, int h, int m, int s, double f=0.0);
00136
00137 protected:
00138
00139 #ifndef DOXYGEN_INTERNAL
00140
00141
00142 clock_t time;
00143
00144 #endif
00145
00146 };
00147
00148 #ifndef DOXYGENP
00149 }
00150 #endif
00151
00152 #endif