39 #ifndef HPP_FCL_UTIL_PROFILER 40 #define HPP_FCL_UTIL_PROFILER 42 #define ENABLE_PROFILING 1 44 #ifndef ENABLE_PROFILING 49 # define ENABLE_PROFILING 0 51 # define ENABLE_PROFILING 1 61 #include <boost/thread.hpp> 62 #include <boost/noncopyable.hpp> 63 #include <boost/date_time/posix_time/posix_time.hpp> 75 typedef boost::posix_time::ptime
point;
78 typedef boost::posix_time::time_duration
duration;
81 inline point
now(
void)
83 return boost::posix_time::microsec_clock::universal_time();
89 long int s =
static_cast<long int>(sec);
90 long int us = ((
static_cast<long int>(sec) - s) * 1000000);
97 return (
double)d.total_microseconds() / 1000000.0;
165 Profiler(
bool printOnDestroy =
false,
bool autoStart =
false) : running_(false), printOnDestroy_(printOnDestroy)
174 if (printOnDestroy_ && !data_.empty())
206 static void Event(
const std::string& name,
const unsigned int times = 1)
208 Instance().
event(name, times);
212 void event(
const std::string &name,
const unsigned int times = 1);
215 static void Average(
const std::string& name,
const double value)
217 Instance().
average(name, value);
221 void average(
const std::string &name,
const double value);
224 static void Begin(
const std::string &name)
226 Instance().
begin(name);
230 static void End(
const std::string &name)
232 Instance().
end(name);
236 void begin(
const std::string &name);
239 void end(
const std::string &name);
244 static void Status(std::ostream &out = std::cout,
bool merge =
true)
246 Instance().
status(out, merge);
252 void status(std::ostream &out = std::cout,
bool merge =
true);
271 TimeInfo(
void) : total(0, 0, 0, 0), shortest(boost::posix_time::pos_infin), longest(boost::posix_time::neg_infin), parts(0)
285 unsigned long int parts;
319 unsigned long int parts;
326 std::map<std::string, unsigned long int> events;
329 std::map<std::string, AvgInfo> avg;
332 std::map<std::string, TimeInfo> time;
335 void printThreadInfo(std::ostream &out,
const PerThread &data);
338 std::map<boost::thread::id, PerThread> data_;
341 bool printOnDestroy_;
401 static void Start(
void)
405 static void Stop(
void)
409 static void Clear(
void)
425 static void Event(
const std::string&,
const unsigned int = 1)
429 void event(
const std::string &,
const unsigned int = 1)
433 static void Average(
const std::string&,
const double)
437 void average(
const std::string &,
const double)
441 static void Begin(
const std::string &)
445 static void End(
const std::string &)
449 void begin(
const std::string &)
453 void end(
const std::string &)
457 static void Status(std::ostream & = std::cout,
bool =
true)
461 void status(std::ostream & = std::cout,
bool =
true)
465 bool running(
void)
const 470 static bool Running(
void)
boost::posix_time::ptime point
Representation of a point in time.
Definition: profile.h:75
Main namespace.
Definition: AABB.h:43
double seconds(const duration &d)
Return the number of seconds that a time duration represents.
Definition: profile.h:95
duration seconds(double sec)
Return the time duration representing a given number of seconds.
Definition: profile.h:87
point now(void)
Get the current time point.
Definition: profile.h:81
boost::posix_time::time_duration duration
Representation of a time duration.
Definition: profile.h:78