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 <stdlib.h>
00020 #include <geos/export.h>
00021
00022
00024 #if defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR)
00025
00026 #include <config.h>
00027
00028 #include <sys/time.h>
00029 extern "C" {
00030 extern _CRTIMP void __cdecl _tzset (void);
00031 __MINGW_IMPORT int _daylight;
00032 __MINGW_IMPORT long _timezone;
00033 __MINGW_IMPORT char *_tzname[2];
00034 }
00035 #endif
00036
00037 #if defined(_MSC_VER) || defined(__MINGW32__) && !defined(HAVE_GETTIMEOFDAY) && !defined(__MINGW64_VERSION_MAJOR)
00038 #include <geos/timeval.h>
00039 #else
00040 #include <sys/time.h>
00041 #endif
00042
00043 #include <map>
00044 #include <memory>
00045 #include <iostream>
00046 #include <string>
00047 #include <vector>
00048
00049 #ifndef PROFILE
00050 #define PROFILE 0
00051 #endif
00052
00053 #ifdef _MSC_VER
00054 #pragma warning(push)
00055 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
00056 #endif
00057
00058 namespace geos {
00059 namespace util {
00060
00061
00062
00063
00064
00065
00066
00067 class GEOS_DLL Profile {
00068 public:
00070 Profile(std::string name);
00071
00073 ~Profile();
00074
00076 void start() {
00077 gettimeofday(&starttime, NULL);
00078 }
00079
00081 void stop()
00082 {
00083 gettimeofday(&stoptime, NULL);
00084 double elapsed = 1000000*(stoptime.tv_sec-starttime.tv_sec)+
00085 (stoptime.tv_usec-starttime.tv_usec);
00086
00087 timings.push_back(elapsed);
00088 totaltime += elapsed;
00089 if ( timings.size() == 1 ) max = min = elapsed;
00090 else
00091 {
00092 if ( elapsed > max ) max = elapsed;
00093 if ( elapsed < min ) min = elapsed;
00094 }
00095 avg = totaltime / timings.size();
00096 }
00097
00099 double getMax() const;
00100
00102 double getMin() const;
00103
00105 double getTot() const;
00106
00108 double getAvg() const;
00109
00111 size_t getNumTimings() const;
00112
00114 std::string name;
00115
00116
00117 private:
00118
00119
00120 struct timeval starttime, stoptime;
00121
00122
00123 std::vector<double> timings;
00124
00125
00126 double totaltime;
00127
00128
00129 double max;
00130
00131
00132 double min;
00133
00134
00135 double avg;
00136
00137 };
00138
00139
00140
00141
00142
00143
00144
00145 class GEOS_DLL Profiler {
00146
00147 public:
00148
00149 Profiler();
00150 ~Profiler();
00151
00157 static Profiler *instance(void);
00158
00164 void start(std::string name);
00165
00171 void stop(std::string name);
00172
00174 Profile *get(std::string name);
00175
00176 std::map<std::string, Profile *> profs;
00177 };
00178
00179
00181 std::ostream& operator<< (std::ostream& os, const Profile&);
00182
00184 std::ostream& operator<< (std::ostream& os, const Profiler&);
00185
00186 }
00187 }
00188
00189 #ifdef _MSC_VER
00190 #pragma warning(pop)
00191 #endif
00192
00193 #endif // ndef GEOS_PROFILER_H
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
00222
00223