38 #include "ompl/tools/debug/Profiler.h"
88 data_[boost::this_thread::get_id()].events[name] += times;
95 AvgInfo &a = data_[boost::this_thread::get_id()].avg[name];
97 a.totalSqr += value*value;
105 data_[boost::this_thread::get_id()].time[name].set();
112 data_[boost::this_thread::get_id()].time[name].update();
120 printOnDestroy_ =
false;
123 out <<
" *** Profiling statistics. Total counted time : " <<
time::seconds(tinfo_.total) <<
" seconds" << std::endl;
128 for (std::map<boost::thread::id, PerThread>::const_iterator it = data_.begin() ; it != data_.end() ; ++it)
130 for (std::map<std::string, unsigned long int>::const_iterator iev = it->second.events.begin() ; iev != it->second.events.end(); ++iev)
131 combined.events[iev->first] += iev->second;
132 for (std::map<std::string, AvgInfo>::const_iterator iavg = it->second.avg.begin() ; iavg != it->second.avg.end(); ++iavg)
134 combined.avg[iavg->first].total += iavg->second.total;
135 combined.avg[iavg->first].totalSqr += iavg->second.totalSqr;
136 combined.avg[iavg->first].parts += iavg->second.parts;
138 for (std::map<std::string, TimeInfo>::const_iterator itm = it->second.time.begin() ; itm != it->second.time.end(); ++itm)
140 TimeInfo &tc = combined.time[itm->first];
141 tc.total = tc.total + itm->second.total;
142 tc.parts = tc.parts + itm->second.parts;
143 if (tc.shortest > itm->second.shortest)
144 tc.shortest = itm->second.shortest;
145 if (tc.longest < itm->second.longest)
146 tc.longest = itm->second.longest;
149 printThreadInfo(out, combined);
152 for (std::map<boost::thread::id, PerThread>::const_iterator it = data_.begin() ; it != data_.end() ; ++it)
154 out <<
"Thread " << it->first <<
":" << std::endl;
155 printThreadInfo(out, it->second);
162 std::stringstream ss;
175 unsigned long int value;
178 struct SortIntByValue
180 bool operator()(
const dataIntVal &a,
const dataIntVal &b)
const
182 return a.value > b.value;
192 struct SortDoubleByValue
194 bool operator()(
const dataDoubleVal &a,
const dataDoubleVal &b)
const
196 return a.value > b.value;
202 void ompl::tools::Profiler::printThreadInfo(std::ostream &out,
const PerThread &data)
206 std::vector<dataIntVal> events;
207 for (std::map<std::string, unsigned long int>::const_iterator iev = data.events.begin() ; iev != data.events.end() ; ++iev)
209 dataIntVal next = {iev->first, iev->second};
210 events.push_back(next);
212 std::sort(events.begin(), events.end(), SortIntByValue());
214 out <<
"Events:" << std::endl;
215 for (
unsigned int i = 0 ; i < events.size() ; ++i)
216 out << events[i].name <<
": " << events[i].value << std::endl;
218 std::vector<dataDoubleVal> avg;
219 for (std::map<std::string, AvgInfo>::const_iterator ia = data.avg.begin() ; ia != data.avg.end() ; ++ia)
221 dataDoubleVal next = {ia->first, ia->second.total / (double)ia->second.parts};
224 std::sort(avg.begin(), avg.end(), SortDoubleByValue());
226 out <<
"Averages:" << std::endl;
227 for (
unsigned int i = 0 ; i < avg.size() ; ++i)
229 const AvgInfo &a = data.avg.find(avg[i].name)->second;
230 out << avg[i].name <<
": " << avg[i].value <<
" (stddev = " <<
231 sqrt(fabs(a.totalSqr - (
double)a.parts * avg[i].value * avg[i].value) / ((
double)a.parts - 1.)) <<
")" << std::endl;
234 std::vector<dataDoubleVal> time;
236 for (std::map<std::string, TimeInfo>::const_iterator itm = data.time.begin() ; itm != data.time.end() ; ++itm)
238 dataDoubleVal next = {itm->first,
time::seconds(itm->second.total)};
239 time.push_back(next);
242 std::sort(time.begin(), time.end(), SortDoubleByValue());
244 out <<
"Blocks of time:" << std::endl;
246 double unaccounted = total;
247 for (
unsigned int i = 0 ; i < time.size() ; ++i)
249 const TimeInfo &d = data.time.find(time[i].name)->second;
253 out << time[i].name <<
": " << time[i].value <<
"s (" << (100.0 * time[i].value/total) <<
"%), ["
254 << tS <<
"s --> " << tL <<
" s], " << d.parts <<
" parts";
256 out <<
", " << (
time::seconds(d.total) / (double)d.parts) <<
" s on average";
258 unaccounted -= time[i].value;
261 if (unaccounted >= 0.0)
263 out <<
"Unaccounted time : " << unaccounted;
265 out <<
" (" << (100.0 * unaccounted / total) <<
" %)";