Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ set_property(CACHE HD_CPU_OPTIMIZATION PROPERTY STRINGS AUTO INTEL AMD ARM GENER
option(BUILD_WITH_CLI_TOOLS "Build with command line tools" ON)
option(BUILD_WITH_HD_MAPPER_APPLICATION "Build with hd_mapper tool" OFF)
option(BUILD_WITH_QUICK_START_DEMO "Build with quick_start_demo" OFF)
option(BUILD_WITH_UTL_PROFILER_DISABLED "Disable UTL profiler (zero overhead when ON)" ON)

# Three-way profiler backend: NONE (zero overhead) | UTL (lightweight) | TRACY (full profiler)
set(HDMAPPING_PROFILER "NONE" CACHE STRING "Profiler backend: NONE | UTL | TRACY")
set_property(CACHE HDMAPPING_PROFILER PROPERTY STRINGS NONE UTL TRACY)
option(BUILD_WITH_BUNDLED_FREEGLUT "Build with bundled FreeGlut" ON)
option(BUILD_WITH_BUNDLED_GLEW "Build with bundled GLEW" ON)
option(BUILD_WITH_BUNDLED_LIBLASZIP "Build with bundled Lib LASZIP" ON)
Expand Down Expand Up @@ -182,6 +185,24 @@ MESSAGE(STATUS "Using bundled spdlog from: ${THIRDPARTY_DIRECTORY}/spdlog")
add_subdirectory(${THIRDPARTY_DIRECTORY}/UTL)
MESSAGE(STATUS "Using bundled UTL from: ${THIRDPARTY_DIRECTORY}/UTL")

# ---- Profiler backend ----
if(HDMAPPING_PROFILER STREQUAL "TRACY")
include(FetchContent)
FetchContent_Declare(tracy
GIT_REPOSITORY https://github.com/wolfpld/tracy.git
GIT_TAG v0.13.1
GIT_SHALLOW TRUE
)
set(TRACY_ENABLE ON CACHE BOOL "" FORCE)
set(TRACY_ON_DEMAND ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(tracy)
message(STATUS "HDMapping profiler: Tracy v0.13.1 (on-demand)")
elseif(HDMAPPING_PROFILER STREQUAL "UTL")
message(STATUS "HDMapping profiler: UTL")
else()
message(STATUS "HDMapping profiler: NONE (disabled)")
endif()

if(BUILD_WITH_PYBIND)
message(STATUS "BUILD_WITH_PYBIND is enabled: fetching pybind.")
include(FetchContent)
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,15 @@ For example on WSL2 Ubuntu-24.04 following package is required to run GUI applic
```bash
sudo apt install zenity
```
# Profiling

You can use multiple backends to profile the code (UTL, Tracy-Profiler)

- Using Tracy-Profiler requires to install / build from source Tracy-Profiler from https://github.com/wolfpld/tracy/releases/tag/v0.13.1.
- Build and run the project with `cmake .. -DCMAKE_BUILD_TYPE=ReleaseWithDebInfo -DHDMAPPING_PROFILER=TRACY`
- Open Tracy Profiler and run e.g. `lidar_odometry_step_1`. Tracy-Profiler should recongnize the code and show the results.
-
To use UTL profiler build and run the project with `cmake .. -DCMAKE_BUILD_TYPE=ReleaseWithDebInfo -DHDMAPPING_PROFILER=UTL`

# Building Debian package.

Expand All @@ -561,6 +570,7 @@ To install package :
sudo dpkg -i hd_mapping-0.*.*-Linux.deb
```


![mandeye](images/softwareX1.png)

Mobile mapping systems is based on LiVOX MID360 - laser scanner with non repetetive scanning pattern.
Expand Down
24 changes: 18 additions & 6 deletions apps/lidar_odometry_step_1/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@ cmake_minimum_required(VERSION 4.0.0)

project(lidar_odometry_step_1)

# Apply the chosen profiler backend to a target.
function(target_apply_hdmapping_profiler TARGET)
if(HDMAPPING_PROFILER STREQUAL "TRACY")
target_compile_definitions(${TARGET} PRIVATE
HDMAPPING_PROFILER_TRACY TRACY_ENABLE TRACY_ON_DEMAND
UTL_PROFILER_DISABLE) # silence any remaining UTL_PROFILER_* calls
target_link_libraries(${TARGET} PRIVATE TracyClient)
elseif(HDMAPPING_PROFILER STREQUAL "UTL")
target_compile_definitions(${TARGET} PRIVATE HDMAPPING_PROFILER_UTL)
else()
target_compile_definitions(${TARGET} PRIVATE UTL_PROFILER_DISABLE)
endif()
endfunction()

# Source files
set(SOURCES
lidar_odometry_utils.h lidar_odometry_utils.cpp
Expand All @@ -20,9 +34,8 @@ add_executable(
lidar_odometry_step_1 lidar_odometry_gui.cpp ${SOURCES}
)

target_compile_definitions(lidar_odometry_step_1 PRIVATE
WITH_GUI=1
$<$<BOOL:${BUILD_WITH_UTL_PROFILER_DISABLED}>:BUILD_WITH_UTL_PROFILER_DISABLED>)
target_compile_definitions(lidar_odometry_step_1 PRIVATE WITH_GUI=1)
target_apply_hdmapping_profiler(lidar_odometry_step_1)

target_include_directories(
lidar_odometry_step_1
Expand Down Expand Up @@ -79,9 +92,8 @@ add_executable(
drag_folder_with_mandeye_data_and_drop_here-precision_forestry drag_folder_with_mandeye_data_and_drop_here-precision_forestry.cpp ${SOURCES}
)

target_compile_definitions(drag_folder_with_mandeye_data_and_drop_here-precision_forestry PRIVATE
WITH_GUI=1
$<$<BOOL:${BUILD_WITH_UTL_PROFILER_DISABLED}>:BUILD_WITH_UTL_PROFILER_DISABLED>)
target_compile_definitions(drag_folder_with_mandeye_data_and_drop_here-precision_forestry PRIVATE WITH_GUI=1)
target_apply_hdmapping_profiler(drag_folder_with_mandeye_data_and_drop_here-precision_forestry)

target_include_directories(
drag_folder_with_mandeye_data_and_drop_here-precision_forestry
Expand Down
46 changes: 46 additions & 0 deletions apps/lidar_odometry_step_1/hdmapping_profiler.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#pragma once

// HDMapping profiler backend — chosen at CMake configure time via HDMAPPING_PROFILER=NONE|UTL|TRACY
//
// Usage in source files:
// HDMAP_ZONE_SCOPE("label") — scoped zone, ends when enclosing scope exits
// HDMAP_ZONE_BEGIN(id, "label") — manual zone begin (id must be unique in scope)
// HDMAP_ZONE_END(id) — manual zone end

#if defined(HDMAPPING_PROFILER_TRACY)

#pragma message("HDMapping profiler: Tracy enabled")
#include <tracy/Tracy.hpp>
#include <tracy/TracyC.h>
// ZoneNamedN lets us embed __LINE__ in the variable name, avoiding clashes
// when multiple HDMAP_ZONE_SCOPE appear in the same function scope.
#define HDMAP_ZONE_SCOPE(name) ZoneNamedN(TracyConcat(hdmap_zone_, __LINE__), name, true)
#define HDMAP_ZONE_BEGIN(id, name) TracyCZoneN(hdmap_ctx_##id, name, true)
#define HDMAP_ZONE_END(id) TracyCZoneEnd(hdmap_ctx_##id)
#define HDMAP_FRAME_MARK FrameMark
#define HDMAP_MESSAGE(msg) TracyMessageL(msg)
#define HDMAP_MESSAGE_STR(str) TracyMessage((str).c_str(), (str).size())
#define HDMAP_PLOT(name, val) TracyPlot(name, static_cast<int64_t>(val))

#elif defined(HDMAPPING_PROFILER_UTL)

#include <UTL/profiler.hpp>
#define HDMAP_ZONE_SCOPE(name) UTL_PROFILER_SCOPE(name)
#define HDMAP_ZONE_BEGIN(id, name) UTL_PROFILER_BEGIN(id, name)
#define HDMAP_ZONE_END(id) UTL_PROFILER_END(id)
#define HDMAP_FRAME_MARK
#define HDMAP_MESSAGE(msg)
#define HDMAP_MESSAGE_STR(str)
#define HDMAP_PLOT(name, val)

#else

#define HDMAP_ZONE_SCOPE(name)
#define HDMAP_ZONE_BEGIN(id, name)
#define HDMAP_ZONE_END(id)
#define HDMAP_FRAME_MARK
#define HDMAP_MESSAGE(msg)
#define HDMAP_MESSAGE_STR(str)
#define HDMAP_PLOT(name, val)

#endif
12 changes: 6 additions & 6 deletions apps/lidar_odometry_step_1/lidar_odometry.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "lidar_odometry.h"
#include "hdmapping_profiler.hpp"
#include "tbb/tbb.h"
#include <UTL/profiler.hpp>
#include <mutex>

#include <Core/system_info.hpp>
Expand All @@ -15,7 +15,7 @@ bool load_data(
Imu& imu_data,
bool debugMsg)
{
UTL_PROFILER_SCOPE("load_data");
HDMAP_ZONE_SCOPE("load_data");
std::sort(input_file_names.begin(), input_file_names.end());
std::vector<std::string> csv_files, laz_files;
std::string sn_file;
Expand Down Expand Up @@ -304,7 +304,7 @@ bool load_data(

void calculate_trajectory(Trajectory& trajectory, Imu& imu_data, LidarOdometryParams& params, bool debugMsg)
{
UTL_PROFILER_SCOPE("calculate_trajectory");
HDMAP_ZONE_SCOPE("calculate_trajectory");

const float RAD_TO_DEG = 180.0f / static_cast<float>(M_PI);
int counter = 1;
Expand Down Expand Up @@ -462,7 +462,7 @@ bool compute_step_1(
std::vector<WorkerData>& worker_data,
const std::atomic<bool>& pause)
{
UTL_PROFILER_SCOPE("compute_step_1");
HDMAP_ZONE_SCOPE("compute_step_1");
int number_of_initial_points = 0;
double timestamp_begin = 0.0;

Expand Down Expand Up @@ -697,7 +697,7 @@ void run_consistency(std::vector<WorkerData>& worker_data, const LidarOdometryPa

void save_result(std::vector<WorkerData>& worker_data, LidarOdometryParams& params, fs::path outwd, double elapsed_time_s)
{
UTL_PROFILER_SCOPE("save_result");
HDMAP_ZONE_SCOPE("save_result");
std::filesystem::create_directory(outwd);
// concatenate data
std::vector<WorkerData> worker_data_concatenated;
Expand Down Expand Up @@ -1066,7 +1066,7 @@ std::string save_results_automatic(

std::vector<WorkerData> run_lidar_odometry(const std::string& input_dir, LidarOdometryParams& params)
{
UTL_PROFILER_SCOPE("run_lidar_odometry");
HDMAP_ZONE_SCOPE("run_lidar_odometry");
Session session;
std::vector<WorkerData> worker_data;
std::vector<std::string> input_file_names;
Expand Down
Loading
Loading