aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorColm Donelan <Colm.Donelan@arm.com>2019-10-16 12:24:20 +0100
committerColm Donelan <colm.donelan@arm.com>2019-10-17 15:59:55 +0000
commitb682d840bb0b4cc34f4febb69c2385feec880ae1 (patch)
tree155457d5c382deec0b45fd85a0609a4c3322613e /tests
parent5ae78299f117a61c48a67c5381341501571a0b03 (diff)
downloadarmnn-b682d840bb0b4cc34f4febb69c2385feec880ae1.tar.gz
IVGCVSW-3721 Add support for startup sequence (Mock Gatord service).
* Updated ExecuteNetwork to propagate a configured Runtime down to RunTest. * Fixed the creation of PeriodicCounterCaptureCommandHandler to match other handlers. * Moved around some printouts to make the MockGatorD output more useful. * Added details to the exception handling for problems in the GatordMockService receive thread. * Mockutils::ConstructHeader is only used in GatordMockTests. Moved it in there and deleted MockUtils.hpp * Refactored SendPeriodicCounterSelectionList to use ProfilingUtils. * Added PeriodicCounterSelectionResponseHandler to received packet echoed back. Signed-off-by: Colm Donelan <Colm.Donelan@arm.com> Change-Id: I4accdbf6cf5dd3f7dcc12b210b8360b4a5e4e277
Diffstat (limited to 'tests')
-rw-r--r--tests/ExecuteNetwork/ExecuteNetwork.cpp14
-rw-r--r--tests/profiling/gatordmock/CommandFileParser.hpp8
-rw-r--r--tests/profiling/gatordmock/CommandLineProcessor.hpp24
-rw-r--r--tests/profiling/gatordmock/GatordMockMain.cpp27
-rw-r--r--tests/profiling/gatordmock/GatordMockService.cpp146
-rw-r--r--tests/profiling/gatordmock/GatordMockService.hpp28
-rw-r--r--tests/profiling/gatordmock/MockUtils.hpp35
-rw-r--r--tests/profiling/gatordmock/PeriodicCounterCaptureCommandHandler.cpp2
-rw-r--r--tests/profiling/gatordmock/PeriodicCounterCaptureCommandHandler.hpp19
-rw-r--r--tests/profiling/gatordmock/PeriodicCounterSelectionResponseHandler.cpp37
-rw-r--r--tests/profiling/gatordmock/PeriodicCounterSelectionResponseHandler.hpp42
-rw-r--r--tests/profiling/gatordmock/tests/GatordMockTests.cpp23
12 files changed, 254 insertions, 151 deletions
diff --git a/tests/ExecuteNetwork/ExecuteNetwork.cpp b/tests/ExecuteNetwork/ExecuteNetwork.cpp
index 1c1fa10031..931bcd4d5f 100644
--- a/tests/ExecuteNetwork/ExecuteNetwork.cpp
+++ b/tests/ExecuteNetwork/ExecuteNetwork.cpp
@@ -41,7 +41,6 @@ int main(int argc, const char* argv[])
const std::string backendsMessage = "REQUIRED: Which device to run layers on by default. Possible choices: "
+ armnn::BackendRegistryInstance().GetBackendIdsAsString();
-
po::options_description desc("Options");
try
{
@@ -185,7 +184,6 @@ int main(int argc, const char* argv[])
options.m_ProfilingOptions.m_OutgoingCaptureFile = outgoingCaptureFile;
options.m_ProfilingOptions.m_FileOnly = fileOnlyExternalProfiling;
options.m_ProfilingOptions.m_CapturePeriod = counterCapturePeriod;
-
std::shared_ptr<armnn::IRuntime> runtime(armnn::IRuntime::Create(options));
const std::string executableName("ExecuteNetwork");
@@ -254,10 +252,18 @@ int main(int argc, const char* argv[])
std::cerr << desc << std::endl;
return EXIT_FAILURE;
}
-
+ // Create runtime
+ armnn::IRuntime::CreationOptions options;
+ options.m_EnableGpuProfiling = enableProfiling;
+ options.m_ProfilingOptions.m_EnableProfiling = enableExternalProfiling;
+ options.m_ProfilingOptions.m_IncomingCaptureFile = incomingCaptureFile;
+ options.m_ProfilingOptions.m_OutgoingCaptureFile = outgoingCaptureFile;
+ options.m_ProfilingOptions.m_FileOnly = fileOnlyExternalProfiling;
+ options.m_ProfilingOptions.m_CapturePeriod = counterCapturePeriod;
+ std::shared_ptr<armnn::IRuntime> runtime(armnn::IRuntime::Create(options));
return RunTest(modelFormat, inputTensorShapes, computeDevices, dynamicBackendsPath, modelPath, inputNames,
inputTensorDataFilePaths, inputTypes, quantizeInput, outputTypes, outputNames,
outputTensorFiles, enableProfiling, enableFp16TurboMode, thresholdTime, printIntermediate,
- subgraphId, enableLayerDetails);
+ subgraphId, enableLayerDetails, runtime);
}
}
diff --git a/tests/profiling/gatordmock/CommandFileParser.hpp b/tests/profiling/gatordmock/CommandFileParser.hpp
index e95395d206..fd4a4fdf38 100644
--- a/tests/profiling/gatordmock/CommandFileParser.hpp
+++ b/tests/profiling/gatordmock/CommandFileParser.hpp
@@ -5,8 +5,8 @@
#pragma once
-#include <string>
#include "GatordMockService.hpp"
+#include <string>
namespace armnn
{
@@ -25,7 +25,5 @@ public:
void ParseFile(std::string CommandFile, GatordMockService& mockService);
};
-} // namespace gatordmock
-} // namespace armnn
-
-
+} // namespace gatordmock
+} // namespace armnn
diff --git a/tests/profiling/gatordmock/CommandLineProcessor.hpp b/tests/profiling/gatordmock/CommandLineProcessor.hpp
index 0eed23ace8..532948a5cf 100644
--- a/tests/profiling/gatordmock/CommandLineProcessor.hpp
+++ b/tests/profiling/gatordmock/CommandLineProcessor.hpp
@@ -12,7 +12,6 @@ namespace armnn
namespace gatordmock
{
-
/// Use Boost program options to process the command line.
/// -h or --help to print the options.
/// -n or --namespace to specify the UDS namespace that the server will be listening on.
@@ -21,11 +20,20 @@ namespace gatordmock
class CommandLineProcessor
{
public:
- bool ProcessCommandLine(int argc, char *argv[]);
- bool IsEchoEnabled() { return m_Echo; }
-
- std::string GetUdsNamespace() { return m_UdsNamespace; }
- std::string GetCommandFile() { return m_File; }
+ bool ProcessCommandLine(int argc, char* argv[]);
+ bool IsEchoEnabled()
+ {
+ return m_Echo;
+ }
+
+ std::string GetUdsNamespace()
+ {
+ return m_UdsNamespace;
+ }
+ std::string GetCommandFile()
+ {
+ return m_File;
+ }
private:
std::string m_UdsNamespace;
@@ -34,6 +42,6 @@ private:
bool m_Echo;
};
-} // namespace gatordmock
+} // namespace gatordmock
-} // namespace armnn
+} // namespace armnn
diff --git a/tests/profiling/gatordmock/GatordMockMain.cpp b/tests/profiling/gatordmock/GatordMockMain.cpp
index 500b016669..002d6c7c5a 100644
--- a/tests/profiling/gatordmock/GatordMockMain.cpp
+++ b/tests/profiling/gatordmock/GatordMockMain.cpp
@@ -3,15 +3,18 @@
// SPDX-License-Identifier: MIT
//
+#include "../../../src/profiling/PacketVersionResolver.hpp"
+#include "../../../src/profiling/PeriodicCounterSelectionCommandHandler.hpp"
#include "CommandFileParser.hpp"
#include "CommandLineProcessor.hpp"
#include "GatordMockService.hpp"
-#include "MockUtils.hpp"
#include "PeriodicCounterCaptureCommandHandler.hpp"
+#include "PeriodicCounterSelectionResponseHandler.hpp"
+#include <iostream>
#include <string>
-int main(int argc, char *argv[])
+int main(int argc, char* argv[])
{
// Process command line arguments
armnn::gatordmock::CommandLineProcessor cmdLine;
@@ -20,21 +23,19 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
- // Initialise functors and register into the CommandHandlerRegistry
- uint32_t version = 1;
-
- // Create headers
- uint32_t counterCaptureCommandHeader = armnn::gatordmock::ConstructHeader(1,0,0);
-
+ armnn::profiling::PacketVersionResolver packetVersionResolver;
// Create the Command Handler Registry
armnn::profiling::CommandHandlerRegistry registry;
- // Update with derived functors
- armnn::gatordmock::PeriodicCounterCaptureCommandHandler counterCaptureCommandHandler(counterCaptureCommandHeader,
- version,
- cmdLine.IsEchoEnabled());
+ // This functor will receive back the selection response packet.
+ armnn::gatordmock::PeriodicCounterSelectionResponseHandler periodicCounterSelectionResponseHandler(
+ 4, packetVersionResolver.ResolvePacketVersion(4).GetEncodedValue());
+ // This functor will receive the counter data.
+ armnn::gatordmock::PeriodicCounterCaptureCommandHandler counterCaptureCommandHandler(
+ 0, packetVersionResolver.ResolvePacketVersion(0).GetEncodedValue());
// Register different derived functors
+ registry.RegisterFunctor(&periodicCounterSelectionResponseHandler);
registry.RegisterFunctor(&counterCaptureCommandHandler);
armnn::gatordmock::GatordMockService mockService(registry, cmdLine.IsEchoEnabled());
@@ -43,12 +44,14 @@ int main(int argc, char *argv[])
{
return EXIT_FAILURE;
}
+ std::cout << "Bound to UDS namespace: \\0" << cmdLine.GetUdsNamespace() << std::endl;
// Wait for a single connection.
if (-1 == mockService.BlockForOneClient())
{
return EXIT_FAILURE;
}
+ std::cout << "Client connection established." << std::endl;
// Send receive the strweam metadata and send connection ack.
if (!mockService.WaitForStreamMetaData())
diff --git a/tests/profiling/gatordmock/GatordMockService.cpp b/tests/profiling/gatordmock/GatordMockService.cpp
index b5531c4e08..4b9d7524f3 100644
--- a/tests/profiling/gatordmock/GatordMockService.cpp
+++ b/tests/profiling/gatordmock/GatordMockService.cpp
@@ -6,9 +6,12 @@
#include "GatordMockService.hpp"
#include <CommandHandlerRegistry.hpp>
+#include "../../src/profiling/PacketVersionResolver.hpp"
+#include "../../src/profiling/ProfilingUtils.hpp"
#include <cerrno>
#include <fcntl.h>
+#include <iomanip>
#include <iostream>
#include <poll.h>
#include <string>
@@ -39,7 +42,7 @@ bool GatordMockService::OpenListeningSocket(std::string udsNamespace)
udsAddress.sun_family = AF_UNIX;
// Bind the socket to the UDS namespace.
- if (-1 == bind(m_ListeningSocket, reinterpret_cast<const sockaddr *>(&udsAddress), sizeof(sockaddr_un)))
+ if (-1 == bind(m_ListeningSocket, reinterpret_cast<const sockaddr*>(&udsAddress), sizeof(sockaddr_un)))
{
std::cerr << ": Binding on socket failed: " << strerror(errno) << std::endl;
return false;
@@ -50,30 +53,17 @@ bool GatordMockService::OpenListeningSocket(std::string udsNamespace)
std::cerr << ": Listen call on socket failed: " << strerror(errno) << std::endl;
return false;
}
- if (m_EchoPackets)
- {
- std::cout << "Bound to UDS namespace: \\0" << udsNamespace << std::endl;
- }
return true;
}
int GatordMockService::BlockForOneClient()
{
- if (m_EchoPackets)
- {
- std::cout << "Waiting for client connection." << std::endl;
- }
m_ClientConnection = accept4(m_ListeningSocket, nullptr, nullptr, SOCK_CLOEXEC);
if (-1 == m_ClientConnection)
{
std::cerr << ": Failure when waiting for a client connection: " << strerror(errno) << std::endl;
return -1;
}
-
- if (m_EchoPackets)
- {
- std::cout << "Client connection established." << std::endl;
- }
return m_ClientConnection;
}
@@ -89,7 +79,7 @@ bool GatordMockService::WaitForStreamMetaData()
{
return false;
}
- EchoPacket(PacketDirection::Received, header, 8);
+ EchoPacket(PacketDirection::ReceivedHeader, header, 8);
// The first word, stream_metadata_identifer, should always be 0.
if (ToUint32(&header[0], TargetEndianness::BeWire) != 0)
{
@@ -102,7 +92,7 @@ bool GatordMockService::WaitForStreamMetaData()
{
return false;
}
- EchoPacket(PacketDirection::Received, pipeMagic, 4);
+ EchoPacket(PacketDirection::ReceivedData, pipeMagic, 4);
// Before we interpret the length we need to read the pipe_magic word to determine endianness.
if (ToUint32(&pipeMagic[0], TargetEndianness::BeWire) == PIPE_MAGIC)
@@ -128,10 +118,10 @@ bool GatordMockService::WaitForStreamMetaData()
std::cerr << ": Protocol read error. Data length mismatch." << std::endl;
return false;
}
- EchoPacket(PacketDirection::Received, packetData, metaDataLength);
- m_StreamMetaDataVersion = ToUint32(&packetData[0], m_Endianness);
+ EchoPacket(PacketDirection::ReceivedData, packetData, metaDataLength);
+ m_StreamMetaDataVersion = ToUint32(&packetData[0], m_Endianness);
m_StreamMetaDataMaxDataLen = ToUint32(&packetData[4], m_Endianness);
- m_StreamMetaDataPid = ToUint32(&packetData[8], m_Endianness);
+ m_StreamMetaDataPid = ToUint32(&packetData[8], m_Endianness);
return true;
}
@@ -175,27 +165,37 @@ void GatordMockService::WaitForReceivingThread()
}
}
-
-void GatordMockService::SendPeriodicCounterSelectionList(uint period, std::vector<uint16_t> counters)
+void GatordMockService::SendPeriodicCounterSelectionList(uint32_t period, std::vector<uint16_t> counters)
{
- //get the datalength in bytes
- uint32_t datalength = static_cast<uint32_t>(4 + counters.size() * 2);
+ // The packet body consists of a UINT32 representing the period following by zero or more
+ // UINT16's representing counter UID's. If the list is empty it implies all counters are to
+ // be disabled.
- u_char data[datalength];
+ if (m_EchoPackets)
+ {
+ std::cout << "SendPeriodicCounterSelectionList: Period=" << std::dec << period << "uSec" << std::endl;
+ std::cout << "List length=" << counters.size() << std::endl;
+ ;
+ }
+ // Start by calculating the length of the packet body in bytes. This will be at least 4.
+ uint32_t dataLength = static_cast<uint32_t>(4 + (counters.size() * 2));
- *data = static_cast<u_char>(period >> 24);
- *(data + 1) = static_cast<u_char>(period >> 16 & 0xFF);
- *(data + 2) = static_cast<u_char>(period >> 8 & 0xFF);
- *(data + 3) = static_cast<u_char>(period & 0xFF);
+ std::unique_ptr<unsigned char[]> uniqueData = std::make_unique<unsigned char[]>(dataLength);
+ unsigned char* data = reinterpret_cast<unsigned char*>(uniqueData.get());
- for (unsigned long i = 0; i < counters.size(); ++i)
+ uint32_t offset = 0;
+ profiling::WriteUint32(data, offset, period);
+ offset += 4;
+ for (std::vector<uint16_t>::iterator it = counters.begin(); it != counters.end(); ++it)
{
- *(data + 4 + i * 2) = static_cast<u_char>(counters[i] >> 8);
- *(data + 5 + i * 2) = static_cast<u_char>(counters[i] & 0xFF);
+ profiling::WriteUint16(data, offset, *it);
+ offset += 2;
}
- // create packet send packet
- SendPacket(0, 4, data, datalength);
+ // Send the packet.
+ SendPacket(0, 4, data, dataLength);
+ // There will be an echo response packet sitting in the receive thread. PeriodicCounterSelectionResponseHandler
+ // should deal with it.
}
void GatordMockService::WaitCommand(uint timeout)
@@ -217,10 +217,21 @@ void GatordMockService::ReceiveLoop(GatordMockService& mockService)
{
armnn::profiling::Packet packet = mockService.WaitForPacket(500);
}
- catch(armnn::TimeoutException)
+ catch (armnn::TimeoutException)
{
// In this case we ignore timeouts and and keep trying to receive.
}
+ catch (armnn::InvalidArgumentException e)
+ {
+ // We couldn't find a functor to handle the packet?
+ std::cerr << "Packet received that could not be processed: " << e.what() << std::endl;
+ }
+ catch (armnn::RuntimeException e)
+ {
+ // A runtime exception occurred which means we must exit the loop.
+ std::cerr << "Receive thread closing: " << e.what() << std::endl;
+ m_CloseReceivingThread.store(true);
+ }
}
}
@@ -239,7 +250,7 @@ armnn::profiling::Packet GatordMockService::WaitForPacket(uint32_t timeoutMs)
// No there's not. Poll for more data.
struct pollfd pollingFd[1]{};
pollingFd[0].fd = m_ClientConnection;
- int pollResult = poll(pollingFd, 1, static_cast<int>(timeoutMs));
+ int pollResult = poll(pollingFd, 1, static_cast<int>(timeoutMs));
switch (pollResult)
{
@@ -254,13 +265,22 @@ armnn::profiling::Packet GatordMockService::WaitForPacket(uint32_t timeoutMs)
// Normal poll return. It could still contain an error signal
default:
-
// Check if the socket reported an error
if (pollingFd[0].revents & (POLLNVAL | POLLERR | POLLHUP))
{
- std::cout << "Error while polling receiving socket." << std::endl;
- throw armnn::RuntimeException(std::string("File descriptor reported an error during polling: ") +
- strerror(errno));
+ if (pollingFd[0].revents == POLLNVAL)
+ {
+ throw armnn::RuntimeException(std::string("Error while polling receiving socket: POLLNVAL"));
+ }
+ if (pollingFd[0].revents == POLLERR)
+ {
+ throw armnn::RuntimeException(std::string("Error while polling receiving socket: POLLERR: ") +
+ strerror(errno));
+ }
+ if (pollingFd[0].revents == POLLHUP)
+ {
+ throw armnn::RuntimeException(std::string("Connection closed by remote client: POLLHUP"));
+ }
}
// Check if there is data to read
@@ -275,7 +295,6 @@ armnn::profiling::Packet GatordMockService::WaitForPacket(uint32_t timeoutMs)
}
}
-
armnn::profiling::Packet GatordMockService::ReceivePacket()
{
uint32_t header[2];
@@ -285,24 +304,30 @@ armnn::profiling::Packet GatordMockService::ReceivePacket()
}
// Read data_length bytes from the socket.
std::unique_ptr<unsigned char[]> uniquePacketData = std::make_unique<unsigned char[]>(header[1]);
- unsigned char *packetData = reinterpret_cast<unsigned char *>(uniquePacketData.get());
+ unsigned char* packetData = reinterpret_cast<unsigned char*>(uniquePacketData.get());
if (!ReadFromSocket(packetData, header[1]))
{
return armnn::profiling::Packet();
}
+ EchoPacket(PacketDirection::ReceivedData, packetData, header[1]);
+
// Construct received packet
+ armnn::profiling::PacketVersionResolver packetVersionResolver;
armnn::profiling::Packet packetRx = armnn::profiling::Packet(header[0], header[1], uniquePacketData);
-
- // Pass packet into the handler registry
- if (packetRx.GetHeader()!= 0)
+ if (m_EchoPackets)
{
- m_PacketsReceivedCount.operator++(std::memory_order::memory_order_release);
- m_HandlerRegistry.GetFunctor(header[0],1)->operator()(packetRx);
+ std::cout << "Processing packet ID= " << packetRx.GetPacketId() << " Length=" << packetRx.GetLength()
+ << std::endl;
}
+ // Pass packet into the handler registry
+ m_PacketsReceivedCount.operator++(std::memory_order::memory_order_release);
+ m_HandlerRegistry
+ .GetFunctor(packetRx.GetPacketId(),
+ packetVersionResolver.ResolvePacketVersion(packetRx.GetPacketId()).GetEncodedValue())
+ ->operator()(packetRx);
- EchoPacket(PacketDirection::Received, packetData, sizeof(packetData));
return packetRx;
}
@@ -314,7 +339,7 @@ bool GatordMockService::SendPacket(uint32_t packetFamily, uint32_t packetId, con
header[0] = packetFamily << 26 | packetId << 16;
header[1] = dataLength;
// Add the header to the packet.
- u_char packet[8 + dataLength ];
+ u_char packet[8 + dataLength];
InsertU32(header[0], packet, m_Endianness);
InsertU32(header[1], packet + 4, m_Endianness);
// And the rest of the data if there is any.
@@ -333,12 +358,13 @@ bool GatordMockService::SendPacket(uint32_t packetFamily, uint32_t packetId, con
bool GatordMockService::ReadHeader(uint32_t headerAsWords[2])
{
- // The herader will always be 2x32bit words.
+ // The header will always be 2x32bit words.
u_char header[8];
if (!ReadFromSocket(header, 8))
{
return false;
}
+ EchoPacket(PacketDirection::ReceivedHeader, header, 8);
headerAsWords[0] = ToUint32(&header[0], m_Endianness);
headerAsWords[1] = ToUint32(&header[4], m_Endianness);
return true;
@@ -373,10 +399,15 @@ void GatordMockService::EchoPacket(PacketDirection direction, u_char* packet, si
{
if (direction == PacketDirection::Sending)
{
- std::cout << "Sending " << std::dec << lengthInBytes << " bytes : ";
- } else
+ std::cout << "TX " << std::dec << lengthInBytes << " bytes : ";
+ }
+ else if (direction == PacketDirection::ReceivedHeader)
+ {
+ std::cout << "RX Header " << std::dec << lengthInBytes << " bytes : ";
+ }
+ else
{
- std::cout << "Received " << std::dec << lengthInBytes << " bytes : ";
+ std::cout << "RX Data " << std::dec << lengthInBytes << " bytes : ";
}
for (unsigned int i = 0; i < lengthInBytes; i++)
{
@@ -384,7 +415,8 @@ void GatordMockService::EchoPacket(PacketDirection direction, u_char* packet, si
{
std::cout << std::endl;
}
- std::cout << std::hex << "0x" << static_cast<unsigned int>(packet[i]) << " ";
+ std::cout << "0x" << std::setfill('0') << std::setw(2) << std::hex << static_cast<unsigned int>(packet[i])
+ << " ";
}
std::cout << std::endl;
}
@@ -412,7 +444,7 @@ void GatordMockService::InsertU32(uint32_t value, u_char* data, TargetEndianness
// the endianness value.
if (endianness == TargetEndianness::BeWire)
{
- *data = static_cast<u_char>((value >> 24) & 0xFF);
+ *data = static_cast<u_char>((value >> 24) & 0xFF);
*(data + 1) = static_cast<u_char>((value >> 16) & 0xFF);
*(data + 2) = static_cast<u_char>((value >> 8) & 0xFF);
*(data + 3) = static_cast<u_char>(value & 0xFF);
@@ -422,10 +454,10 @@ void GatordMockService::InsertU32(uint32_t value, u_char* data, TargetEndianness
*(data + 3) = static_cast<u_char>((value >> 24) & 0xFF);
*(data + 2) = static_cast<u_char>((value >> 16) & 0xFF);
*(data + 1) = static_cast<u_char>((value >> 8) & 0xFF);
- *data = static_cast<u_char>(value & 0xFF);
+ *data = static_cast<u_char>(value & 0xFF);
}
}
-} // namespace gatordmock
+} // namespace gatordmock
-} // namespace armnn
+} // namespace armnn
diff --git a/tests/profiling/gatordmock/GatordMockService.hpp b/tests/profiling/gatordmock/GatordMockService.hpp
index c860f16815..10bf88406e 100644
--- a/tests/profiling/gatordmock/GatordMockService.hpp
+++ b/tests/profiling/gatordmock/GatordMockService.hpp
@@ -8,9 +8,9 @@
#include <CommandHandlerRegistry.hpp>
#include <Packet.hpp>
+#include <atomic>
#include <string>
#include <thread>
-#include <atomic>
namespace armnn
{
@@ -20,12 +20,15 @@ namespace gatordmock
enum class TargetEndianness
{
- BeWire, LeWire
+ BeWire,
+ LeWire
};
enum class PacketDirection
{
- Sending, Received
+ Sending,
+ ReceivedHeader,
+ ReceivedData
};
/// A class that implements a Mock Gatord server. It will listen on a specified Unix domain socket (UDS)
@@ -33,8 +36,6 @@ enum class PacketDirection
class GatordMockService
{
public:
-
-
/// @param registry reference to a command handler registry.
/// @param echoPackets if true the raw packets will be printed to stdout.
GatordMockService(armnn::profiling::CommandHandlerRegistry& registry, bool echoPackets)
@@ -83,7 +84,7 @@ public:
void WaitForReceivingThread();
/// Send the counter list to ArmNN.
- void SendPeriodicCounterSelectionList(uint period, std::vector<uint16_t> counters);
+ void SendPeriodicCounterSelectionList(uint32_t period, std::vector<uint16_t> counters);
/// Execute the WAIT command from the comamnd file.
void WaitCommand(uint timeout);
@@ -104,7 +105,6 @@ public:
}
private:
-
void ReceiveLoop(GatordMockService& mockService);
/// Block on the client connection until a complete packet has been received. This is a placeholder function to
@@ -129,10 +129,10 @@ private:
static const uint32_t PIPE_MAGIC = 0x45495434;
std::atomic<uint32_t> m_PacketsReceivedCount;
- TargetEndianness m_Endianness;
- uint32_t m_StreamMetaDataVersion;
- uint32_t m_StreamMetaDataMaxDataLen;
- uint32_t m_StreamMetaDataPid;
+ TargetEndianness m_Endianness;
+ uint32_t m_StreamMetaDataVersion;
+ uint32_t m_StreamMetaDataMaxDataLen;
+ uint32_t m_StreamMetaDataPid;
armnn::profiling::CommandHandlerRegistry& m_HandlerRegistry;
@@ -142,8 +142,6 @@ private:
std::thread m_ListeningThread;
std::atomic<bool> m_CloseReceivingThread;
};
-} // namespace gatordmock
-
-} // namespace armnn
-
+} // namespace gatordmock
+} // namespace armnn
diff --git a/tests/profiling/gatordmock/MockUtils.hpp b/tests/profiling/gatordmock/MockUtils.hpp
deleted file mode 100644
index 93fc408037..0000000000
--- a/tests/profiling/gatordmock/MockUtils.hpp
+++ /dev/null
@@ -1,35 +0,0 @@
-//
-// Copyright © 2017 Arm Ltd. All rights reserved.
-// SPDX-License-Identifier: MIT
-//
-
-#pragma once
-
-#include <EncodeVersion.hpp>
-
-namespace armnn
-{
-
-namespace gatordmock
-{
-
-
-uint32_t ConstructHeader(uint32_t packetFamily,
- uint32_t packetClass,
- uint32_t packetType)
-{
- return ((packetFamily & 0x3F) << 26)|
- ((packetClass & 0x3FF) << 19)|
- ((packetType & 0x3FFF) << 16);
-}
-
-uint32_t ConstructHeader(uint32_t packetFamily,
- uint32_t packetId)
-{
- return ((packetFamily & 0x3F) << 26)|
- ((packetId & 0x3FF) << 16);
-}
-
-} // gatordmock
-
-} // armnn
diff --git a/tests/profiling/gatordmock/PeriodicCounterCaptureCommandHandler.cpp b/tests/profiling/gatordmock/PeriodicCounterCaptureCommandHandler.cpp
index f3bf7960ea..90d52a7848 100644
--- a/tests/profiling/gatordmock/PeriodicCounterCaptureCommandHandler.cpp
+++ b/tests/profiling/gatordmock/PeriodicCounterCaptureCommandHandler.cpp
@@ -97,7 +97,7 @@ void PeriodicCounterCaptureCommandHandler::ParseData(const armnn::profiling::Pac
void PeriodicCounterCaptureCommandHandler::operator()(const profiling::Packet& packet)
{
ParseData(packet);
- if (m_EchoPackets)
+ if (!m_QuietOperation) // Are we supposed to print to stdout?
{
std::string header, body, uidString, valueString;
diff --git a/tests/profiling/gatordmock/PeriodicCounterCaptureCommandHandler.hpp b/tests/profiling/gatordmock/PeriodicCounterCaptureCommandHandler.hpp
index 7d6471bf91..b2fd48f4e8 100644
--- a/tests/profiling/gatordmock/PeriodicCounterCaptureCommandHandler.hpp
+++ b/tests/profiling/gatordmock/PeriodicCounterCaptureCommandHandler.hpp
@@ -7,6 +7,7 @@
#include <Packet.hpp>
#include <CommandHandlerFunctor.hpp>
+#include "../../armnn/src/profiling/Packet.hpp"
#include <vector>
@@ -27,11 +28,15 @@ class PeriodicCounterCaptureCommandHandler : public profiling::CommandHandlerFun
{
public:
- PeriodicCounterCaptureCommandHandler(uint32_t packetId,
- uint32_t version,
- bool echoPackets)
+ /**
+ *
+ * @param packetId The id of packets this handler will process.
+ * @param version The version of that id.
+ * @param quietOperation Optional parameter to turn off printouts. This is useful for unittests.
+ */
+ PeriodicCounterCaptureCommandHandler(uint32_t packetId, uint32_t version, bool quietOperation = false)
: CommandHandlerFunctor(packetId, version)
- , m_EchoPackets(echoPackets)
+ , m_QuietOperation(quietOperation)
{}
void operator()(const armnn::profiling::Packet& packet) override;
@@ -46,9 +51,9 @@ private:
uint64_t m_FirstTimestamp = 0, m_SecondTimestamp = 0;
bool m_HeaderPrinted = false;
- bool m_EchoPackets;
+ bool m_QuietOperation;
};
-} // namespace gatordmock
+} // namespace gatordmock
-} // namespace armnn
+} // namespace armnn
diff --git a/tests/profiling/gatordmock/PeriodicCounterSelectionResponseHandler.cpp b/tests/profiling/gatordmock/PeriodicCounterSelectionResponseHandler.cpp
new file mode 100644
index 0000000000..645b0b3507
--- /dev/null
+++ b/tests/profiling/gatordmock/PeriodicCounterSelectionResponseHandler.cpp
@@ -0,0 +1,37 @@
+//
+// Copyright © 2019 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include "PeriodicCounterSelectionResponseHandler.hpp"
+
+#include "../../../src/profiling/ProfilingUtils.hpp"
+
+#include <iostream>
+
+namespace armnn
+{
+
+namespace gatordmock
+{
+
+void PeriodicCounterSelectionResponseHandler::operator()(const profiling::Packet& packet)
+{
+ if (!m_QuietOperation) // Are we supposed to print to stdout?
+ {
+ uint32_t period = profiling::ReadUint32(reinterpret_cast<const unsigned char*>(packet.GetData()), 0);
+ uint32_t numCounters = 0;
+ // First check if there are any counters mentioned.
+ if(packet.GetLength() > 4)
+ {
+ // Length will be 4 bytes for the period and then a list of 16 bit UIDS.
+ numCounters = ((packet.GetLength() - 4) / 2);
+ }
+ std::cout << "PeriodicCounterSelectionResponse: Collection interval = " << std::dec << period << "uSec"
+ << " Num counters activated = " << numCounters << std::endl;
+ }
+}
+
+} // namespace gatordmock
+
+} // namespace armnn \ No newline at end of file
diff --git a/tests/profiling/gatordmock/PeriodicCounterSelectionResponseHandler.hpp b/tests/profiling/gatordmock/PeriodicCounterSelectionResponseHandler.hpp
new file mode 100644
index 0000000000..e1172e2d68
--- /dev/null
+++ b/tests/profiling/gatordmock/PeriodicCounterSelectionResponseHandler.hpp
@@ -0,0 +1,42 @@
+//
+// Copyright © 2019 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include "../../armnn/src/profiling/CommandHandlerFunctor.hpp"
+#include "../../armnn/src/profiling/Packet.hpp"
+
+#include <vector>
+
+namespace armnn
+{
+
+namespace gatordmock
+{
+
+#pragma once
+
+class PeriodicCounterSelectionResponseHandler : public profiling::CommandHandlerFunctor
+{
+
+public:
+ /**
+ *
+ * @param packetId The id of packets this handler will process.
+ * @param version The version of that id.
+ * @param quietOperation Optional parameter to turn off printouts. This is useful for unittests.
+ */
+ PeriodicCounterSelectionResponseHandler(uint32_t packetId, uint32_t version, bool quietOperation = true)
+ : CommandHandlerFunctor(packetId, version)
+ , m_QuietOperation(quietOperation)
+ {}
+
+ void operator()(const armnn::profiling::Packet& packet) override;
+
+private:
+ bool m_QuietOperation;
+};
+
+} // namespace gatordmock
+
+} // namespace armnn \ No newline at end of file
diff --git a/tests/profiling/gatordmock/tests/GatordMockTests.cpp b/tests/profiling/gatordmock/tests/GatordMockTests.cpp
index a6297e94b8..3f58f39124 100644
--- a/tests/profiling/gatordmock/tests/GatordMockTests.cpp
+++ b/tests/profiling/gatordmock/tests/GatordMockTests.cpp
@@ -4,7 +4,6 @@
//
#include "../GatordMockService.hpp"
-#include "../MockUtils.hpp"
#include "../PeriodicCounterCaptureCommandHandler.hpp"
#include <CommandHandlerRegistry.hpp>
@@ -25,12 +24,22 @@ using namespace std::chrono_literals;
// Required so build succeeds when local variable used only in assert
#define _unused(x) ((void)(x))
+uint32_t ConstructHeader(uint32_t packetFamily, uint32_t packetClass, uint32_t packetType)
+{
+ return ((packetFamily & 0x3F) << 26) | ((packetClass & 0x3FF) << 19) | ((packetType & 0x3FFF) << 16);
+}
+
+uint32_t ConstructHeader(uint32_t packetFamily, uint32_t packetId)
+{
+ return ((packetFamily & 0x3F) << 26) | ((packetId & 0x3FF) << 16);
+}
+
BOOST_AUTO_TEST_CASE(CounterCaptureHandlingTest)
{
using boost::numeric_cast;
// Initialise functors and register into the CommandHandlerRegistry
- uint32_t headerWord1 = gatordmock::ConstructHeader(1, 0, 0);
+ uint32_t headerWord1 = ConstructHeader(1, 0, 0);
// Create the Command Handler Registry
profiling::CommandHandlerRegistry registry;
@@ -56,10 +65,10 @@ BOOST_AUTO_TEST_CASE(CounterCaptureHandlingTest)
// UniqueData required for Packet class
std::unique_ptr<unsigned char[]> uniqueData1 = std::make_unique<unsigned char[]>(dataLength);
- unsigned char* data1 = reinterpret_cast<unsigned char*>(uniqueData1.get());
+ unsigned char* data1 = reinterpret_cast<unsigned char*>(uniqueData1.get());
std::unique_ptr<unsigned char[]> uniqueData2 = std::make_unique<unsigned char[]>(dataLength);
- unsigned char* data2 = reinterpret_cast<unsigned char*>(uniqueData2.get());
+ unsigned char* data2 = reinterpret_cast<unsigned char*>(uniqueData2.get());
uint32_t sizeOfUint64 = numeric_cast<uint32_t>(sizeof(uint64_t));
uint32_t sizeOfUint32 = numeric_cast<uint32_t>(sizeof(uint32_t));
@@ -94,7 +103,7 @@ BOOST_AUTO_TEST_CASE(CounterCaptureHandlingTest)
profiling::Packet packet2(headerWord1, dataLength, uniqueData2);
uint32_t version = 1;
- gatordmock::PeriodicCounterCaptureCommandHandler commandHandler(headerWord1, version, false);
+ gatordmock::PeriodicCounterCaptureCommandHandler commandHandler(headerWord1, version, true);
// Simulate two separate packets coming in to calculate period
commandHandler(packet1);
@@ -114,14 +123,14 @@ BOOST_AUTO_TEST_CASE(GatorDMockEndToEnd)
// performance data.
// Initialise functors and register into the CommandHandlerRegistry
- uint32_t counterCaptureHeader = gatordmock::ConstructHeader(1, 0);
+ uint32_t counterCaptureHeader = ConstructHeader(1, 0);
uint32_t version = 1;
// Create the Command Handler Registry
profiling::CommandHandlerRegistry registry;
// Update with derived functors
- gatordmock::PeriodicCounterCaptureCommandHandler counterCaptureCommandHandler(counterCaptureHeader, version, false);
+ gatordmock::PeriodicCounterCaptureCommandHandler counterCaptureCommandHandler(counterCaptureHeader, version, true);
// Register different derived functors
registry.RegisterFunctor(&counterCaptureCommandHandler);