Add spdlog logging and UTL profiling to lidar odometry hot path #328
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
std::cout/std::cerrinlidar_odometry_utils_optimizers.cppwith structured, level-based logging (spdlog::info,spdlog::warn,spdlog::debug)std::chronotiming withspdlog::stopwatchfor cleaner timer codecompute_step_2andoptimize_lidar_odometryhot paths for performance analysis, controlled byUTL_PROFILER_DISABLECMake option (disabled by default for zero overhead)3rdparty/Note: Currently spdlog is only used in
lidar_odometry_utils_optimizers.cpp. The remaining source files still usestd::cout/`std::cerr. I suggest gradually migrating the rest of the project to spdlog in follow-up PRs.Note: - Profiler macros are kept in the code - the benefit is you can enable profiling on any build just by flipping one CMake option, no code changes, no risk of forgetting to re-add instrumentation points
Details
spdlog integration
std::cout/std::cerrstatements inlidar_odometry_utils_optimizers.cppwithspdlog::info()andspdlog::warn()std::chronotiming patterns withspdlog::stopwatch(stopwatch_total,stopwatch_worker,stopwatch_realtime,stopwatch_update)main()withspdlog::cfg::load_env_levels()(runtime level control viaSPDLOG_LEVELenv var) andspdlog::flush_on(spdlog::level::warn)spdlog::spdlogto all targets that compile lidar_odometry source files (step1, pybind, 4 dependent apps)Enabling debug logging at runtime:
Set the
SPDLOG_LEVEL="debug"environment variable before running the application. No recompilation needed.Available levels (from most to least verbose):
trace,debug,info,warn,err,critical,off. Default level isinfo.UTL profiler instrumentation
Profiler segments added to the optimization hot path. The resulting profile looks like this:
Such profile could be usefull to understand the performance difference between windows and linux.
CMake configuration
UTL_PROFILER_DISABLEoption (defaultON) — when ON, all profiler macros compile to no-ops with zero overheadcmake -DUTL_PROFILER_DISABLE=OFF ...UTL_PROFILER_DISABLEalways definedlidar_odometry_step_1andpybindrespect the CMake option via generator expression