Re-implement to be more threads-friendly (a first step towards thread-safety).

This commit is contained in:
Sylvain Pion 2008-12-04 01:57:33 +00:00
parent 68c1bcc095
commit aa06636838
2 changed files with 21 additions and 19 deletions

View File

@ -2,14 +2,17 @@
#include <CGAL/Profile_timer.h>
void f()
{
CGAL_TIME_PROFILER("seconds spent in this function (total time)");
// do something
double d = 1+1;
(void) d;
}
int main()
{
CGAL_TIME_PROFILER("seconds spent in this for loop");
for (int i=0; i<10; ++i)
{
// do something
double d = 1+1;
(void) d;
}
for (int i=0; i<100000; ++i)
f();
return 0;
}

View File

@ -23,8 +23,9 @@
// This file contains a class to help in profiling, together with macros
// triggered by CGAL_PROFILE to enable it:
//
// - Profile_timer which keeps track of the time spent in its scope-block.
// (be careful at recursive functions :-).
// - Profile_timer which keeps track of the time spent in its scope-block,
// it accumulates the timings if it goes there several times.
// Note: be careful at recursive functions...
//
// See also CGAL/Profile_counter.h
@ -39,26 +40,24 @@ CGAL_BEGIN_NAMESPACE
struct Profile_timer
{
class Local {
Profile_timer &p;
Real_timer rt;
Profile_timer *p;
public:
Local(Profile_timer& p_) : p(p_) { p.start(); }
~Local() { p.stop(); }
Local(Profile_timer* p_) : p(p_) { rt.start(); }
~Local() { rt.stop(); p->t += rt.time(); }
};
Profile_timer(const std::string & ss)
: s(ss) { t.reset(); }
void start() { t.start(); }
void stop() { t.stop(); }
: t(0) {}
~Profile_timer()
{
std::cerr << "[CGAL::Profile_timer] "
<< std::setw(10) << t.time() << " " << s << std::endl;
<< std::setw(10) << t << " " << s << std::endl;
}
private:
Real_timer t;
double t;
const std::string s;
};
@ -66,7 +65,7 @@ private:
#ifdef CGAL_PROFILE
# define CGAL_TIME_PROFILER(NAME) \
static CGAL::Profile_timer CGAL_profile_timer_tmp(NAME); \
CGAL::Profile_timer::Local CGAL_local_profile_timer_tmp(CGAL_profile_timer_tmp);
CGAL::Profile_timer::Local CGAL_local_profile_timer_tmp(&CGAL_profile_timer_tmp);
#else
# define CGAL_TIME_PROFILER(NAME)
#endif