Skip to content

Conversation

@bloom256
Copy link
Collaborator

Summary

  • Add spdlog logging library to replace std::cout/std::cerr in lidar_odometry_utils_optimizers.cpp with structured, level-based logging (spdlog::info, spdlog::warn, spdlog::debug)
  • Replace manual std::chrono timing with spdlog::stopwatch for cleaner timer code
  • Add UTL profiler instrumentation to compute_step_2 and optimize_lidar_odometry hot paths for performance analysis, controlled by UTL_PROFILER_DISABLE CMake option (disabled by default for zero overhead)
  • Add spdlog (v1.17.0) and UTL (v9.0.0) as git submodules under 3rdparty/

Note: Currently spdlog is only used in lidar_odometry_utils_optimizers.cpp. The remaining source files still use std::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

  • Replaced all active std::cout/std::cerr statements in lidar_odometry_utils_optimizers.cpp with spdlog::info() and spdlog::warn()
  • Replaced 4 manual std::chrono timing patterns with spdlog::stopwatch (stopwatch_total, stopwatch_worker, stopwatch_realtime, stopwatch_update)
  • Initialized spdlog in main() with spdlog::cfg::load_env_levels() (runtime level control via SPDLOG_LEVEL env var) and spdlog::flush_on(spdlog::level::warn)
  • Linked spdlog::spdlog to 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.

# Linux/macOS
SPDLOG_LEVEL=debug ./lidar_odometry_step_1 ...

# PowerShell (Windows)
$env:SPDLOG_LEVEL = "debug"
.\lidar_odometry_step_1.exe ...

Available levels (from most to least verbose): trace, debug, info, warn, err, critical, off. Default level is info.

UTL profiler instrumentation

Profiler segments added to the optimization hot path. The resulting profile looks like this:

-------------------- UTL PROFILING RESULTS ---------------------

# Thread [main] (reuse 0) (joined) (runtime -> 79459.01 ms)
   - 62.43% ------ | 49602.99 ms |          compute_step_2 | lidar_odometry_utils_optimizers.cpp:2245, compute_step_2()          |
     - 2.21% ----- |  1759.80 ms |       before_iterations | lidar_odometry_utils_optimizers.cpp:2310, compute_step_2()          |
     - 44.12% ---- | 35059.92 ms |          iteration_loop | lidar_odometry_utils_optimizers.cpp:2505, compute_step_2()          |
       - 44.11% -- | 35048.11 ms | optimize_lidar_odometry | lidar_odometry_utils_optimizers.cpp:1778, optimize_lidar_odometry() |
         - 0.25% - |   196.88 ms |             pre_hessian | lidar_odometry_utils_optimizers.cpp:1779, optimize_lidar_odometry() |
         - 33.18%  | 26366.49 ms |         hessian_compute | lidar_odometry_utils_optimizers.cpp:1813, optimize_lidar_odometry() |
         - 10.51%  |  8349.21 ms |            post_hessian | lidar_odometry_utils_optimizers.cpp:1891, optimize_lidar_odometry() |
     - 15.90% ---- | 12630.85 ms |        after_iterations | lidar_odometry_utils_optimizers.cpp:2560, compute_step_2()          |
       - 0.16% --- |   123.46 ms |           temp_save_laz | lidar_odometry_utils_optimizers.cpp:2591, compute_step_2()          |
       - 2.31% --- |  1835.14 ms |    propagate_trajectory | lidar_odometry_utils_optimizers.cpp:2630, compute_step_2()          |
       - 2.14% --- |  1696.83 ms | transform_points_global | lidar_odometry_utils_optimizers.cpp:2647, compute_step_2()          |
       - 11.24% -- |  8931.01 ms |              update_rgd | lidar_odometry_utils_optimizers.cpp:2657, compute_step_2()          |

Such profile could be usefull to understand the performance difference between windows and linux.

CMake configuration

  • UTL_PROFILER_DISABLE option (default ON) — when ON, all profiler macros compile to no-ops with zero overhead
  • To enable profiling: cmake -DUTL_PROFILER_DISABLE=OFF ...
  • Dependent apps that don't need profiling have UTL_PROFILER_DISABLE always defined
  • lidar_odometry_step_1 and pybind respect the CMake option via generator expression

@JanuszBedkowski JanuszBedkowski merged commit 1412c38 into MapsHD:main Jan 27, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants