GEOS
3.3.7
|
00001 /********************************************************************** 00002 * $Id: profiler.h 3255 2011-03-01 17:56:10Z mloskot $ 00003 * 00004 * GEOS - Geometry Engine Open Source 00005 * http://geos.refractions.net 00006 * 00007 * Copyright (C) 2001-2002 Vivid Solutions Inc. 00008 * 00009 * This is free software; you can redistribute and/or modify it under 00010 * the terms of the GNU Lesser General Public Licence as published 00011 * by the Free Software Foundation. 00012 * See the COPYING file for more information. 00013 * 00014 **********************************************************************/ 00015 00016 #ifndef GEOS_PROFILER_H 00017 #define GEOS_PROFILER_H 00018 00019 #include <geos/export.h> 00020 00021 /* For MingW builds with __STRICT_ANSI__ (-ansi) */ 00022 #if defined(__MINGW32__) 00023 /* Allow us to check for presence of gettimeofday in MingW */ 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 * \class Profile utils.h geos.h 00062 * 00063 * \brief Profile statistics 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 /* \brief current start and stop times */ 00118 struct timeval starttime, stoptime; 00119 00120 /* \brief actual times */ 00121 std::vector<double> timings; 00122 00123 /* \brief total time */ 00124 double totaltime; 00125 00126 /* \brief max time */ 00127 double max; 00128 00129 /* \brief max time */ 00130 double min; 00131 00132 /* \brief max time */ 00133 double avg; 00134 00135 }; 00136 00137 /* 00138 * \class Profiler utils.h geos.h 00139 * 00140 * \brief Profiling class 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 } // namespace geos::util 00185 } // namespace geos 00186 00187 #ifdef _MSC_VER 00188 #pragma warning(pop) 00189 #endif 00190 00191 #endif // ndef GEOS_PROFILER_H 00192 00193 /********************************************************************** 00194 * $Log$ 00195 * Revision 1.8 2006/06/12 11:29:23 strk 00196 * unsigned int => size_t 00197 * 00198 * Revision 1.7 2006/03/06 19:40:47 strk 00199 * geos::util namespace. New GeometryCollection::iterator interface, many cleanups. 00200 * 00201 * Revision 1.6 2006/03/03 10:46:21 strk 00202 * Removed 'using namespace' from headers, added missing headers in .cpp files, removed useless includes in headers (bug#46) 00203 * 00204 * Revision 1.5 2005/02/01 14:18:04 strk 00205 * Made profiler start/stop inline 00206 * 00207 * Revision 1.4 2004/12/03 16:21:07 frank 00208 * dont try for sys/time.h with MSVC 00209 * 00210 * Revision 1.3 2004/11/30 16:44:16 strk 00211 * Added gettimeofday implementation for win32, curtesy of Wu Yongwei. 00212 * 00213 * Revision 1.2 2004/11/04 08:49:13 strk 00214 * Unlinked new documentation. 00215 * 00216 * Revision 1.1 2004/11/01 16:43:04 strk 00217 * Added Profiler code. 00218 * Temporarly patched a bug in DoubleBits (must check drawbacks). 00219 * Various cleanups and speedups. 00220 * 00221 **********************************************************************/