Skip to content

Commit

Permalink
iox-#2003 Make iceperf memory size output human readable
Browse files Browse the repository at this point in the history
  • Loading branch information
elBoberido committed Aug 9, 2023
1 parent 7865d0e commit 615e560
Showing 1 changed file with 35 additions and 6 deletions.
41 changes: 35 additions & 6 deletions iceoryx_examples/iceperf/iceperf_leader.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) 2019 - 2020 by Robert Bosch GmbH. All rights reserved.
// Copyright (c) 2020 - 2021 by Apex.AI Inc. All rights reserved.
// Copyright (c) 2023 by Mathias Kraus <[email protected]>. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -53,6 +54,25 @@ void IcePerfLeader::doMeasurement(IcePerfBase& ipcTechnology) noexcept
{
ipcTechnology.initLeader();

auto humanReadableMemorySize = [](const uint64_t memorySize) {
constexpr const uint64_t UNIT_DIVIDER{1024};
auto humanReadalbeMemorySize = memorySize;
for (const auto& unit : {iox::string<2>("B"),
iox::string<2>("kB"),
iox::string<2>("MB"),
iox::string<2>("GB"),
iox::string<2>("TB")})
{
if (humanReadalbeMemorySize >= UNIT_DIVIDER)
{
humanReadalbeMemorySize /= UNIT_DIVIDER;
continue;
}
return std::make_tuple(humanReadalbeMemorySize, unit);
}
return (std::make_tuple(memorySize, iox::string<2>("B")));
};

std::vector<std::tuple<uint32_t, iox::units::Duration>> latencyMeasurements;
const std::vector<uint32_t> payloadSizes{16,
32,
Expand All @@ -77,7 +97,10 @@ void IcePerfLeader::doMeasurement(IcePerfBase& ipcTechnology) noexcept
const char* separator = " ";
for (const auto payloadSize : payloadSizes)
{
std::cout << separator << payloadSize << std::flush;
uint64_t humanReadablePayloadSize{0};
iox::string<2> memorySizeUnit{};
std::tie(humanReadablePayloadSize, memorySizeUnit) = humanReadableMemorySize(payloadSize);
std::cout << separator << humanReadablePayloadSize << " [" << memorySizeUnit << "]" << std::flush;
separator = ", ";

ipcTechnology.preLatencyPerfTestLeader(payloadSize);
Expand All @@ -98,14 +121,20 @@ 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 | Average Latency [µs] |" << std::endl;
std::cout << "|------------------:|---------------------:|" << std::endl;
std::cout << "| Payload Size | Average Latency [µs] |" << std::endl;
std::cout << "|-------------:|---------------------:|" << std::endl;
for (const auto& latencyMeasuement : latencyMeasurements)
{
auto payloadSize = std::get<0>(latencyMeasuement);
uint64_t humanReadablePayloadSize{0};
iox::string<2> memorySizeUnit{};
std::tie(humanReadablePayloadSize, memorySizeUnit) = humanReadableMemorySize(std::get<0>(latencyMeasuement));
auto latencyInMicroseconds = static_cast<double>(std::get<1>(latencyMeasuement).toNanoseconds()) / 1000.0;
std::cout << "| " << std::setw(17) << payloadSize << " | " << std::setw(20) << std::setprecision(2)
<< latencyInMicroseconds << " |" << std::endl;
iox::string<10> unitString{"["};
unitString.append(iox::TruncateToCapacity, memorySizeUnit);
unitString.append(iox::TruncateToCapacity, "]");
std::cout << "| " << std::setw(7) << humanReadablePayloadSize << " " << std::setw(4) << std::left << unitString
<< std::right << " | " << std::setw(20) << std::setprecision(2) << latencyInMicroseconds << " |"
<< std::endl;
}

std::cout << std::endl;
Expand Down

0 comments on commit 615e560

Please sign in to comment.