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 #ifdef _MSC_VER
00052 #pragma warning(push)
00053 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
00054 #endif
00055
00056 namespace geos {
00057 namespace util {
00058
00059
00060
00061
00062
00063
00064
00065 class GEOS_DLL Profile {
00066 public:
00068 Profile(std::string name);
00069
00071 ~Profile();
00072
00074 void start() {
00075 gettimeofday(&starttime, NULL);
00076 }
00077
00079 void stop()
00080 {
00081 gettimeofday(&stoptime, NULL);
00082 double elapsed = 1000000*(stoptime.tv_sec-starttime.tv_sec)+
00083 (stoptime.tv_usec-starttime.tv_usec);
00084
00085 timings.push_back(elapsed);
00086 totaltime += elapsed;
00087 if ( timings.size() == 1 ) max = min = elapsed;
00088 else
00089 {
00090 if ( elapsed > max ) max = elapsed;
00091 if ( elapsed < min ) min = elapsed;
00092 }
00093 avg = totaltime / timings.size();
00094 }
00095
00097 double getMax() const;
00098
00100 double getMin() const;
00101
00103 double getTot() const;
00104
00106 double getAvg() const;
00107
00109 size_t getNumTimings() const;
00110
00112 std::string name;
00113
00114
00115 private:
00116
00117
00118 struct timeval starttime, stoptime;
00119
00120
00121 std::vector<double> timings;
00122
00123
00124 double totaltime;
00125
00126
00127 double max;
00128
00129
00130 double min;
00131
00132
00133 double avg;
00134
00135 };
00136
00137
00138
00139
00140
00141
00142
00143 class GEOS_DLL Profiler {
00144
00145 public:
00146
00147 Profiler();
00148 ~Profiler();
00149
00155 static Profiler *instance(void);
00156
00162 void start(std::string name);
00163
00169 void stop(std::string name);
00170
00172 Profile *get(std::string name);
00173
00174 std::map<std::string, Profile *> profs;
00175 };
00176
00177
00179 std::ostream& operator<< (std::ostream& os, const Profile&);
00180
00182 std::ostream& operator<< (std::ostream& os, const Profiler&);
00183
00184 }
00185 }
00186
00187 #ifdef _MSC_VER
00188 #pragma warning(pop)
00189 #endif
00190
00191 #endif // ndef GEOS_PROFILER_H
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221