GEOS
3.3.9
|
00001 /********************************************************************** 00002 * $Id: profiler.h 3815 2013-06-11 12:36:24Z strk $ 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 <stdlib.h> 00020 #include <geos/export.h> 00021 00022 /* For MingW builds with __STRICT_ANSI__ (-ansi) */ 00024 #if defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR) 00025 /* Allow us to check for presence of gettimeofday in MingW */ 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 * \class Profile utils.h geos.h 00064 * 00065 * \brief Profile statistics 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 /* \brief current start and stop times */ 00120 struct timeval starttime, stoptime; 00121 00122 /* \brief actual times */ 00123 std::vector<double> timings; 00124 00125 /* \brief total time */ 00126 double totaltime; 00127 00128 /* \brief max time */ 00129 double max; 00130 00131 /* \brief max time */ 00132 double min; 00133 00134 /* \brief max time */ 00135 double avg; 00136 00137 }; 00138 00139 /* 00140 * \class Profiler utils.h geos.h 00141 * 00142 * \brief Profiling class 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 } // namespace geos::util 00187 } // namespace geos 00188 00189 #ifdef _MSC_VER 00190 #pragma warning(pop) 00191 #endif 00192 00193 #endif // ndef GEOS_PROFILER_H 00194 00195 /********************************************************************** 00196 * $Log$ 00197 * Revision 1.8 2006/06/12 11:29:23 strk 00198 * unsigned int => size_t 00199 * 00200 * Revision 1.7 2006/03/06 19:40:47 strk 00201 * geos::util namespace. New GeometryCollection::iterator interface, many cleanups. 00202 * 00203 * Revision 1.6 2006/03/03 10:46:21 strk 00204 * Removed 'using namespace' from headers, added missing headers in .cpp files, removed useless includes in headers (bug#46) 00205 * 00206 * Revision 1.5 2005/02/01 14:18:04 strk 00207 * Made profiler start/stop inline 00208 * 00209 * Revision 1.4 2004/12/03 16:21:07 frank 00210 * dont try for sys/time.h with MSVC 00211 * 00212 * Revision 1.3 2004/11/30 16:44:16 strk 00213 * Added gettimeofday implementation for win32, curtesy of Wu Yongwei. 00214 * 00215 * Revision 1.2 2004/11/04 08:49:13 strk 00216 * Unlinked new documentation. 00217 * 00218 * Revision 1.1 2004/11/01 16:43:04 strk 00219 * Added Profiler code. 00220 * Temporarly patched a bug in DoubleBits (must check drawbacks). 00221 * Various cleanups and speedups. 00222 * 00223 **********************************************************************/