-
Notifications
You must be signed in to change notification settings - Fork 189
Feature/latency benchmarking #2461
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
yuvrajdhadwal
wants to merge
22
commits into
ros2
Choose a base branch
from
feature/latency_benchmarking
base: ros2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
a1a33c2
started work
yuvrajdhadwal e04d73e
theoretically finished benchmarking
yuvrajdhadwal 163a7df
i'm confused
yuvrajdhadwal 0367db8
created a new node for rj_benchmarking
yuvrajdhadwal f4ea17a
started working on registry within the node, there is an issue with m…
yuvrajdhadwal 1a61c6a
aaaaaaalind
yuvrajdhadwal 4988c4b
end of day work
yuvrajdhadwal b799876
starting work to transform to pub/sub model
yuvrajdhadwal 2e3cb17
its working! we are now measuring latency for pivots!
yuvrajdhadwal e7ab876
added benchmarking as a library import to all packages
yuvrajdhadwal 5d38c15
linting
yuvrajdhadwal 94d8918
added new flush mechanism so that latency files are created and easy …
yuvrajdhadwal c0e1303
removed timer calls in other code
yuvrajdhadwal d4c5292
Fix Code Style On feature/latency_benchmarking (#2462)
github-actions[bot] f4bc21f
fixed pr comments
yuvrajdhadwal 787ea2c
Fix missing newline at end of rotate_path_planner.hpp
yuvrajdhadwal c4cfa5e
whoops missed some
yuvrajdhadwal 2636e1c
Merge branch 'feature/latency_benchmarking' of https://github.com/Rob…
yuvrajdhadwal 0f76cf1
more cleanup
yuvrajdhadwal 652e3db
Fix Code Style On feature/latency_benchmarking (#2464)
github-actions[bot] f85c032
added package dependencies
yuvrajdhadwal c045a29
switched to ros2 timer so that it matches sim time rather than real time
yuvrajdhadwal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,4 +55,5 @@ compile_commands.json | |
| # Colcon Build Things | ||
| build/ | ||
| install/ | ||
| log/ | ||
| log/ | ||
| latency/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| cmake_minimum_required(VERSION 3.8) | ||
| project(rj_benchmarking) | ||
|
|
||
| if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") | ||
| add_compile_options(-Wall -Wextra -Wpedantic) | ||
| endif() | ||
|
|
||
| list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") | ||
|
|
||
| # Find dependencies | ||
| find_package(ament_cmake REQUIRED) | ||
| find_package(rclcpp REQUIRED) | ||
| find_package(rclcpp_components REQUIRED) | ||
| find_package(spdlog REQUIRED) | ||
| find_package(fmt REQUIRED) | ||
| find_package(rosidl_default_generators REQUIRED) | ||
| find_package(std_msgs REQUIRED) | ||
| find_package(rj_msgs REQUIRED) | ||
| find_package(rj_constants REQUIRED) | ||
|
|
||
| set(BENCHMARKING_DEPS | ||
| fmt | ||
| rclcpp | ||
| spdlog | ||
| rj_msgs | ||
| rj_constants | ||
| ) | ||
|
|
||
| set(BENCHMARKING_LIBS | ||
| fmt | ||
| spdlog | ||
| ) | ||
|
|
||
| set(BENCHMARKING_SRC | ||
| src/registry.cpp | ||
| src/timer.cpp | ||
| src/registry_publisher.cpp | ||
| ) | ||
|
|
||
| # RJ Benchmarking Library | ||
| add_library(${PROJECT_NAME} SHARED | ||
| ${BENCHMARKING_SRC} | ||
| ) | ||
|
|
||
| target_include_directories(${PROJECT_NAME} | ||
| PUBLIC | ||
| $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> | ||
| $<INSTALL_INTERFACE:include> | ||
| ) | ||
|
|
||
| target_link_libraries(${PROJECT_NAME} | ||
| PUBLIC | ||
| ${BENCHMARKING_LIBS} | ||
| ) | ||
|
|
||
| ament_target_dependencies(${PROJECT_NAME} | ||
| PUBLIC | ||
| ${BENCHMARKING_DEPS} | ||
| ) | ||
|
|
||
| # Benchmarking Node | ||
| add_executable(${PROJECT_NAME}_node | ||
| ${BENCHMARKING_SRC} | ||
| src/main.cpp | ||
| ) | ||
|
|
||
| target_include_directories(${PROJECT_NAME}_node | ||
| PUBLIC | ||
| $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> | ||
| $<INSTALL_INTERFACE:include> | ||
| ) | ||
|
|
||
| target_link_libraries(${PROJECT_NAME}_node | ||
| PUBLIC | ||
| ${BENCHMARKING_LIBS} | ||
| ) | ||
|
|
||
| ament_target_dependencies(${PROJECT_NAME}_node | ||
| PUBLIC | ||
| ${BENCHMARKING_DEPS} | ||
| ) | ||
|
|
||
| install( | ||
| DIRECTORY include/ | ||
| DESTINATION include | ||
| ) | ||
|
|
||
| install( | ||
| TARGETS ${PROJECT_NAME} | ||
| EXPORT ${PROJECT_NAME} | ||
| LIBRARY DESTINATION lib | ||
| ARCHIVE DESTINATION lib | ||
| RUNTIME DESTINATION bin | ||
| INCLUDES DESTINATION include | ||
| ) | ||
|
|
||
| install( | ||
| TARGETS ${PROJECT_NAME}_node | ||
| DESTINATION lib/${PROJECT_NAME} | ||
| ) | ||
|
|
||
| ament_export_dependencies( | ||
| ${BENCHMARKING_DEPS} | ||
| ) | ||
|
|
||
| ament_export_include_directories(include) | ||
|
|
||
| ament_export_targets(${PROJECT_NAME}) | ||
| ament_package() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| #pragma once | ||
|
|
||
| #include <array> | ||
| #include <chrono> | ||
| #include <cstdint> | ||
| #include <ctime> | ||
| #include <filesystem> | ||
| #include <fstream> | ||
| #include <iomanip> | ||
| #include <iterator> | ||
| #include <numeric> | ||
| #include <string> | ||
| #include <unordered_map> | ||
| #include <vector> | ||
|
|
||
| #include <rclcpp/rclcpp.hpp> | ||
| #include <spdlog/spdlog.h> | ||
|
|
||
| #include <rj_constants/constants.hpp> | ||
| #include <rj_msgs/msg/latency.hpp> | ||
|
|
||
| class Registry : public rclcpp::Node { | ||
| public: | ||
| Registry(); | ||
| ~Registry(); | ||
|
|
||
| private: | ||
| void topic_callback(const rj_msgs::msg::Latency& msg); | ||
|
|
||
| std::string get_curr_datetime(); | ||
|
|
||
| // registry[robot_id][label] -> latency sampling | ||
| std::array<std::unordered_map<std::string, std::vector<uint64_t>>, kNumShells> registry_{}; | ||
| rclcpp::Subscription<rj_msgs::msg::Latency>::SharedPtr subscription_{}; | ||
| size_t max_rows_{}; | ||
| }; |
31 changes: 31 additions & 0 deletions
31
src/rj_benchmarking/include/rj_benchmarking/registry_publisher.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| #pragma once | ||
|
|
||
| #include <rclcpp/rclcpp.hpp> | ||
|
|
||
| #include <rj_msgs/msg/latency.hpp> | ||
|
|
||
| class RegistryPublisher { | ||
| public: | ||
| // Singleton pattern | ||
| static std::shared_ptr<RegistryPublisher> getInstance() { | ||
| static std::shared_ptr<RegistryPublisher> instance{new RegistryPublisher()}; | ||
| return instance; | ||
| } | ||
|
|
||
| void publish(const std::string& label, uint8_t robot_id, uint64_t time); | ||
|
|
||
| private: | ||
| static RegistryPublisher* instance; | ||
|
|
||
| // Private Constructor | ||
| RegistryPublisher() = default; | ||
|
|
||
| // Delete Copy Constructor and Assignment | ||
| RegistryPublisher(const RegistryPublisher& other) = delete; | ||
| RegistryPublisher& operator=(const RegistryPublisher& other) = delete; | ||
|
|
||
| std::shared_ptr<rclcpp::Node> node_ = | ||
| std::make_shared<rclcpp::Node>("rj_benchmarking_publisher"); | ||
| rclcpp::Publisher<rj_msgs::msg::Latency>::SharedPtr publisher_ = | ||
| node_->create_publisher<rj_msgs::msg::Latency>("/registry", 100); | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| #pragma once | ||
|
|
||
| #include <chrono> | ||
| #include <cstdint> | ||
| #include <string> | ||
|
|
||
| #include <rclcpp/rclcpp.hpp> | ||
| #include <spdlog/spdlog.h> | ||
|
|
||
| #include <rj_msgs/msg/latency.hpp> | ||
|
|
||
| #include "rj_benchmarking/registry_publisher.hpp" | ||
|
|
||
| // Lazy static ros_clock | ||
| static rclcpp::Clock& ros_clock() { | ||
| static rclcpp::Clock clock(RCL_STEADY_TIME); | ||
| return clock; | ||
| } | ||
|
|
||
| class Timer { | ||
| public: | ||
| Timer(const std::string& label, uint8_t robot_id); | ||
| ~Timer(); | ||
|
|
||
| private: | ||
| const std::string label_; | ||
| const std::uint8_t robot_id_; | ||
| const rclcpp::Time start_; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| <?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>rj_benchmarking</name> | ||
| <version>0.0.0</version> | ||
| <description>Node for Benchmarking</description> | ||
| <maintainer email="[email protected]">Yuvraj Dhadwal</maintainer> | ||
| <license>TODO: License declaration</license> | ||
|
|
||
| <depend>rclcpp</depend> | ||
| <depend>rclcpp_components</depend> | ||
| <depend>spdlog</depend> | ||
| <depend>fmt</depend> | ||
| <depend>rosidl_default_generators</depend> | ||
| <depend>std_msgs</depend> | ||
| <depend>rj_msgs</depend> | ||
| <depend>rj_constants</depend> | ||
|
|
||
| <buildtool_depend>ament_cmake</buildtool_depend> | ||
|
|
||
| <export> | ||
| <build_type>ament_cmake</build_type> | ||
| </export> | ||
| </package> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| #include <rclcpp/rclcpp.hpp> | ||
|
|
||
| #include "rj_benchmarking/registry.hpp" | ||
| #include "rj_benchmarking/registry_publisher.hpp" | ||
|
|
||
| int main(int argc, char* argv[]) { | ||
| rclcpp::init(argc, argv); | ||
| rclcpp::spin(std::make_shared<Registry>()); | ||
| rclcpp::shutdown(); | ||
| return 0; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| #include "rj_benchmarking/registry.hpp" | ||
|
|
||
| Registry::Registry() : rclcpp::Node{"rj_benchmarking"} { | ||
| subscription_ = this->create_subscription<rj_msgs::msg::Latency>( | ||
| "/registry", 100, std::bind(&Registry::topic_callback, this, std::placeholders::_1)); | ||
| } | ||
|
|
||
| Registry::~Registry() { | ||
| /* | ||
| 1. Make LatencyLogs Directory if not already there | ||
| 2. Make latency_curr-date_curr-time folder | ||
| 3. Make csv for Robot 1 | ||
| 3a. first row is labels | ||
| 4. Make csvs for all robots | ||
| */ | ||
|
|
||
| if (max_rows_ != 0) { | ||
| std::string base_path{"./latency"}; | ||
| std::filesystem::create_directories(base_path); | ||
| base_path += "/session_"; | ||
| base_path += get_curr_datetime(); | ||
| std::filesystem::create_directories(base_path); | ||
|
|
||
| for (size_t i = 0; i < kNumShells; i++) { | ||
| if (registry_[i].empty()) { | ||
| continue; | ||
| } | ||
|
|
||
| std::string ss{}; | ||
| ss += "/robot_"; | ||
| ss += std::to_string(i); | ||
| ss += ".csv"; | ||
| std::ofstream robot_csv{base_path + ss}; | ||
|
|
||
| // Print out labels | ||
| for (const auto& [label, timestamps] : registry_[i]) { | ||
| robot_csv << label << ','; | ||
| } | ||
| robot_csv << '\n'; | ||
|
|
||
| // Print out data row by row | ||
| for (size_t row = 0; row < max_rows_; ++row) { | ||
| for (const auto& [label, timestamps] : registry_[i]) { | ||
| robot_csv << timestamps[row] << ','; | ||
| } | ||
|
|
||
| robot_csv << '\n'; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void Registry::topic_callback(const rj_msgs::msg::Latency& msg) { | ||
| registry_[msg.robot_id][msg.label].push_back(msg.duration_ns); | ||
| max_rows_ = std::max(max_rows_, static_cast<size_t>(registry_[msg.robot_id][msg.label].size())); | ||
| } | ||
|
|
||
| std::string Registry::get_curr_datetime() { | ||
| auto now = std::chrono::system_clock::now(); | ||
| std::time_t now_time = std::chrono::system_clock::to_time_t(now); | ||
| std::tm tm_buf{}; | ||
|
|
||
| localtime_r(&now_time, &tm_buf); | ||
|
|
||
| std::ostringstream ss; | ||
| ss << std::put_time(&tm_buf, "%Y-%m-%d_%H:%M:%S"); | ||
| return ss.str(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| #include "rj_benchmarking/registry_publisher.hpp" | ||
|
|
||
| RegistryPublisher* RegistryPublisher::instance = nullptr; | ||
|
|
||
| void RegistryPublisher::publish(const std::string& label, u_int8_t robot_id, uint64_t time) { | ||
| rj_msgs::msg::Latency message = rj_msgs::msg::Latency(); | ||
|
|
||
| message.label = label; | ||
| message.robot_id = robot_id; | ||
| message.duration_ns = time; | ||
|
|
||
| publisher_->publish(message); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| #include "rj_benchmarking/timer.hpp" | ||
|
|
||
| Timer::Timer(const std::string& label, uint8_t robot_id) | ||
| : label_(label), robot_id_(robot_id), start_(ros_clock().now()) {} | ||
|
|
||
| Timer::~Timer() { | ||
| rclcpp::Duration duration = ros_clock().now() - start_; | ||
| uint64_t time_ns = static_cast<uint64_t>(duration.nanoseconds()); | ||
| RegistryPublisher::getInstance()->publish(label_, robot_id_, time_ns); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| string label | ||
| uint64 duration_ns | ||
| int8 robot_id |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.