diff options
author | Colm Donelan <Colm.Donelan@arm.com> | 2019-10-11 13:09:49 +0100 |
---|---|---|
committer | Colm Donelan <Colm.Donelan@arm.com> | 2019-10-11 13:12:37 +0100 |
commit | a21620d32a8a0a8d527c061e2a22d51009d75877 (patch) | |
tree | b08ffee4cddb1bb3b1d206c67ea80bc2093d7bf5 /tests/profiling/gatordmock/PeriodicCounterCaptureCommandHandler.cpp | |
parent | 67ef2a52c3cdcc37538d77711bbcea2f0e5655e5 (diff) | |
download | armnn-a21620d32a8a0a8d527c061e2a22d51009d75877.tar.gz |
IVGCVSW-3721 Add support for startup sequence (Mock Gatord service).
* Receive and process the stream metadata from the client.
* Send the connection ack packet.
* Wait in a receiving thread and print the packets.
* GatordMockTest and Impl for PeriodicCounterCapture CommandHandler
* CaptureData class to retain packet data
* MockUtils
* Update SocketProfilingConnection to fix non blocking receipt of packets.
* Restructure directory layout following review comments.
* Extract the mock service into a static library in the cmake files.
Signed-off-by: Colm Donelan <Colm.Donelan@arm.com>
Signed-off-by: Keith Davis <keith.davis@arm.com>
Signed-off-by: Mike Kelly <mike.kelly@arm.com>
Signed-off-by: Finn Williams <Finn.Williams@arm.com>
Signed-off-by: Kevin May <kevin.may@arm.com>
Change-Id: I33c1c9f93976708c9315f71290d42cff53b8c075
Diffstat (limited to 'tests/profiling/gatordmock/PeriodicCounterCaptureCommandHandler.cpp')
-rw-r--r-- | tests/profiling/gatordmock/PeriodicCounterCaptureCommandHandler.cpp | 147 |
1 files changed, 147 insertions, 0 deletions
diff --git a/tests/profiling/gatordmock/PeriodicCounterCaptureCommandHandler.cpp b/tests/profiling/gatordmock/PeriodicCounterCaptureCommandHandler.cpp new file mode 100644 index 0000000000..5a70f68805 --- /dev/null +++ b/tests/profiling/gatordmock/PeriodicCounterCaptureCommandHandler.cpp @@ -0,0 +1,147 @@ +// +// Copyright © 2019 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include <iostream> + +#include "../../../src/profiling/ProfilingUtils.hpp" +#include "PeriodicCounterCaptureCommandHandler.hpp" + +#include <boost/numeric/conversion/cast.hpp> + +namespace armnn +{ + +namespace gatordmock +{ + +using boost::numeric_cast; + +std::string CentreAlignFormatting(const std::string stringToPass, const int spacingWidth) +{ + std::stringstream outputStream, centrePadding; + int padding = spacingWidth - static_cast<int>(stringToPass.size()); + + for (int i = 0; i < padding / 2; ++i) + { + centrePadding << " "; + } + + outputStream << centrePadding.str() << stringToPass << centrePadding.str(); + + if (padding > 0 && padding % 2 != 0) + { + outputStream << " "; + } + + return outputStream.str(); +} + +void PeriodicCounterCaptureCommandHandler::ParseData(const armnn::profiling::Packet& packet) +{ + std::vector<uint16_t> counterIds; + std::vector<uint32_t> counterValues; + + uint32_t sizeOfUint64 = numeric_cast<uint32_t>(sizeof(uint64_t)); + uint32_t sizeOfUint32 = numeric_cast<uint32_t>(sizeof(uint32_t)); + uint32_t sizeOfUint16 = numeric_cast<uint32_t>(sizeof(uint16_t)); + + uint32_t offset = 0; + + if (packet.GetLength() >= 8) + { + offset = 0; + + uint64_t timestamp = profiling::ReadUint64(reinterpret_cast<const unsigned char*>(packet.GetData()), offset); + + if (m_FirstTimestamp == 0) // detect the first timestamp we receive. + { + m_FirstTimestamp = timestamp; + } + else + { + m_SecondTimestamp = timestamp; + m_CurrentPeriodValue = m_SecondTimestamp - m_FirstTimestamp; + m_FirstTimestamp = m_SecondTimestamp; + } + + // Length minus timestamp and header divided by the length of an indexPair + unsigned int counters = (packet.GetLength() - 8) / 6; + + if (counters > 0) + { + counterIds.reserve(counters); + counterValues.reserve(counters); + // Move offset over timestamp area + offset += sizeOfUint64; + for (unsigned int pos = 0; pos < counters; ++pos) + { + counterIds.emplace_back( + profiling::ReadUint16(reinterpret_cast<const unsigned char*>(packet.GetData()), offset)); + offset += sizeOfUint16; + + counterValues.emplace_back( + profiling::ReadUint32(reinterpret_cast<const unsigned char*>(packet.GetData()), offset)); + offset += sizeOfUint32; + } + } + + m_CounterCaptureValues.m_Timestamp = timestamp; + m_CounterCaptureValues.m_Uids = counterIds; + m_CounterCaptureValues.m_Values = counterValues; + } +} + +void PeriodicCounterCaptureCommandHandler::operator()(const profiling::Packet& packet) +{ + ParseData(packet); + if (m_EchoPackets) + { + std::string header, body, uidString, valueString; + + for (uint16_t uid : m_CounterCaptureValues.m_Uids) + { + uidString.append(std::to_string(uid)); + uidString.append(", "); + } + + for (uint32_t val : m_CounterCaptureValues.m_Values) + { + valueString.append(std::to_string(val)); + valueString.append(", "); + } + + body.append(gatordmock::CentreAlignFormatting(std::to_string(m_CounterCaptureValues.m_Timestamp), 10)); + body.append(" | "); + body.append(gatordmock::CentreAlignFormatting(std::to_string(m_CurrentPeriodValue), 13)); + body.append(" | "); + body.append(gatordmock::CentreAlignFormatting(uidString, 10)); + body.append(" | "); + body.append(gatordmock::CentreAlignFormatting(valueString, 10)); + body.append("\n"); + + if (!m_HeaderPrinted) + { + header.append(gatordmock::CentreAlignFormatting(" Timestamp", 11)); + header.append(" | "); + header.append(gatordmock::CentreAlignFormatting("Period (us)", 13)); + header.append(" | "); + header.append(gatordmock::CentreAlignFormatting("UID's", static_cast<int>(uidString.size()))); + header.append(" | "); + header.append(gatordmock::CentreAlignFormatting("Values", 10)); + header.append("\n"); + + std::cout << header; + m_HeaderPrinted = true; + } + + std::cout << std::string(body.size(), '-') << "\n"; + + std::cout << body; + } +} + +} // namespace gatordmock + +} // namespace armnn
\ No newline at end of file |