Skip to content
Open
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: 21 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,35 @@ name: CI
on: [push, pull_request, workflow_dispatch]

jobs:
matrix:
name: Determine modified packages
runs-on: ubuntu-latest
outputs:
packages: ${{ steps.modified-packages.outputs.packages }}
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 300
- name: Commit Range
id: commit-range
uses: tue-robotics/tue-env/ci/commit-range@master
- name: Modified packages
id: modified-packages
uses: tue-robotics/tue-env/ci/modified-packages@master
with:
commit-range: ${{ steps.commit-range.outputs.commit-range }}
tue-ci:
name: TUe CI - ${{ github.event_name }} (${{ matrix.ros_distro }})
name: TUe CI - ${{ matrix.package }} (${{ matrix.ros_distro }})
runs-on: ubuntu-latest
needs: matrix
strategy:
fail-fast: false
matrix:
ros_distro: [humble, jazzy, rolling-u24]
package: ${{ fromJson(needs.matrix.outputs.packages) }}
steps:
- name: TUe CI
uses: tue-robotics/tue-env/ci/main@master
with:
image: ghcr.io/tue-robotics/tue-env-ros-${{ matrix.ros_distro }}
package: ${{ github.event.repository.name }}
package: ${{ matrix.package }}
File renamed without changes.
29 changes: 11 additions & 18 deletions CMakeLists.txt → code_profiler/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,12 @@ endif()
find_package(Threads REQUIRED)

find_package(ament_cmake REQUIRED)
find_package(code_profiler_interfaces REQUIRED)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)
find_package(rosidl_default_generators REQUIRED)

# 1. This internally creates a target "code_profiler"
rosidl_generate_interfaces(${PROJECT_NAME}
"msg/Statistics.msg"
DEPENDENCIES std_msgs
)

# 2. Give the library a unique name (Project name + _lib)
add_library(${PROJECT_NAME}_lib SHARED
add_library(${PROJECT_NAME} SHARED
src/loop_timer.cpp
src/profiler.cpp
src/profiling/ProfileLog.cpp
Expand All @@ -37,31 +31,30 @@ add_library(${PROJECT_NAME}_lib SHARED
)

# Link the typesupport of custom messages
rosidl_get_typesupport_target(cpp_typesupport_target ${PROJECT_NAME} "rosidl_typesupport_cpp")
target_link_libraries(${PROJECT_NAME}_lib
target_link_libraries(${PROJECT_NAME}
PRIVATE
${cpp_typesupport_target}
code_profiler_interfaces::code_profiler_interfaces__rosidl_typesupport_cpp
rclcpp::rclcpp
std_msgs::std_msgs__rosidl_typesupport_cpp
)
target_include_directories(${PROJECT_NAME}_lib PUBLIC
target_include_directories(${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)

# 3. Executables (Make sure they are all defined before the install step)
add_executable(profiler_test src/main.cpp)
target_link_libraries(profiler_test ${PROJECT_NAME}_lib Threads::Threads)
target_link_libraries(profiler_test ${PROJECT_NAME} Threads::Threads)

add_executable(test_loop_timer test/test_loop_timer.cpp)
target_link_libraries(test_loop_timer ${PROJECT_NAME}_lib)
target_link_libraries(test_loop_timer ${PROJECT_NAME})

add_executable(test_profiler test/test_profiler.cpp)
target_link_libraries(test_profiler ${PROJECT_NAME}_lib)
target_link_libraries(test_profiler ${PROJECT_NAME})

# 4. Installation
install(
TARGETS ${PROJECT_NAME}_lib
TARGETS ${PROJECT_NAME}
EXPORT export_${PROJECT_NAME}
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
Expand All @@ -88,7 +81,7 @@ install(

# 5. Export
ament_export_targets(export_${PROJECT_NAME} HAS_LIBRARY_TARGET)
ament_export_dependencies(rclcpp std_msgs rosidl_default_runtime)
ament_export_dependencies(code_profiler_interfaces rclcpp std_msgs)

# 6. Testing and Linting
if(BUILD_TESTING)
Expand All @@ -103,7 +96,7 @@ if(BUILD_TESTING)
)
ament_clang_tidy(
CONFIG_FILE ${tue_lint_config_DIR}/../config/.clang-tidy
# --fix-errors
--clang-tidy-version=21
${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_BINARY_DIR}/compile_commands.json)
ament_lint_cmake(MAX_LINE_LENGTH 120 "--filter=
+convention/filename,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef CODE_PROFILER_STATS_PUBLISHER_H_
#define CODE_PROFILER_STATS_PUBLISHER_H_
#ifndef code_profiler_STATS_PUBLISHER_H_
#define code_profiler_STATS_PUBLISHER_H_

#include <code_profiler/msg/statistics.hpp>
#include <code_profiler_interfaces/msg/statistics.hpp>
#include <map>
#include <rclcpp/rclcpp.hpp>
#include <stack>
Expand All @@ -26,7 +26,7 @@ class StatsPublisher
public:
StatsPublisher();

virtual ~StatsPublisher();
virtual ~StatsPublisher() = default;

void initialize(rclcpp::Node* node);

Expand All @@ -37,7 +37,7 @@ class StatsPublisher
void publish() const;

protected:
rclcpp::Publisher<code_profiler::msg::Statistics>::SharedPtr pub_stats_;
rclcpp::Publisher<code_profiler_interfaces::msg::Statistics>::SharedPtr pub_stats_;

std::map<std::string, Timer> timers_;

Expand Down
File renamed without changes.
7 changes: 3 additions & 4 deletions package.xml → code_profiler/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,24 @@
<author>Tim de Jager</author>

<buildtool_depend>ament_cmake</buildtool_depend>
<buildtool_depend>rosidl_default_generators</buildtool_depend>

<depend>rclcpp</depend>
<depend>std_msgs</depend>
<depend>code_profiler_interfaces</depend>

<exec_depend>rosidl_default_runtime</exec_depend>
<exec_depend>python3-numpy</exec_depend>
<exec_depend>rclpy</exec_depend>

<test_depend>ament_cmake_clang_format</test_depend>
<test_depend>ament_cmake_clang_tidy</test_depend>
<test_depend>ament_cmake_lint_cmake</test_depend>
<test_depend>ament_cmake_xmllint</test_depend>
<test_depend>clang-format-21</test_depend>
<test_depend>clang-tidy-21</test_depend>
<test_depend>tue_lint_config</test_depend>

<doc_depend>doxygen</doc_depend>

<member_of_group>rosidl_interface_packages</member_of_group>

<export>
<build_type>ament_cmake</build_type>
<rosdoc config="rosdoc.yaml" />
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "profiling/StatsPublisher.h"

#include <code_profiler/msg/statistics.hpp>
#include <code_profiler_interfaces/msg/statistics.hpp>
#include <iostream>
#include <rclcpp/rclcpp.hpp>

Expand All @@ -10,10 +10,6 @@ StatsPublisher::StatsPublisher() : node_(nullptr) {}

// ----------------------------------------------------------------------------------------------------

StatsPublisher::~StatsPublisher() = default;

// ----------------------------------------------------------------------------------------------------

void StatsPublisher::initialize(rclcpp::Node* node)
{
if (!node)
Expand All @@ -23,7 +19,7 @@ void StatsPublisher::initialize(rclcpp::Node* node)
}

node_ = node;
pub_stats_ = node_->create_publisher<code_profiler::msg::Statistics>("profiler_stats", 1);
pub_stats_ = node_->create_publisher<code_profiler_interfaces::msg::Statistics>("profiler_stats", 1);
}

// ----------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -69,7 +65,7 @@ void StatsPublisher::publish() const
return;
}

code_profiler::msg::Statistics msg;
code_profiler_interfaces::msg::Statistics msg;
for (const auto& timer : timers_)
{
msg.labels.push_back(timer.first);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
24 changes: 24 additions & 0 deletions code_profiler_interfaces/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
cmake_minimum_required(VERSION 3.5)
project(code_profiler_interfaces)

if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
endif()
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Werror=all)
add_compile_options(-Wextra -Werror=extra)
endif()

find_package(ament_cmake REQUIRED)
find_package(builtin_interfaces REQUIRED)
find_package(rosidl_default_generators REQUIRED)

rosidl_generate_interfaces(${PROJECT_NAME}
"msg/Statistics.msg"
DEPENDENCIES builtin_interfaces
ADD_LINTER_TESTS
)

ament_export_dependencies(rosidl_default_runtime)

ament_package()
33 changes: 33 additions & 0 deletions code_profiler_interfaces/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# code_profiler

[![CI](https://github.com/tue-robotics/code_profiler/actions/workflows/main.yml/badge.svg)](https://github.com/tue-robotics/code_profiler/actions/workflows/main.yml)

Various classes to profile code in different ways, including some additional loop statistics.

## ROS2 Compatibility

This package has been fully migrated to ROS2. It provides profiling utilities that can be used standalone or integrated with ROS2 nodes.

## Key Components

- **Profiler**: Core profiling class for timing code sections
- **LoopTimer**: Timer with Kahan summation for accurate loop timing
- **ProfilePublisher**: ROS2 publisher for profiling data (requires `rclcpp::Node*`)
- **StatsPublisher**: ROS2 publisher for statistics messages (requires `rclcpp::Node*`)
- **liveprofile**: Python script for live visualization of profiling data

## Usage with ROS2

The `ProfilePublisher` and `StatsPublisher` classes are designed to be usable by other libraries. They accept an `rclcpp::Node*` pointer during initialization:

```cpp
#include <tue/profiling/profiler.h>
#include <tue/profiling/ros/profile_publisher.h>

// In your node class
tue::Profiler profiler("my_profiler");
tue::ProfilePublisher publisher(profiler, this); // 'this' is your rclcpp::Node*

// Later, publish profiling data
publisher.publish();
```
File renamed without changes.
30 changes: 30 additions & 0 deletions code_profiler_interfaces/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0"?>
<?xml-model
href="http://download.ros.org/schema/package_format3.xsd"
schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>code_profiler_interfaces</name>
<version>0.1.0</version>
<description>Various classes to profile code in different ways. Including some additonal loop statistics.</description>

<maintainer email="MatthijsBurgh@outlook.com">Matthijs van der Burgh</maintainer>

<license>BSD</license>

<author email="MatthijsBurgh@outlook.com">Matthijs van der Burgh</author>

<buildtool_depend>ament_cmake</buildtool_depend>
<buildtool_depend>rosidl_default_generators</buildtool_depend>

<exec_depend>rosidl_default_runtime</exec_depend>

<test_depend>ament_lint_common</test_depend>

<member_of_group>rosidl_interface_packages</member_of_group>

<export>
<build_type>ament_cmake</build_type>
<rosdoc config="rosdoc.yaml" />
</export>

</package>
7 changes: 7 additions & 0 deletions code_profiler_interfaces/rosdoc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- builder: doxygen
name: C++ API
output_dir: cpp
file_patterns: '*.c *.cpp *.h *.hpp'
tab_size: 4
use_mdfile_as_mainpage: README.md
exclude_patterns: 'msg/* scripts/* test/*'
Loading