Skip to content
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

Iceperf example updated - ein bisschen less advertisement #1860

Merged
merged 7 commits into from
Aug 3, 2023
Merged
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
1 change: 1 addition & 0 deletions doc/website/release-notes/iceoryx-unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
- Add `iox::span` [\#180](https://github.com/eclipse-iceoryx/iceoryx/issues/180)
- Implement custom error reporting API [\#1032](https://github.com/eclipse-iceoryx/iceoryx/issues/1032)
- Implement iceoryx platform for FreeRTOS [#1982](https://github.com/eclipse-iceoryx/iceoryx/issues/1982)
- Extend 'iceperf' with 'WaitSet' [#2003](https://github.com/eclipse-iceoryx/iceoryx/issues/2003)

**Bugfixes:**

Expand Down
2 changes: 2 additions & 0 deletions iceoryx_examples/iceperf/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ cc_library(
"base.cpp",
"iceoryx.cpp",
"iceoryx_c.cpp",
"iceoryx_wait.cpp",
"mq.cpp",
"uds.cpp",
],
Expand All @@ -30,6 +31,7 @@ cc_library(
"example_common.hpp",
"iceoryx.hpp",
"iceoryx_c.hpp",
"iceoryx_wait.hpp",
"mq.hpp",
"topic_data.hpp",
"uds.hpp",
Expand Down
4 changes: 2 additions & 2 deletions iceoryx_examples/iceperf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ include(IceoryxPlatformSettings)

iox_add_executable(
TARGET iceperf-bench-leader
FILES main_leader.cpp iceperf_leader.cpp base.cpp iceoryx.cpp iceoryx_c.cpp uds.cpp mq.cpp
FILES main_leader.cpp iceperf_leader.cpp base.cpp iceoryx.cpp iceoryx_c.cpp iceoryx_wait.cpp uds.cpp mq.cpp
LIBS iceoryx_posh::iceoryx_posh iceoryx_binding_c::iceoryx_binding_c
LIBS_QNX socket
)

iox_add_executable(
TARGET iceperf-bench-follower
FILES main_follower.cpp iceperf_follower.cpp base.cpp iceoryx.cpp iceoryx_c.cpp uds.cpp mq.cpp
FILES main_follower.cpp iceperf_follower.cpp base.cpp iceoryx.cpp iceoryx_c.cpp iceoryx_wait.cpp uds.cpp mq.cpp
LIBS iceoryx_posh::iceoryx_posh iceoryx_binding_c::iceoryx_binding_c
LIBS_QNX socket
)
Expand Down
1 change: 1 addition & 0 deletions iceoryx_examples/iceperf/example_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ enum class Technology
{
ALL,
ICEORYX_CPP_API,
ICEORYX_CPP_WAIT_API,
ICEORYX_C_API,
POSIX_MESSAGE_QUEUE,
UNIX_DOMAIN_SOCKET
Expand Down
10 changes: 8 additions & 2 deletions iceoryx_examples/iceperf/iceoryx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,14 @@
#include <thread>

Iceoryx::Iceoryx(const iox::capro::IdString_t& publisherName, const iox::capro::IdString_t& subscriberName) noexcept
: m_publisher({"IcePerf", publisherName, "C++-API"}, iox::popo::PublisherOptions{1U})
, m_subscriber({"IcePerf", subscriberName, "C++-API"}, iox::popo::SubscriberOptions{1U, 1U})
: Iceoryx(publisherName, subscriberName, "C++-API")
{
}
Iceoryx::Iceoryx(const iox::capro::IdString_t& publisherName,
const iox::capro::IdString_t& subscriberName,
const iox::capro::IdString_t& eventName) noexcept
elBoberido marked this conversation as resolved.
Show resolved Hide resolved
: m_publisher({"IcePerf", publisherName, eventName}, iox::popo::PublisherOptions{1U})
, m_subscriber({"IcePerf", subscriberName, eventName}, iox::popo::SubscriberOptions{1U, 1U})
{
}

Expand Down
7 changes: 5 additions & 2 deletions iceoryx_examples/iceperf/iceoryx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ class Iceoryx : public IcePerfBase
void initFollower() noexcept override;
void shutdown() noexcept override;

private:
void init() noexcept;
protected:
Iceoryx(const iox::capro::IdString_t& publisherName,
const iox::capro::IdString_t& subscriberName,
const iox::capro::IdString_t& eventName) noexcept;
virtual void init() noexcept;
void sendPerfTopic(const uint32_t payloadSizeInBytes, const RunFlag runFlag) noexcept override;
PerfTopic receivePerfTopic() noexcept override;

Expand Down
52 changes: 52 additions & 0 deletions iceoryx_examples/iceperf/iceoryx_wait.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright 2023, Eclipse Foundation and the iceoryx contributors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
elBoberido marked this conversation as resolved.
Show resolved Hide resolved
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://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

#include "iceoryx_wait.hpp"

IceoryxWait::IceoryxWait(const iox::capro::IdString_t& publisherName,
const iox::capro::IdString_t& subscriberName) noexcept
: Iceoryx(publisherName, subscriberName, "C++-Wait-API")
{
}

void IceoryxWait::init() noexcept
{
Iceoryx::init();

waitset.attachState(m_subscriber, iox::popo::SubscriberState::HAS_DATA).or_else([](auto) {
std::cerr << "failed to attach subscriber" << std::endl;
std::exit(EXIT_FAILURE);
});
}

PerfTopic IceoryxWait::receivePerfTopic() noexcept
{
PerfTopic receivedSample;

auto notificationVector = waitset.wait();
for (auto& notification : notificationVector)
{
if (notification->doesOriginateFrom(&m_subscriber))
{
m_subscriber.take().and_then([&](const void* data) {
receivedSample = *(static_cast<const PerfTopic*>(data));
m_subscriber.release(data);
});
}
}

return receivedSample;
}
33 changes: 33 additions & 0 deletions iceoryx_examples/iceperf/iceoryx_wait.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2023, Eclipse Foundation and the iceoryx contributors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
anderay marked this conversation as resolved.
Show resolved Hide resolved
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://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
#ifndef IOX_EXAMPLES_ICEPERF_ICEORYX_WAIT_HPP
#define IOX_EXAMPLES_ICEPERF_ICEORYX_WAIT_HPP

#include "iceoryx.hpp"

class IceoryxWait : public Iceoryx
{
public:
IceoryxWait(const iox::capro::IdString_t& publisherName, const iox::capro::IdString_t& subscriberName) noexcept;

private:
void init() noexcept override;
PerfTopic receivePerfTopic() noexcept override;

iox::popo::WaitSet<> waitset;
};

#endif // IOX_EXAMPLES_ICEPERF_ICEORYX_WAIT_HPP
9 changes: 9 additions & 0 deletions iceoryx_examples/iceperf/iceperf_follower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "iceoryx.hpp"
#include "iceoryx_c.hpp"
#include "iceoryx_posh/runtime/posh_runtime.hpp"
#include "iceoryx_wait.hpp"
#include "mq.hpp"
#include "topic_data.hpp"
#include "uds.hpp"
Expand Down Expand Up @@ -119,6 +120,14 @@ int IcePerfFollower::run() noexcept
IceoryxC iceoryxc(PUBLISHER, SUBSCRIBER);
doMeasurement(iceoryxc);
}

if (m_settings.technology == Technology::ALL || m_settings.technology == Technology::ICEORYX_CPP_WAIT_API)
{
std::cout << std::endl << "****** ICEORYX WAITSET ********" << std::endl;
IceoryxWait iceoryxwait(PUBLISHER, SUBSCRIBER);
doMeasurement(iceoryxwait);
}

//! [create an run technologies]

return EXIT_SUCCESS;
Expand Down
43 changes: 34 additions & 9 deletions iceoryx_examples/iceperf/iceperf_leader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "iceoryx_posh/popo/publisher.hpp"
#include "iceoryx_posh/popo/subscriber.hpp"
#include "iceoryx_posh/runtime/posh_runtime.hpp"
#include "iceoryx_wait.hpp"
#include "mq.hpp"
#include "topic_data.hpp"
#include "uds.hpp"
Expand Down Expand Up @@ -53,20 +54,37 @@ void IcePerfLeader::doMeasurement(IcePerfBase& ipcTechnology) noexcept
ipcTechnology.initLeader();

std::vector<std::tuple<uint32_t, iox::units::Duration>> latencyMeasurements;
const std::vector<uint32_t> payloadSizesInKB{1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096};
const std::vector<uint32_t> payloadSizes{16,
32,
64,
128,
256,
512,
1 * IcePerfBase::ONE_KILOBYTE,
2 * IcePerfBase::ONE_KILOBYTE,
4 * IcePerfBase::ONE_KILOBYTE,
8 * IcePerfBase::ONE_KILOBYTE,
16 * IcePerfBase::ONE_KILOBYTE,
32 * IcePerfBase::ONE_KILOBYTE,
64 * IcePerfBase::ONE_KILOBYTE,
128 * IcePerfBase::ONE_KILOBYTE,
256 * IcePerfBase::ONE_KILOBYTE,
512 * IcePerfBase::ONE_KILOBYTE,
1024 * IcePerfBase::ONE_KILOBYTE,
2048 * IcePerfBase::ONE_KILOBYTE,
4096 * IcePerfBase::ONE_KILOBYTE};
std::cout << "Measurement for:";
const char* separator = " ";
for (const auto payloadSizeInKB : payloadSizesInKB)
for (const auto payloadSize : payloadSizes)
{
std::cout << separator << payloadSizeInKB << " kB" << std::flush;
std::cout << separator << payloadSize << std::flush;
separator = ", ";
auto payloadSizeInBytes = payloadSizeInKB * IcePerfBase::ONE_KILOBYTE;

ipcTechnology.preLatencyPerfTestLeader(payloadSizeInBytes);
ipcTechnology.preLatencyPerfTestLeader(payloadSize);

auto latency = ipcTechnology.latencyPerfTestLeader(m_settings.numberOfSamples);

latencyMeasurements.push_back(std::make_tuple(payloadSizeInKB, latency));
latencyMeasurements.push_back(std::make_tuple(payloadSize, latency));

ipcTechnology.postLatencyPerfTestLeader();
}
Expand All @@ -80,13 +98,13 @@ void IcePerfLeader::doMeasurement(IcePerfBase& ipcTechnology) noexcept
std::cout << "#### Measurement Result ####" << std::endl;
std::cout << m_settings.numberOfSamples << " round trips for each payload." << std::endl;
std::cout << std::endl;
std::cout << "| Payload Size [kB] | Average Latency [µs] |" << std::endl;
std::cout << "| Payload Size | Average Latency [µs] |" << std::endl;
elBoberido marked this conversation as resolved.
Show resolved Hide resolved
std::cout << "|------------------:|---------------------:|" << std::endl;
for (const auto& latencyMeasuement : latencyMeasurements)
{
auto payloadSizeInKB = std::get<0>(latencyMeasuement);
auto payloadSize = std::get<0>(latencyMeasuement);
auto latencyInMicroseconds = static_cast<double>(std::get<1>(latencyMeasuement).toNanoseconds()) / 1000.0;
std::cout << "| " << std::setw(17) << payloadSizeInKB << " | " << std::setw(20) << std::setprecision(2)
std::cout << "| " << std::setw(17) << payloadSize << " | " << std::setw(20) << std::setprecision(2)
<< latencyInMicroseconds << " |" << std::endl;
}

Expand Down Expand Up @@ -147,6 +165,13 @@ int IcePerfLeader::run() noexcept
IceoryxC iceoryxc(PUBLISHER, SUBSCRIBER);
doMeasurement(iceoryxc);
}

if (m_settings.technology == Technology::ALL || m_settings.technology == Technology::ICEORYX_CPP_WAIT_API)
{
std::cout << std::endl << "****** ICEORYX WAITSET ********" << std::endl;
IceoryxWait iceoryxwait(PUBLISHER, SUBSCRIBER);
doMeasurement(iceoryxwait);
}
//! [create an run technologies]

return EXIT_SUCCESS;
Expand Down
5 changes: 5 additions & 0 deletions iceoryx_examples/iceperf/main_leader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ int main(int argc, char* argv[])
std::cout << "-t, --technology <TYPE> Selects the type of technology to benchmark" << std::endl;
std::cout << " <TYPE> {all," << std::endl;
std::cout << " iceoryx-cpp-api," << std::endl;
std::cout << " iceoryx-cpp-waitset-api," << std::endl;
std::cout << " iceoryx-c-api," << std::endl;
std::cout << " posix-message-queue," << std::endl;
std::cout << " unix-domain-sockets}" << std::endl;
Expand Down Expand Up @@ -90,6 +91,10 @@ int main(int argc, char* argv[])
{
settings.technology = Technology::ICEORYX_CPP_API;
}
else if (strcmp(optarg, "iceoryx-cpp-waitset-api") == 0)
{
settings.technology = Technology::ICEORYX_CPP_WAIT_API;
}
else if (strcmp(optarg, "iceoryx-c-api") == 0)
{
settings.technology = Technology::ICEORYX_C_API;
Expand Down
Loading