-
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
25
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 13 commits
Commits
Show all changes
25 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 8c80fa7
added sentinel value for timer rows smaller than max_rows
yuvrajdhadwal d605a7e
fixed comment
yuvrajdhadwal 113483e
Fix Code Style On feature/latency_benchmarking (#2476)
github-actions[bot] 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
Some comments aren't visible on the classic Files Changed page.
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,107 @@ | ||
| 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) | ||
|
|
||
| set(BENCHMARKING_DEPS | ||
| fmt | ||
| rclcpp | ||
| spdlog | ||
| rj_msgs | ||
| ) | ||
|
|
||
| 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,35 @@ | ||
| #pragma once | ||
|
|
||
| #include <rj_msgs/msg/latency.hpp> | ||
|
|
||
| #include <spdlog/spdlog.h> | ||
| #include <rclcpp/rclcpp.hpp> | ||
|
|
||
| #include <string> | ||
| #include <unordered_map> | ||
| #include <array> | ||
| #include <vector> | ||
| #include <numeric> | ||
| #include <fstream> | ||
| #include <cstdint> | ||
| #include <filesystem> | ||
| #include <ctime> | ||
| #include <iterator> | ||
|
|
||
| class Registry : public rclcpp::Node | ||
| { | ||
| public: | ||
| Registry(); | ||
| ~Registry(); | ||
|
|
||
| private: | ||
| void topic_callback(const rj_msgs::msg::Latency &msg); | ||
| void dump(); | ||
|
|
||
| std::string get_curr_datetime(); | ||
|
|
||
| // registry[robot_id][label] -> latency sampling | ||
| std::array<std::unordered_map<std::string, std::vector<uint64_t>>, 6> registry_{}; | ||
yuvrajdhadwal marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| rclcpp::Subscription<rj_msgs::msg::Latency>::SharedPtr subscription_{}; | ||
| int max_rows_{}; | ||
yuvrajdhadwal marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }; | ||
38 changes: 38 additions & 0 deletions
38
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,38 @@ | ||
| #pragma once | ||
|
|
||
| #include <rj_msgs/msg/latency.hpp> | ||
|
|
||
| #include <rclcpp/rclcpp.hpp> | ||
|
|
||
| class RegistryPublisher | ||
| { | ||
| public: | ||
| // Singleton pattern | ||
yuvrajdhadwal marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| static RegistryPublisher* getInstance() | ||
yuvrajdhadwal marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
yuvrajdhadwal marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| if (instance == nullptr) | ||
| { | ||
| instance = new RegistryPublisher(); | ||
| } | ||
|
|
||
| return instance; | ||
| } | ||
|
|
||
| void publish(std::string label, std::int8_t robot_id, uint64_t time); | ||
yuvrajdhadwal marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
yuvrajdhadwal marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| private: | ||
| static RegistryPublisher* instance; | ||
|
|
||
| // Private Constructor | ||
| RegistryPublisher(); | ||
|
|
||
| // 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,24 @@ | ||
| #pragma once | ||
|
|
||
| #include "rj_benchmarking/registry_publisher.hpp" | ||
| #include <rj_msgs/msg/latency.hpp> | ||
|
|
||
| #include <rclcpp/rclcpp.hpp> | ||
| #include <spdlog/spdlog.h> | ||
|
|
||
| #include <string> | ||
| #include <chrono> | ||
| #include <cstdint> | ||
|
|
||
| class Timer | ||
| { | ||
|
|
||
| public: | ||
| Timer(std::string label, std::int8_t robot_id); | ||
| ~Timer(); | ||
|
|
||
| private: | ||
| const std::chrono::steady_clock::time_point start_{}; | ||
| std::string label_{}; | ||
| std::int8_t robot_id_{}; | ||
| }; |
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,20 @@ | ||
| <?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> | ||
|
|
||
| <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,12 @@ | ||
| #include "rj_benchmarking/registry.hpp" | ||
| #include "rj_benchmarking/registry_publisher.hpp" | ||
|
|
||
| #include <rclcpp/rclcpp.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,94 @@ | ||
| #include "rj_benchmarking/registry.hpp" | ||
|
|
||
| Registry::Registry() : rclcpp::Node{"rj_benchmarking"} | ||
| { | ||
| // SPDLOG_INFO("TESTING: Registry Built"); | ||
yuvrajdhadwal marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| subscription_ = this->create_subscription<rj_msgs::msg::Latency>( | ||
| "/registry", 100, std::bind(&Registry::topic_callback, this, | ||
| std::placeholders::_1)); | ||
| } | ||
|
|
||
| Registry::~Registry() | ||
| { | ||
| dump(); | ||
| // SPDLOG_INFO("TESTING: Registry Destroyed"); | ||
yuvrajdhadwal marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
yuvrajdhadwal marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| void Registry::topic_callback(const rj_msgs::msg::Latency &msg) | ||
| { | ||
| registry_.at(msg.robot_id)[msg.label].push_back(msg.duration_ns); | ||
yuvrajdhadwal marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| max_rows_ = std::max(max_rows_, static_cast<int>(registry_.at(msg.robot_id)[msg.label].size())); | ||
| } | ||
|
|
||
|
|
||
| void Registry::dump() | ||
yuvrajdhadwal marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| // SPDLOG_INFO("TESTING: Dump Called"); | ||
yuvrajdhadwal marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /* | ||
| 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 | ||
yuvrajdhadwal marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 4. Make csvs for all robots | ||
| */ | ||
| 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); | ||
|
|
||
| // std::ofstream output_file; | ||
| // output_file.open(path_); | ||
| for (int i = 0; i < 6; i++) | ||
| { | ||
| std::stringstream ss; | ||
| ss << "/robot_" << i << ".csv"; | ||
yuvrajdhadwal marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| std::ofstream robot_csv{ base_path + ss.str() }; | ||
|
|
||
| for (int row = -1; row < max_rows_; row++) | ||
yuvrajdhadwal marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
yuvrajdhadwal marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
yuvrajdhadwal marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (row == -1) | ||
| { | ||
| for (std::pair<std::string, std::vector<uint64_t>> labels : registry_.at(i)) | ||
| { | ||
| robot_csv << labels.first << ','; | ||
yuvrajdhadwal marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| robot_csv << '\n'; | ||
| } | ||
|
|
||
| for (std::pair<std::string, std::vector<uint64_t>> labels : registry_.at(i)) | ||
| { | ||
| robot_csv << labels.second[row] << ','; | ||
| } | ||
|
|
||
| robot_csv << '\n'; | ||
| } | ||
|
|
||
|
|
||
| // output_file << "Robot " << i << '\n'; | ||
| // for (auto& p : registry_[i]) | ||
| // { | ||
| // output_file << p.first << " "; | ||
| // for (uint64_t e : p.second) | ||
| // { | ||
yuvrajdhadwal marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // output_file << e << ", "; | ||
| // } | ||
| // output_file << "AVG: " << std::accumulate(p.second.begin(), p.second.end(), 0) | ||
| // / p.second.size(); | ||
| // output_file << '\n'; | ||
| // } | ||
| } | ||
| // output_file.close(); | ||
yuvrajdhadwal marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| std::string Registry::get_curr_datetime() | ||
| { | ||
| std::time_t time = std::time({}); | ||
yuvrajdhadwal marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| char timeString[std::size("yyyy-mm-ddThh:mm:ssZ")]; | ||
| std::strftime(std::data(timeString), std::size(timeString), | ||
| "%FT%TZ", std::localtime(&time)); | ||
| std::string out{ timeString }; | ||
| return out; | ||
| } | ||
Oops, something went wrong.
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.