24 #include "crocoddyl/core/utils/Stdafx.hh"
34 #include "crocoddyl/core/utils/stop-watch.hpp"
37 using std::ostringstream;
42 Stopwatch& getProfiler() {
43 static Stopwatch s(REAL_TIME);
48 records_of =
new map<string, PerformanceData>();
58 if (
mode == CPU_TIME) {
62 }
else if (
mode == REAL_TIME) {
68 LARGE_INTEGER intervals;
72 GetSystemTimeAsFileTime(&ft);
73 intervals.LowPart = ft.dwLowDateTime;
74 intervals.HighPart = ft.dwHighDateTime;
76 long double measure = intervals.QuadPart;
77 measure -= 116444736000000000.0;
78 measure /= 10000000.0;
84 gettimeofday(&tv, NULL);
86 long double measure = tv.tv_usec;
131 long double lapse = clock_end - perf_info.
clock_start;
133 if (
mode == CPU_TIME) lapse /= (double)CLOCKS_PER_SEC;
149 long double clock_end = clock();
159 long double lapse = clock_end - perf_info.
clock_start;
169 map<string, PerformanceData>::iterator it;
179 output <<
"\n" << std::setw(STOP_WATCH_MAX_NAME_LENGTH) << std::left <<
"*** PROFILING RESULTS [ms] ";
180 output << std::setw(STOP_WATCH_TIME_WIDTH) <<
"min"
182 output << std::setw(STOP_WATCH_TIME_WIDTH) <<
"avg"
184 output << std::setw(STOP_WATCH_TIME_WIDTH) <<
"max"
186 output << std::setw(STOP_WATCH_TIME_WIDTH) <<
"lastTime"
188 output << std::setw(STOP_WATCH_TIME_WIDTH) <<
"nSamples"
190 output << std::setw(STOP_WATCH_TIME_WIDTH) <<
"totalTime"
192 map<string, PerformanceData>::iterator it;
194 if (it->second.stops > 0)
report(it->first, precision, output);
216 std::cout <<
"Stopwatch active." << std::endl;
221 std::cout <<
"Stopwatch inactive." << std::endl;
233 output << std::setw(STOP_WATCH_MAX_NAME_LENGTH) << std::left << perf_name;
234 output << std::fixed << std::setprecision(precision) << std::setw(STOP_WATCH_TIME_WIDTH)
235 << (perf_info.
min_time * 1e3) <<
" ";
236 output << std::fixed << std::setprecision(precision) << std::setw(STOP_WATCH_TIME_WIDTH)
238 output << std::fixed << std::setprecision(precision) << std::setw(STOP_WATCH_TIME_WIDTH)
239 << (perf_info.
max_time * 1e3) <<
" ";
240 output << std::fixed << std::setprecision(precision) << std::setw(STOP_WATCH_TIME_WIDTH)
242 output << std::fixed << std::setprecision(precision) << std::setw(STOP_WATCH_TIME_WIDTH) << perf_info.
stops <<
" ";
243 output << std::fixed << std::setprecision(precision) << std::setw(STOP_WATCH_TIME_WIDTH)
253 if (
mode == CPU_TIME) lapse /= (double)CLOCKS_PER_SEC;