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 #include <geos/profiler.h>
24 namespace util
{ // geos.util
26 Profile::Profile(string newname
)
41 gettimeofday(&starttime
, NULL
);
47 gettimeofday(&stoptime
, NULL
);
48 double elapsed
= 1000000*(stoptime
.tv_sec
-starttime
.tv_sec
)+
49 (stoptime
.tv_usec
-starttime
.tv_usec
);
51 timings
.push_back(elapsed
);
53 if ( timings
.size() == 1 ) max
= min
= elapsed
;
56 if ( elapsed
> max
) max
= elapsed
;
57 if ( elapsed
< min
) min
= elapsed
;
59 avg
= totaltime
/ timings
.size();
64 Profile::getMax() const
70 Profile::getMin() const
76 Profile::getAvg() const
82 Profile::getTot() const
88 Profile::getNumTimings() const
90 return timings
.size();
99 map
<string
, Profile
*>::const_iterator it
;
100 for ( it
=profs
.begin(); it
!= profs
.end(); ++it
)
107 Profiler::start(string name
)
109 Profile
*prof
= get(name
);
114 Profiler::stop(string name
)
116 map
<string
, Profile
*>::iterator iter
= profs
.find(name
);
117 if ( iter
== profs
.end() ) {
118 cerr
<<name
<<": no such Profile started";
121 iter
->second
->stop();
125 Profiler::get(string name
)
128 map
<string
, Profile
*>::iterator iter
= profs
.find(name
);
129 if ( iter
== profs
.end() ) {
130 prof
= new Profile(name
);
131 profs
.insert(pair
<string
, Profile
*>(name
, prof
));
141 static Profiler internal_profiler
;
142 return &internal_profiler
;
147 operator<< (ostream
&os
, const Profile
&prof
)
149 os
<< " num:"<<prof
.getNumTimings()<<" min:"<<
150 prof
.getMin()<<" max:"<<prof
.getMax()<<
151 " avg:"<<prof
.getAvg()<<" tot:"<<prof
.getTot()<<
152 " ["<<prof
.name
<<"]";
157 operator<< (ostream
&os
, const Profiler
&prof
)
159 map
<string
, Profile
*>::const_iterator it
;
160 for ( it
=prof
.profs
.begin(); it
!= prof
.profs
.end(); ++it
)
162 os
<<*(it
->second
)<<endl
;
168 } // namespace geos.util
171 /**********************************************************************
173 * Revision 1.10 2006/06/12 11:29:24 strk
174 * unsigned int => size_t
176 * Revision 1.9 2006/03/07 14:18:34 strk
177 * Profiler singleton implemented with a function-static Profiler instance
179 * Revision 1.8 2006/03/06 19:40:48 strk
180 * geos::util namespace. New GeometryCollection::iterator interface, many cleanups.
182 * Revision 1.7 2006/03/03 10:46:22 strk
183 * Removed 'using namespace' from headers, added missing headers in .cpp files, removed useless includes in headers (bug#46)
185 * Revision 1.6 2005/02/01 14:18:04 strk
186 * Made profiler start/stop inline
188 * Revision 1.5 2005/02/01 13:44:59 strk
189 * More profiling labels.
191 * Revision 1.4 2004/12/03 22:52:56 strk
192 * enforced const return of CoordinateSequence::toVector() method to derivate classes.
194 * Revision 1.3 2004/11/08 12:15:35 strk
195 * Added number of gathered timings in output.
197 * Revision 1.2 2004/11/08 11:19:39 strk
198 * Profiler::get() always return a Profile (new if not existant).
200 * Revision 1.1 2004/11/01 16:43:04 strk
201 * Added Profiler code.
202 * Temporarly patched a bug in DoubleBits (must check drawbacks).
203 * Various cleanups and speedups.
205 **********************************************************************/