Skip to content

Commit

Permalink
Added perftool for performance-testing different sender / reiver impl…
Browse files Browse the repository at this point in the history
…ementations (#11)
  • Loading branch information
FlorianReimold authored Apr 22, 2024
1 parent 243474e commit c3cfc50
Show file tree
Hide file tree
Showing 35 changed files with 2,058 additions and 20 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/ecaludp-module)
# Add samples, if enabled
if (ECALUDP_BUILD_SAMPLES)
add_subdirectory(samples/ecaludp_sample)
add_subdirectory(samples/ecaludp_perftool)
if (ECALUDP_ENABLE_NPCAP)
add_subdirectory(samples/ecaludp_sample_npcap)
endif()
Expand Down
5 changes: 2 additions & 3 deletions ecaludp/include_with_udpcap/ecaludp/socket_npcap.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,11 @@ namespace ecaludp
ECALUDP_EXPORT std::shared_ptr<ecaludp::OwningBuffer> receive_from(asio::ip::udp::endpoint& sender_endpoint, ecaludp::Error& error);

ECALUDP_EXPORT void async_receive_from(asio::ip::udp::endpoint& sender_endpoint
, const std::function<void(const std::shared_ptr<ecaludp::OwningBuffer>&, ecaludp::Error)>& completion_handler);

, const std::function<void(const std::shared_ptr<ecaludp::OwningBuffer>&, const ecaludp::Error&)>& completion_handler);

private:
void receive_next_datagram_from(asio::ip::udp::endpoint& sender_endpoint
, const std::function<void(const std::shared_ptr<ecaludp::OwningBuffer>&, ecaludp::Error)>& completion_handler);
, const std::function<void(const std::shared_ptr<ecaludp::OwningBuffer>&, const ecaludp::Error&)>& completion_handler);

std::shared_ptr<ecaludp::OwningBuffer> handle_datagram(const std::shared_ptr<ecaludp::RawMemory>& buffer
, const std::shared_ptr<asio::ip::udp::endpoint>& sender_endpoint
Expand Down
2 changes: 1 addition & 1 deletion ecaludp/src/async_udpcap_socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ namespace ecaludp
, size_t max_buffer_size
, Udpcap::HostAddress& sender_address
, uint16_t& sender_port
, const std::function<void(ecaludp::Error&, size_t)>& read_handler)
, const std::function<void(const ecaludp::Error&, size_t)>& read_handler)
{
const std::unique_lock<std::mutex> lock(wait_thread_trigger_mutex_);
async_receive_from_parameters_queue_.push_back({ buffer, max_buffer_size, &sender_address, &sender_port, read_handler });
Expand Down
6 changes: 3 additions & 3 deletions ecaludp/src/async_udpcap_socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ namespace ecaludp
, size_t max_buffer_size
, Udpcap::HostAddress& sender_address
, uint16_t& sender_port
, ecaludp::Error& error);
, ecaludp::Error& error);

void asyncReceiveFrom( char* buffer
, size_t max_buffer_size
, Udpcap::HostAddress& sender_address
, uint16_t& sender_port
, const std::function<void(ecaludp::Error&, size_t)>& read_handler);
, const std::function<void(const ecaludp::Error&, size_t)>& read_handler);

private:
static void toEcaludpError(const Udpcap::Error& udpcap_error, ecaludp::Error& ecaludp_error);
Expand All @@ -95,7 +95,7 @@ namespace ecaludp
size_t max_buffer_size_;
Udpcap::HostAddress* sender_address_;
uint16_t* sender_port_;
std::function<void(ecaludp::Error&, size_t)> read_handler_;
std::function<void(const ecaludp::Error&, size_t)> read_handler_;
};

Udpcap::UdpcapSocket udpcap_socket_;
Expand Down
6 changes: 3 additions & 3 deletions ecaludp/src/socket_npcap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,13 @@ namespace ecaludp


void SocketNpcap::async_receive_from(asio::ip::udp::endpoint& sender_endpoint
, const std::function<void(const std::shared_ptr<ecaludp::OwningBuffer>&, ecaludp::Error)>& completion_handler)
, const std::function<void(const std::shared_ptr<ecaludp::OwningBuffer>&, const ecaludp::Error&)>& completion_handler)
{
receive_next_datagram_from(sender_endpoint, completion_handler);
}

void SocketNpcap::receive_next_datagram_from(asio::ip::udp::endpoint& sender_endpoint
, const std::function<void(const std::shared_ptr<ecaludp::OwningBuffer>&, ecaludp::Error)>& completion_handler)
, const std::function<void(const std::shared_ptr<ecaludp::OwningBuffer>&, const ecaludp::Error&)>& completion_handler)

{
auto datagram_buffer = datagram_buffer_pool_->allocate();
Expand All @@ -164,7 +164,7 @@ namespace ecaludp
, buffer->size()
, *sender_address
, *sender_port
, [this, buffer, completion_handler, sender_address, sender_port, &sender_endpoint](ecaludp::Error& error, size_t bytes_received)
, [this, buffer, completion_handler, sender_address, sender_port, &sender_endpoint](const ecaludp::Error& error, size_t bytes_received)
{
if (error)
{
Expand Down
7 changes: 7 additions & 0 deletions samples/ecaludp_perftool/.clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
# This disables the warning of non-private members. We use those for inheritance here (with protected visibility).

Checks: "-cppcoreguidelines-non-private-member-variables-in-classes,
"

InheritParentConfig: true
65 changes: 65 additions & 0 deletions samples/ecaludp_perftool/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
################################################################################
# Copyright (c) 2024 Continental Corporation
#
# This program and the accompanying materials are made available under the
# terms of the Apache License, Version 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0.
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
# SPDX-License-Identifier: Apache-2.0
################################################################################

cmake_minimum_required(VERSION 3.13)

project(ecaludp_perftool)

find_package(Threads REQUIRED)
find_package(ecaludp REQUIRED)

set(sources
src/main.cpp
src/receiver.cpp
src/receiver.h
src/receiver_async.cpp
src/receiver_async.h
src/receiver_parameters.h
src/receiver_sync.cpp
src/receiver_sync.h
src/sender.cpp
src/sender.h
src/sender_async.cpp
src/sender_async.h
src/sender_parameters.h
src/sender_sync.cpp
src/sender_sync.h
src/socket_builder_asio.cpp
src/socket_builder_asio.h
)
if (${ECALUDP_ENABLE_NPCAP})
list (APPEND sources
src/receiver_npcap_async.cpp
src/receiver_npcap_async.h
src/receiver_npcap_sync.cpp
src/receiver_npcap_sync.h
src/socket_builder_npcap.cpp
src/socket_builder_npcap.h
)
endif()

add_executable(${PROJECT_NAME} ${sources})

target_link_libraries(${PROJECT_NAME}
PRIVATE
ecaludp::ecaludp
Threads::Threads)

target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14)

source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" FILES
${sources}
)
25 changes: 25 additions & 0 deletions samples/ecaludp_perftool/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# ecaludp-perftool

ecaludp_perftool is a simple tool for sending and receiving data using the eCAL protocol.

```
Usage:
ecaludp_perftool <IMPLEMENTATION> [PARAMETERS]
With IMPLEMENTATION one of:
send Asio-based sender using send_to in a while-loop
sendasync Asio-based sender using async_send_to
receive Asio-based receiver using receive_from in a while-loop
receiveasync Asio-based receiver using async_receive_from
receivenpcap Npcap-based receiver using receive_from in a while-loop
receivenpcapasync Npcap-based receiver using async_receive_from
Options:
-h, --help Show this help message and exit
-i, --ip <IP> IP address to send to / receive from. Default to 127.0.0.1
-p, --port <PORT> Port to send to / receive from. Default to 14000
-s, --size <SIZE> Message size to send. Default to 0 (-> empty messages)
-m, --max-udp-datagram-size <SIZE> Maximum UDP datagram size
-b, --buffer-size <SIZE> Buffer size for sending & receiving messages
```
Loading

0 comments on commit c3cfc50

Please sign in to comment.