128 data_[std::this_thread::get_id()].events[
name] += times;
165 data_[std::this_thread::get_id()].time[
name].set();
173 data_[std::this_thread::get_id()].time[
name].update();
191 out <<
" *** Profiling statistics. Total counted time : " <<
time::seconds(
tinfo_.
total) <<
" seconds" << std::endl;
196 for (std::map<std::thread::id, PerThread>::const_iterator it =
data_.begin() ; it !=
data_.end() ; ++it)
198 for (std::map<std::string, unsigned long int>::const_iterator iev = it->second.events.begin() ; iev != it->second.events.end(); ++iev)
199 combined.
events[iev->first] += iev->second;
200 for (std::map<std::string, AvgInfo>::const_iterator iavg = it->second.avg.begin() ; iavg != it->second.avg.end(); ++iavg)
202 combined.
avg[iavg->first].total += iavg->second.total;
203 combined.
avg[iavg->first].totalSqr += iavg->second.totalSqr;
204 combined.
avg[iavg->first].parts += iavg->second.parts;
206 for (std::map<std::string, TimeInfo>::const_iterator itm = it->second.time.begin() ; itm != it->second.time.end(); ++itm)
211 if (tc.
shortest > itm->second.shortest)
213 if (tc.
longest < itm->second.longest)
214 tc.
longest = itm->second.longest;
220 for (std::map<std::thread::id, PerThread>::const_iterator it =
data_.begin() ; it !=
data_.end() ; ++it)
222 out <<
"Thread " << it->first <<
":" << std::endl;
277 std::vector<detail::dataIntVal> events;
278 for (std::map<std::string, unsigned long int>::const_iterator iev = data.
events.begin() ; iev != data.
events.end() ; ++iev)
281 events.push_back(next);
285 out <<
"Events:" << std::endl;
286 for (
unsigned int i = 0 ; i < events.size() ; ++i)
287 out << events[i].
name <<
": " << events[i].value << std::endl;
289 std::vector<detail::dataDoubleVal> avg;
290 for (std::map<std::string, AvgInfo>::const_iterator ia = data.
avg.begin() ; ia != data.
avg.end() ; ++ia)
297 out <<
"Averages:" << std::endl;
298 for (
unsigned int i = 0 ; i < avg.size() ; ++i)
301 out << avg[i].name <<
": " << avg[i].value <<
" (stddev = " <<
302 std::sqrt(std::abs(a.
totalSqr - (
double)a.
parts * avg[i].value * avg[i].value) / ((
double)a.
parts - 1.)) <<
")" << std::endl;
305 std::vector<detail::dataDoubleVal> time;
307 for (std::map<std::string, TimeInfo>::const_iterator itm = data.
time.begin() ; itm != data.
time.end() ; ++itm)
310 time.push_back(next);
315 out <<
"Blocks of time:" << std::endl;
317 double unaccounted = total;
318 for (
unsigned int i = 0 ; i < time.size() ; ++i)
324 out << time[i].name <<
": " << time[i].value <<
"s (" << (100.0 * time[i].value/total) <<
"%), [" 325 << tS <<
"s --> " << tL <<
" s], " << d.
parts <<
" parts";
329 unaccounted -= time[i].value;
331 out <<
"Unaccounted time : " << unaccounted;
333 out <<
" (" << (100.0 * unaccounted / total) <<
" %)";
371 Profiler::ScopedStart::ScopedStart(
Profiler& prof)
379 Profiler::ScopedStart::~ScopedStart()
386 Profiler::ScopedBlock::ScopedBlock(
const std::string&
name,
Profiler& prof)
393 Profiler::ScopedBlock::~ScopedBlock()
time::point start
The point in time when counting time started.
std::chrono::system_clock::duration duration
Representation of a time duration.
FCL_EXPORT duration seconds(double sec)
Return the time duration representing a given number of seconds.
unsigned long int parts
Number of times a value was added to this structure.
time::duration shortest
The shortest counted time interval.
Information about time spent in a section of the code.
void update(void)
Add the counted time to the total time.
std::map< std::string, unsigned long int > events
The stored events.
void clear(void)
Clear counted time and events.
static bool Running(void)
Check if the profiler is counting time or not.
unsigned long int parts
Number of times a chunk of time was added to this structure.
FCL_EXPORT point now(void)
Get the current time point.
static void Begin(const std::string &name)
Begin counting time for a specific chunk of code.
double total
The sum of the values to average.
EndPoint * next[3]
the next end point in the end point list
static void End(const std::string &name)
Stop counting time for a specific chunk of code.
Information maintained about averaged values.
static void Status(std::ostream &out=std::cout, bool merge=true)
Print the status of the profiled code chunks and events. Optionally, computation done by different th...
static void Event(const std::string &name, const unsigned int times=1)
Count a specific event for a number of times.
static Profiler & Instance(void)
Return an instance of the class.
void average(const std::string &name, const double value)
Maintain the average of a specific value.
void status(std::ostream &out=std::cout, bool merge=true)
Print the status of the profiled code chunks and events. Optionally, computation done by different th...
bool operator()(const dataDoubleVal &a, const dataDoubleVal &b) const
void event(const std::string &name, const unsigned int times=1)
Count a specific event for a number of times.
time::duration longest
The longest counted time interval.
std::map< std::string, AvgInfo > avg
The stored averages.
bool running(void) const
Check if the profiler is counting time or not.
std::map< std::string, TimeInfo > time
The amount of time spent in various places.
void printThreadInfo(std::ostream &out, const PerThread &data)
static void Start(void)
Start counting time.
void stop(void)
Stop counting time.
~Profiler(void)
Destructor.
double totalSqr
The sub of squares of the values to average.
static void Clear(void)
Clear counted time and events.
Information to be maintained for each thread.
bool operator()(const dataIntVal &a, const dataIntVal &b) const
void end(const std::string &name)
Stop counting time for a specific chunk of code.
static void Average(const std::string &name, const double value)
Maintain the average of a specific value.
time::duration total
Total time counted.
void set(void)
Begin counting time.
void start(void)
Start counting time.
This is a simple thread-safe tool for counting time spent in various chunks of code. This is different from external profiling tools in that it allows the user to count time spent in various bits of code (sub-function granularity) or count how many times certain pieces of code are executed.
void begin(const std::string &name)
Begin counting time for a specific chunk of code.
Profiler(const Profiler &)=delete
static void Stop(void)
Stop counting time.
std::map< std::thread::id, PerThread > data_