38 #if MOVEIT_ENABLE_PROFILING 90 data_[boost::this_thread::get_id()].events[name] += times;
97 AvgInfo& a =
data_[boost::this_thread::get_id()].avg[name];
99 a.totalSqr += value * value;
107 data_[boost::this_thread::get_id()].time[name].set();
114 data_[boost::this_thread::get_id()].time[name].update();
120 inline double to_seconds(
const boost::posix_time::time_duration& d)
122 return (
double)d.total_microseconds() / 1000000.0;
133 out <<
" *** Profiling statistics. Total counted time : " << to_seconds(
tinfo_.
total) <<
" seconds" << std::endl;
138 for (std::map<boost::thread::id, PerThread>::const_iterator it =
data_.begin(); it !=
data_.end(); ++it)
140 for (std::map<std::string, unsigned long int>::const_iterator iev = it->second.events.begin();
141 iev != it->second.events.end(); ++iev)
142 combined.events[iev->first] += iev->second;
143 for (std::map<std::string, AvgInfo>::const_iterator iavg = it->second.avg.begin(); iavg != it->second.avg.end();
146 combined.avg[iavg->first].total += iavg->second.total;
147 combined.avg[iavg->first].totalSqr += iavg->second.totalSqr;
148 combined.avg[iavg->first].parts += iavg->second.parts;
150 for (std::map<std::string, TimeInfo>::const_iterator itm = it->second.time.begin(); itm != it->second.time.end();
153 TimeInfo& tc = combined.time[itm->first];
154 tc.total = tc.total + itm->second.total;
155 tc.parts = tc.parts + itm->second.parts;
156 if (tc.shortest > itm->second.shortest)
157 tc.shortest = itm->second.shortest;
158 if (tc.longest < itm->second.longest)
159 tc.longest = itm->second.longest;
165 for (std::map<boost::thread::id, PerThread>::const_iterator it =
data_.begin(); it !=
data_.end(); ++it)
167 out <<
"Thread " << it->first <<
":" << std::endl;
175 std::stringstream ss;
187 unsigned long int value;
190 struct SortIntByValue
192 bool operator()(
const dataIntVal& a,
const dataIntVal& b)
const 194 return a.value > b.value;
204 struct SortDoubleByValue
206 bool operator()(
const dataDoubleVal& a,
const dataDoubleVal& b)
const 208 return a.value > b.value;
218 std::vector<dataIntVal> events;
219 for (std::map<std::string, unsigned long int>::const_iterator iev = data.events.begin(); iev != data.events.end();
222 dataIntVal next = { iev->first, iev->second };
223 events.push_back(next);
225 std::sort(events.begin(), events.end(), SortIntByValue());
227 out <<
"Events:" << std::endl;
228 for (
unsigned int i = 0; i < events.size(); ++i)
229 out << events[i].name <<
": " << events[i].value << std::endl;
231 std::vector<dataDoubleVal> avg;
232 for (std::map<std::string, AvgInfo>::const_iterator ia = data.avg.begin(); ia != data.avg.end(); ++ia)
234 dataDoubleVal next = { ia->first, ia->second.total / (double)ia->second.parts };
237 std::sort(avg.begin(), avg.end(), SortDoubleByValue());
239 out <<
"Averages:" << std::endl;
240 for (
unsigned int i = 0; i < avg.size(); ++i)
242 const AvgInfo& a = data.avg.find(avg[i].name)->second;
243 out << avg[i].name <<
": " << avg[i].value <<
" (stddev = " 244 <<
sqrt(fabs(a.totalSqr - (
double)a.parts * avg[i].value * avg[i].value) / ((
double)a.parts - 1.)) <<
")" 248 std::vector<dataDoubleVal> time;
250 for (std::map<std::string, TimeInfo>::const_iterator itm = data.time.begin(); itm != data.time.end(); ++itm)
252 dataDoubleVal next = { itm->first, to_seconds(itm->second.total) };
253 time.push_back(next);
256 std::sort(time.begin(), time.end(), SortDoubleByValue());
258 out <<
"Blocks of time:" << std::endl;
260 double unaccounted = total;
261 for (
unsigned int i = 0; i < time.size(); ++i)
263 const TimeInfo& d = data.time.find(time[i].name)->second;
265 double tS = to_seconds(d.shortest);
266 double tL = to_seconds(d.longest);
267 out << time[i].name <<
": " << time[i].value <<
"s (" << (100.0 * time[i].value / total) <<
"%), [" << tS
268 <<
"s --> " << tL <<
" s], " << d.parts <<
" parts";
271 double pavg = to_seconds(d.total) / (double)d.parts;
272 out <<
", " << pavg <<
" s on average";
274 out <<
" (" << 1.0 / pavg <<
" /s)";
277 unaccounted -= time[i].value;
280 if (unaccounted >= 0.0)
282 out <<
"Unaccounted time : " << unaccounted;
284 out <<
" (" << (100.0 * unaccounted / total) <<
" %)";
#define ROS_INFO_STREAM_NAMED(name, args)
INLINE Rall1d< T, V, S > sqrt(const Rall1d< T, V, S > &arg)
Main namespace for MoveIt!