38 #if MOVEIT_ENABLE_PROFILING
89 data_[boost::this_thread::get_id()].events[
name] += times;
96 AvgInfo& a =
data_[boost::this_thread::get_id()].avg[
name];
98 a.totalSqr += value * value;
106 data_[boost::this_thread::get_id()].time[
name].set();
113 data_[boost::this_thread::get_id()].time[
name].update();
119 inline double to_seconds(
const boost::posix_time::time_duration&
d)
121 return (
double)
d.total_microseconds() / 1000000.0;
132 out <<
" *** Profiling statistics. Total counted time : " << to_seconds(
tinfo_.
total) <<
" seconds" << std::endl;
137 for (std::map<boost::thread::id, PerThread>::const_iterator it =
data_.begin(); it !=
data_.end(); ++it)
139 for (
const std::pair<const std::string, unsigned long int>&
event : it->second.events)
140 combined.events[
event.first] +=
event.second;
141 for (
const std::pair<const std::string, AvgInfo>& iavg : it->second.avg)
143 combined.avg[iavg.first].total += iavg.second.total;
144 combined.avg[iavg.first].totalSqr += iavg.second.totalSqr;
145 combined.avg[iavg.first].parts += iavg.second.parts;
147 for (
const std::pair<const std::string, TimeInfo>& itm : it->second.time)
149 TimeInfo& tc = combined.time[itm.first];
150 tc.total = tc.total + itm.second.total;
151 tc.parts = tc.parts + itm.second.parts;
152 if (tc.shortest > itm.second.shortest)
153 tc.shortest = itm.second.shortest;
154 if (tc.longest < itm.second.longest)
155 tc.longest = itm.second.longest;
161 for (std::map<boost::thread::id, PerThread>::const_iterator it =
data_.begin(); it !=
data_.end(); ++it)
163 out <<
"Thread " << it->first <<
":" << std::endl;
171 std::stringstream ss;
183 unsigned long int value_;
186 struct SortIntByValue
188 bool operator()(
const DataIntVal& a,
const DataIntVal& b)
const
190 return a.value_ > b.value_;
200 struct SortDoubleByValue
202 bool operator()(
const DataDoubleVal& a,
const DataDoubleVal& b)
const
204 return a.value_ > b.value_;
214 std::vector<DataIntVal> events;
215 for (
const std::pair<const std::string, unsigned long>&
event : data.events)
217 DataIntVal
next = {
event.first,
event.second };
218 events.push_back(next);
220 std::sort(events.begin(), events.end(), SortIntByValue());
222 out <<
"Events:" << std::endl;
223 for (
const DataIntVal&
event : events)
224 out <<
event.name_ <<
": " <<
event.value_ << std::endl;
226 std::vector<DataDoubleVal> avg;
227 for (
const std::pair<const std::string, AvgInfo>& ia : data.avg)
229 DataDoubleVal
next = { ia.first, ia.second.total / (double)ia.second.parts };
232 std::sort(avg.begin(), avg.end(), SortDoubleByValue());
234 out <<
"Averages:" << std::endl;
235 for (
const DataDoubleVal&
average : avg)
237 const AvgInfo& a = data.avg.find(
average.name_)->second;
239 << sqrt(fabs(a.totalSqr - (
double)a.parts *
average.value_ *
average.value_) / ((
double)a.parts - 1.)) <<
")"
243 std::vector<DataDoubleVal> time;
245 for (
const std::pair<const std::string, TimeInfo>& itm : data.time)
247 DataDoubleVal
next = { itm.first, to_seconds(itm.second.total) };
248 time.push_back(next);
251 std::sort(time.begin(), time.end(), SortDoubleByValue());
253 out <<
"Blocks of time:" << std::endl;
255 double unaccounted = total;
256 for (DataDoubleVal& time_block : time)
258 const TimeInfo&
d = data.time.find(time_block.name_)->second;
260 double t_s = to_seconds(
d.shortest);
261 double t_l = to_seconds(
d.longest);
262 out << time_block.name_ <<
": " << time_block.value_ <<
"s (" << (100.0 * time_block.value_ / total) <<
"%), ["
263 << t_s <<
"s --> " << t_l <<
" s], " <<
d.parts <<
" parts";
266 double pavg = to_seconds(
d.total) / (double)
d.parts;
267 out <<
", " << pavg <<
" s on average";
269 out <<
" (" << 1.0 / pavg <<
" /s)";
272 unaccounted -= time_block.value_;
275 if (unaccounted >= 0.0)
277 out <<
"Unaccounted time : " << unaccounted;
279 out <<
" (" << (100.0 * unaccounted / total) <<
" %)";