37 #include "ompl/tools/debug/Profiler.h"
88 data_[std::this_thread::get_id()].events[name] += times;
95 AvgInfo &a = data_[std::this_thread::get_id()].avg[name];
97 a.totalSqr += value * value;
105 data_[std::this_thread::get_id()].time[name].set();
112 data_[std::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<std::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();
131 iev != it->second.events.end(); ++iev)
132 combined.events[iev->first] += iev->second;
133 for (std::map<std::string, AvgInfo>::const_iterator iavg = it->second.avg.begin();
134 iavg != it->second.avg.end(); ++iavg)
136 combined.avg[iavg->first].total += iavg->second.total;
137 combined.avg[iavg->first].totalSqr += iavg->second.totalSqr;
138 combined.avg[iavg->first].parts += iavg->second.parts;
140 for (std::map<std::string, TimeInfo>::const_iterator itm = it->second.time.begin();
141 itm != it->second.time.end(); ++itm)
143 TimeInfo &tc = combined.time[itm->first];
144 tc.total = tc.total + itm->second.total;
145 tc.parts = tc.parts + itm->second.parts;
146 if (tc.shortest > itm->second.shortest)
147 tc.shortest = itm->second.shortest;
148 if (tc.longest < itm->second.longest)
149 tc.longest = itm->second.longest;
152 printThreadInfo(out, combined);
155 for (std::map<std::thread::id, PerThread>::const_iterator it = data_.begin(); it != data_.end(); ++it)
157 out <<
"Thread " << it->first <<
":" << std::endl;
158 printThreadInfo(out, it->second);
165 std::stringstream ss;
177 unsigned long int value;
180 struct SortIntByValue
182 bool operator()(
const dataIntVal &a,
const dataIntVal &b)
const
184 return a.value > b.value;
194 struct SortDoubleByValue
196 bool operator()(
const dataDoubleVal &a,
const dataDoubleVal &b)
const
198 return a.value > b.value;
204 void ompl::tools::Profiler::printThreadInfo(std::ostream &out,
const PerThread &data)
208 std::vector<dataIntVal> events;
209 for (std::map<std::string, unsigned long int>::const_iterator iev = data.events.begin(); iev != data.events.end();
212 dataIntVal next = {iev->first, iev->second};
213 events.push_back(next);
215 std::sort(events.begin(), events.end(), SortIntByValue());
217 out <<
"Events:" << std::endl;
218 for (
unsigned int i = 0; i < events.size(); ++i)
219 out << events[i].name <<
": " << events[i].value << std::endl;
221 std::vector<dataDoubleVal> avg;
222 for (std::map<std::string, AvgInfo>::const_iterator ia = data.avg.begin(); ia != data.avg.end(); ++ia)
224 dataDoubleVal next = {ia->first, ia->second.total / (double)ia->second.parts};
227 std::sort(avg.begin(), avg.end(), SortDoubleByValue());
229 out <<
"Averages:" << std::endl;
230 for (
unsigned int i = 0; i < avg.size(); ++i)
232 const AvgInfo &a = data.avg.find(avg[i].name)->second;
233 out << avg[i].name <<
": " << avg[i].value <<
" (stddev = "
234 << std::sqrt(std::abs(a.totalSqr - (
double)a.parts * avg[i].value * avg[i].value) / ((
double)a.parts - 1.))
238 std::vector<dataDoubleVal> time;
240 for (std::map<std::string, TimeInfo>::const_iterator itm = data.time.begin(); itm != data.time.end(); ++itm)
242 dataDoubleVal next = {itm->first,
time::seconds(itm->second.total)};
243 time.push_back(next);
246 std::sort(time.begin(), time.end(), SortDoubleByValue());
248 out <<
"Blocks of time:" << std::endl;
250 double unaccounted = total;
251 for (
unsigned int i = 0; i < time.size(); ++i)
253 const TimeInfo &d = data.time.find(time[i].name)->second;
257 out << time[i].name <<
": " << time[i].value <<
"s (" << (100.0 * time[i].value / total) <<
"%), [" << tS
258 <<
"s --> " << tL <<
" s], " << d.parts <<
" parts";
260 out <<
", " << (
time::seconds(d.total) / (double)d.parts) <<
" s on average";
262 unaccounted -= time[i].value;
265 if (unaccounted >= 0.0)
267 out <<
"Unaccounted time : " << unaccounted;
269 out <<
" (" << (100.0 * unaccounted / total) <<
" %)";