1 /**********************************************************************
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
6 * Copyright (C) 2001-2002 Vivid Solutions Inc.
8 * This is free software; you can redistribute and/or modify it under
9 * the terms of the GNU Lesser General Public Licence as published
10 * by the Free Software Foundation.
11 * See the COPYING file for more information.
13 **********************************************************************/
15 #ifndef GEOS_PROFILER_H
16 #define GEOS_PROFILER_H
18 #include <geos/export.h>
20 /* For MingW builds with __STRICT_ANSI__ (-ansi) */
21 #if defined(__MINGW32__)
22 /* Allow us to check for presence of gettimeofday in MingW */
27 extern _CRTIMP
void __cdecl
_tzset (void);
28 __MINGW_IMPORT
int _daylight
;
29 __MINGW_IMPORT
long _timezone
;
30 __MINGW_IMPORT
char *_tzname
[2];
34 #if defined(_MSC_VER) || defined(__MINGW32__) && !defined(HAVE_GETTIMEOFDAY)
35 #include <geos/timeval.h>
52 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
60 * \class Profile utils.h geos.h
62 * \brief Profile statistics
64 class GEOS_DLL Profile
{
66 /** \brief Create a named profile */
67 Profile(std::string name
);
69 /** \brief Destructor */
72 /** \brief start a new timer */
74 gettimeofday(&starttime
, NULL
);
77 /** \brief stop current timer */
80 gettimeofday(&stoptime
, NULL
);
81 double elapsed
= 1000000*(stoptime
.tv_sec
-starttime
.tv_sec
)+
82 (stoptime
.tv_usec
-starttime
.tv_usec
);
84 timings
.push_back(elapsed
);
86 if ( timings
.size() == 1 ) max
= min
= elapsed
;
89 if ( elapsed
> max
) max
= elapsed
;
90 if ( elapsed
< min
) min
= elapsed
;
92 avg
= totaltime
/ timings
.size();
95 /** \brief Return Max stored timing */
96 double getMax() const;
98 /** \brief Return Min stored timing */
99 double getMin() const;
101 /** \brief Return total timing */
102 double getTot() const;
104 /** \brief Return average timing */
105 double getAvg() const;
107 /** \brief Return number of timings */
108 size_t getNumTimings() const;
110 /** \brief Profile name */
116 /* \brief current start and stop times */
117 struct timeval starttime
, stoptime
;
119 /* \brief actual times */
120 std::vector
<double> timings
;
122 /* \brief total time */
125 /* \brief max time */
128 /* \brief max time */
131 /* \brief max time */
137 * \class Profiler utils.h geos.h
139 * \brief Profiling class
142 class GEOS_DLL Profiler
{
151 * Return the singleton instance of the
154 static Profiler
*instance(void);
158 * Start timer for named task. The task is
159 * created if does not exist.
161 void start(std::string name
);
165 * Stop timer for named task.
166 * Elapsed time is registered in the given task.
168 void stop(std::string name
);
170 /** \brief get Profile of named task */
171 Profile
*get(std::string name
);
173 std::map
<std::string
, Profile
*> profs
;
177 /** \brief Return a string representing the Profile */
178 std::ostream
& operator<< (std::ostream
& os
, const Profile
&);
180 /** \brief Return a string representing the Profiler */
181 std::ostream
& operator<< (std::ostream
& os
, const Profiler
&);
183 } // namespace geos::util
190 #endif // ndef GEOS_PROFILER_H
192 /**********************************************************************
194 * Revision 1.8 2006/06/12 11:29:23 strk
195 * unsigned int => size_t
197 * Revision 1.7 2006/03/06 19:40:47 strk
198 * geos::util namespace. New GeometryCollection::iterator interface, many cleanups.
200 * Revision 1.6 2006/03/03 10:46:21 strk
201 * Removed 'using namespace' from headers, added missing headers in .cpp files, removed useless includes in headers (bug#46)
203 * Revision 1.5 2005/02/01 14:18:04 strk
204 * Made profiler start/stop inline
206 * Revision 1.4 2004/12/03 16:21:07 frank
207 * dont try for sys/time.h with MSVC
209 * Revision 1.3 2004/11/30 16:44:16 strk
210 * Added gettimeofday implementation for win32, curtesy of Wu Yongwei.
212 * Revision 1.2 2004/11/04 08:49:13 strk
213 * Unlinked new documentation.
215 * Revision 1.1 2004/11/01 16:43:04 strk
216 * Added Profiler code.
217 * Temporarly patched a bug in DoubleBits (must check drawbacks).
218 * Various cleanups and speedups.
220 **********************************************************************/