Skip to content

Commit

Permalink
Add SANITIZE option to package to help with debugging, document it
Browse files Browse the repository at this point in the history
Signed-off-by: Evan Flynn <[email protected]>
  • Loading branch information
flynneva committed Jul 23, 2023
1 parent 4f6cd51 commit b221d7f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ rclcpp_components_register_node(${PROJECT_NAME}_node
EXECUTABLE ${PROJECT_NAME}_node_exe
)

if(SANITIZE)
target_compile_options(${PROJECT_NAME} PUBLIC -fsanitize=address -fsanitize=leak)
target_link_libraries(${PROJECT_NAME} -fsanitize=address -fsanitize=leak)
target_compile_options(${PROJECT_NAME}_node PUBLIC -fsanitize=address -fsanitize=leak)
target_link_libraries(${PROJECT_NAME}_node -fsanitize=address -fsanitize=leak)
target_link_libraries(${PROJECT_NAME}_node_exe -fsanitize=address -fsanitize=leak)
endif()

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()
Expand Down
35 changes: 34 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,17 @@ Possible options for this driver today are:

More formats and conversions can be added, contributions welcome!

### Supported IO methods

This driver supports three different IO methods as of today:

1. `read`: copies the video frame between user and kernal space
1. `mmap`: memory mapped buffers allocated in kernel space
1. `userptr`: memory buffers allocated in the user space

To read more on the different methods, check out [this article that provides a good overview
of each](https://lwn.net/Articles/240667/)

## Compression

Big thanks to [the `ros2_v4l2_camera` package](https://gitlab.com/boldhearts/ros2_v4l2_camera#usage-1) and their documentation on this topic.
Expand All @@ -147,7 +158,29 @@ Unfortunately `rviz2` and `show_image.py` do not support visualizing the compres
ros2 run image_transport republish compressed raw --ros-args --remap in/compressed:=image_raw/compressed --remap out:=image_raw/uncompressed
```

#### Documentation
## Address and leak sanitizing

Incorporated into the `CMakelists.txt` file to assist with memory leak and address sanitizing
is a flag to add these compile commands to the targets.

To enable them, pass in the `SANITIZE=1` flag:

```
colcon build --packages-select usb_cam --cmake-args -DSANITIZE=1
```

Once built, run the nodes executable directly and pass any `ASAN_OPTIONS` that are needed:

```
ASAN_OPTIONS=new_delete_type_mismatch=0 ./install/usb_cam/lib/usb_cam/usb_cam_node_exe
```

After shutting down the executable with `Ctrl+C`, the sanitizer will report any memory leaks.

By default this is turned off since compiling with the sanatizer turned on causes bloat and slows
down performance.

## Documentation

[Doxygen](http://docs.ros.org/indigo/api/usb_cam/html/) files can be found on the ROS wiki.

Expand Down
4 changes: 4 additions & 0 deletions include/usb_cam/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,14 @@ namespace utils
using usb_cam::formats::pixel_format_base;


/// @brief Read more on IO methods here: https://lwn.net/Articles/240667/
typedef enum
{
/// @brief read method copies the video frame between user and kernal space
IO_METHOD_READ,
/// @brief memory mapped buffers allocated in kernel space
IO_METHOD_MMAP,
/// @brief memory buffers allocated in the user space
IO_METHOD_USERPTR,
IO_METHOD_UNKNOWN,
} io_method_t;
Expand Down

0 comments on commit b221d7f

Please sign in to comment.