9 #ifndef LIBCARLA_ENABLE_PROFILER 10 # define CARLA_PROFILE_SCOPE(context, profiler_name) 11 # define CARLA_PROFILE_FPS(context, profiler_name) 27 explicit ProfilerData(std::string name,
bool print_fps =
false)
28 : _name(std::move(name)),
29 _print_fps(print_fps) {}
33 void Annotate(
const StopWatch &stop_watch) {
34 const auto elapsed_microseconds = stop_watch.GetElapsedTime<std::chrono::microseconds>();
36 _total_microseconds += elapsed_microseconds;
37 _max_elapsed = std::max(elapsed_microseconds, _max_elapsed);
38 _min_elapsed =
std::min(elapsed_microseconds, _min_elapsed);
41 float average()
const {
42 return ms(_total_microseconds) /
static_cast<float>(_count);
45 float maximum()
const {
46 return ms(_max_elapsed);
49 float minimum()
const {
50 return ms(_min_elapsed);
55 static inline float ms(
size_t microseconds) {
56 return 1e-3f *
static_cast<float>(microseconds);
59 static inline float fps(
float milliseconds) {
60 return milliseconds > 0.0f ? (1e3f / milliseconds) : std::numeric_limits<float>::max();
63 const std::string _name;
65 const bool _print_fps;
69 size_t _total_microseconds = 0u;
71 size_t _max_elapsed = 0u;
73 size_t _min_elapsed = std::numeric_limits<size_t>::max();
76 class ScopedProfiler {
79 explicit ScopedProfiler(ProfilerData &parent) : _profiler(parent) {}
83 _profiler.Annotate(_stop_watch);
88 ProfilerData &_profiler;
97 #ifdef LIBCARLA_WITH_GTEST 98 # define LIBCARLA_GTEST_GET_TEST_NAME() std::string(::testing::UnitTest::GetInstance()->current_test_info()->name()) 100 # define LIBCARLA_GTEST_GET_TEST_NAME() std::string("") 101 #endif // LIBCARLA_WITH_GTEST 103 #define CARLA_PROFILE_SCOPE(context, profiler_name) \ 104 static thread_local ::carla::profiler::detail::ProfilerData carla_profiler_ ## context ## _ ## profiler_name ## _data( \ 105 LIBCARLA_GTEST_GET_TEST_NAME() + "." #context "." #profiler_name); \ 106 ::carla::profiler::detail::ScopedProfiler carla_profiler_ ## context ## _ ## profiler_name ## _scoped_profiler( \ 107 carla_profiler_ ## context ## _ ## profiler_name ## _data); 109 #define CARLA_PROFILE_FPS(context, profiler_name) \ 111 static thread_local ::carla::StopWatch stop_watch; \ 113 static thread_local bool first_time = true; \ 115 static thread_local ::carla::profiler::detail::ProfilerData profiler_data( \ 116 LIBCARLA_GTEST_GET_TEST_NAME() + "." #context "." #profiler_name, true); \ 117 profiler_data.Annotate(stop_watch); \ 119 first_time = false; \ 121 stop_watch.Restart(); \ 124 #endif // LIBCARLA_ENABLE_PROFILER This file contains definitions of common data structures used in traffic manager. ...
detail::StopWatchTmpl< std::chrono::steady_clock > StopWatch
double min(double v1, double v2)