00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef GEOS_PROFILER_H
00017 #define GEOS_PROFILER_H
00018
00019 #include <geos/export.h>
00020
00021
00022 #if defined(__MINGW32__)
00023
00024 #include <config.h>
00025
00026 #include <sys/time.h>
00027 extern "C" {
00028 extern _CRTIMP void __cdecl _tzset (void);
00029 __MINGW_IMPORT int _daylight;
00030 __MINGW_IMPORT long _timezone;
00031 __MINGW_IMPORT char *_tzname[2];
00032 }
00033 #endif
00034
00035 #if defined(_MSC_VER) || defined(__MINGW32__) && !defined(HAVE_GETTIMEOFDAY)
00036 #include <geos/timeval.h>
00037 #else
00038 #include <sys/time.h>
00039 #endif
00040
00041 #include <map>
00042 #include <memory>
00043 #include <iostream>
00044 #include <string>
00045 #include <vector>
00046
00047 #ifndef PROFILE
00048 #define PROFILE 0
00049 #endif
00050
00051 namespace geos {
00052 namespace util {
00053
00054
00055
00056
00057
00058
00059
00060 class GEOS_DLL Profile {
00061 public:
00063 Profile(std::string name);
00064
00066 ~Profile();
00067
00069 void start() {
00070 gettimeofday(&starttime, NULL);
00071 }
00072
00074 void stop()
00075 {
00076 gettimeofday(&stoptime, NULL);
00077 double elapsed = 1000000*(stoptime.tv_sec-starttime.tv_sec)+
00078 (stoptime.tv_usec-starttime.tv_usec);
00079
00080 timings.push_back(elapsed);
00081 totaltime += elapsed;
00082 if ( timings.size() == 1 ) max = min = elapsed;
00083 else
00084 {
00085 if ( elapsed > max ) max = elapsed;
00086 if ( elapsed < min ) min = elapsed;
00087 }
00088 avg = totaltime / timings.size();
00089 }
00090
00092 double getMax() const;
00093
00095 double getMin() const;
00096
00098 double getTot() const;
00099
00101 double getAvg() const;
00102
00104 size_t getNumTimings() const;
00105
00107 std::string name;
00108
00109
00110 private:
00111
00112
00113 struct timeval starttime, stoptime;
00114
00115
00116 std::vector<double> timings;
00117
00118
00119 double totaltime;
00120
00121
00122 double max;
00123
00124
00125 double min;
00126
00127
00128 double avg;
00129
00130 };
00131
00132
00133
00134
00135
00136
00137
00138 class GEOS_DLL Profiler {
00139
00140 public:
00141
00142 Profiler();
00143 ~Profiler();
00144
00150 static Profiler *instance(void);
00151
00157 void start(std::string name);
00158
00164 void stop(std::string name);
00165
00167 Profile *get(std::string name);
00168
00169 std::map<std::string, Profile *> profs;
00170 };
00171
00172
00174 std::ostream& operator<< (std::ostream& os, const Profile&);
00175
00177 std::ostream& operator<< (std::ostream& os, const Profiler&);
00178
00179 }
00180 }
00181
00182 #endif // ndef GEOS_PROFILER_H
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212