- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List

# profiler.h

    00001 /**********************************************************************
    00002  * $Id: profiler.h 2556 2009-06-06 22:22:28Z 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 <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 namespace geos {
    00052 namespace util {
    00053
    00054
    00055 /*
    00056  * \class Profile utils.h geos.h
    00057  *
    00058  * \brief Profile statistics
    00059  */
    00060 class GEOS_DLL Profile {
    00061 public:
    00063         Profile(std::string name);
    00064
    00066         ~Profile();
    00067
    00069         void start() {
    00070                 gettimeofday(&starttime, NULL);
    00071         }
    00072
    00074         void stop()
    00075         {
    00076                 gettimeofday(&stoptime, NULL);
    00077                 double elapsed = 1000000*(stoptime.tv_sec-starttime.tv_sec)+
    00078                         (stoptime.tv_usec-starttime.tv_usec);
    00079
    00080                 timings.push_back(elapsed);
    00081                 totaltime += elapsed;
    00082                 if ( timings.size() == 1 ) max = min = elapsed;
    00083                 else
    00084                 {
    00085                         if ( elapsed > max ) max = elapsed;
    00086                         if ( elapsed < min ) min = elapsed;
    00087                 }
    00088                 avg = totaltime / timings.size();
    00089         }
    00090
    00092         double getMax() const;
    00093
    00095         double getMin() const;
    00096
    00098         double getTot() const;
    00099
    00101         double getAvg() const;
    00102
    00104         size_t getNumTimings() const;
    00105
    00107         std::string name;
    00108
    00109
    00110 private:
    00111
    00112         /* \brief current start and stop times */
    00113         struct timeval starttime, stoptime;
    00114
    00115         /* \brief actual times */
    00116         std::vector<double> timings;
    00117
    00118         /* \brief total time */
    00119         double totaltime;
    00120
    00121         /* \brief max time */
    00122         double max;
    00123
    00124         /* \brief max time */
    00125         double min;
    00126
    00127         /* \brief max time */
    00128         double avg;
    00129
    00130 };
    00131
    00132 /*
    00133  * \class Profiler utils.h geos.h
    00134  *
    00135  * \brief Profiling class
    00136  *
    00137  */
    00138 class GEOS_DLL Profiler {
    00139
    00140 public:
    00141
    00142         Profiler();
    00143         ~Profiler();
    00144
    00150         static Profiler *instance(void);
    00151
    00157         void start(std::string name);
    00158
    00164         void stop(std::string name);
    00165
    00167         Profile *get(std::string name);
    00168
    00169         std::map<std::string, Profile *> profs;
    00170 };
    00171
    00172
    00174 std::ostream& operator<< (std::ostream& os, const Profile&);
    00175
    00177 std::ostream& operator<< (std::ostream& os, const Profiler&);
    00178
    00179 } // namespace geos::util
    00180 } // namespace geos
    00181
    00182 #endif // ndef GEOS_PROFILER_H
    00183
    00184 /**********************************************************************
    00185  * $Log$
    00186  * Revision 1.8  2006/06/12 11:29:23  strk
    00187  * unsigned int => size_t
    00188  *
    00189  * Revision 1.7  2006/03/06 19:40:47  strk
    00190  * geos::util namespace. New GeometryCollection::iterator interface, many cleanups.
    00191  *
    00192  * Revision 1.6  2006/03/03 10:46:21  strk
    00193  * Removed 'using namespace' from headers, added missing headers in .cpp files, removed useless includes in headers (bug#46)
    00194  *
    00195  * Revision 1.5  2005/02/01 14:18:04  strk
    00196  * Made profiler start/stop inline
    00197  *
    00198  * Revision 1.4  2004/12/03 16:21:07  frank
    00199  * dont try for sys/time.h with MSVC
    00200  *
    00201  * Revision 1.3  2004/11/30 16:44:16  strk
    00202  * Added gettimeofday implementation for win32, curtesy of Wu Yongwei.
    00203  *
    00204  * Revision 1.2  2004/11/04 08:49:13  strk
    00205  * Unlinked new documentation.
    00206  *
    00207  * Revision 1.1  2004/11/01 16:43:04  strk
    00208  * Added Profiler code.
    00209  * Temporarly patched a bug in DoubleBits (must check drawbacks).
    00210  * Various cleanups and speedups.
    00211  *
    00212  **********************************************************************/