aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Davis <keith.davis@arm.com>2019-10-17 09:52:50 +0100
committerMatteo Martincigh <matteo.martincigh@arm.com>2019-10-22 08:02:04 +0000
commitb10e08180dc1576fbe0f838a9f0277ab4b3f40f4 (patch)
treebd97c3227a573add7bedd0ded0dc8e688402a95c
parent98d6b3d7e9eef724c6ed64c85c23cd1ad04d7c5a (diff)
downloadarmnn-b10e08180dc1576fbe0f838a9f0277ab4b3f40f4.tar.gz
Fix for bug where ProfilingConnectionDumpToFactory is not used in profiling service
Signed-off-by: Keith Davis <keith.davis@arm.com> Change-Id: I962093766a79fefc8fb91b9bc3d5bd8f28c35114
-rw-r--r--src/profiling/ProfilingConnectionDumpToFileDecorator.cpp28
-rw-r--r--src/profiling/ProfilingConnectionDumpToFileDecorator.hpp36
-rw-r--r--src/profiling/ProfilingConnectionFactory.cpp13
-rw-r--r--src/profiling/test/ProfilingConnectionDumpToFileDecoratorTests.cpp61
4 files changed, 65 insertions, 73 deletions
diff --git a/src/profiling/ProfilingConnectionDumpToFileDecorator.cpp b/src/profiling/ProfilingConnectionDumpToFileDecorator.cpp
index d7915624f6..5a14aa864e 100644
--- a/src/profiling/ProfilingConnectionDumpToFileDecorator.cpp
+++ b/src/profiling/ProfilingConnectionDumpToFileDecorator.cpp
@@ -19,9 +19,11 @@ namespace profiling
ProfilingConnectionDumpToFileDecorator::ProfilingConnectionDumpToFileDecorator(
std::unique_ptr<IProfilingConnection> connection,
- const Settings& settings)
- : m_Connection(std::move(connection))
- , m_Settings(settings)
+ const Runtime::CreationOptions::ExternalProfilingOptions& options,
+ bool ignoreFailures)
+ : m_Connection(std::move(connection))
+ , m_Options(options)
+ , m_IgnoreFileErrors(ignoreFailures)
{
if (!m_Connection)
{
@@ -49,7 +51,7 @@ void ProfilingConnectionDumpToFileDecorator::Close()
bool ProfilingConnectionDumpToFileDecorator::WritePacket(const unsigned char* buffer, uint32_t length)
{
bool success = true;
- if (m_Settings.m_DumpOutgoing)
+ if (!m_Options.m_OutgoingCaptureFile.empty())
{
success &= DumpOutgoingToFile(buffer, length);
}
@@ -60,7 +62,7 @@ bool ProfilingConnectionDumpToFileDecorator::WritePacket(const unsigned char* bu
Packet ProfilingConnectionDumpToFileDecorator::ReadPacket(uint32_t timeout)
{
Packet packet = m_Connection->ReadPacket(timeout);
- if (m_Settings.m_DumpIncoming)
+ if (!m_Options.m_IncomingCaptureFile.empty())
{
DumpIncomingToFile(packet);
}
@@ -69,13 +71,13 @@ Packet ProfilingConnectionDumpToFileDecorator::ReadPacket(uint32_t timeout)
bool ProfilingConnectionDumpToFileDecorator::OpenIncomingDumpFile()
{
- m_IncomingDumpFileStream.open(m_Settings.m_IncomingDumpFileName, std::ios::out | std::ios::binary);
+ m_IncomingDumpFileStream.open(m_Options.m_IncomingCaptureFile, std::ios::out | std::ios::binary);
return m_IncomingDumpFileStream.is_open();
}
bool ProfilingConnectionDumpToFileDecorator::OpenOutgoingDumpFile()
{
- m_OutgoingDumpFileStream.open(m_Settings.m_OutgoingDumpFileName, std::ios::out | std::ios::binary);
+ m_OutgoingDumpFileStream.open(m_Options.m_OutgoingCaptureFile, std::ios::out | std::ios::binary);
return m_OutgoingDumpFileStream.is_open();
}
@@ -93,9 +95,9 @@ void ProfilingConnectionDumpToFileDecorator::DumpIncomingToFile(const Packet& pa
{
// attempt to open dump file
success &= OpenIncomingDumpFile();
- if (!(success || m_Settings.m_IgnoreFileErrors))
+ if (!(success || m_IgnoreFileErrors))
{
- Fail("Failed to open \"" + m_Settings.m_IncomingDumpFileName + "\" for writing");
+ Fail("Failed to open \"" + m_Options.m_IncomingCaptureFile + "\" for writing");
}
}
@@ -109,7 +111,7 @@ void ProfilingConnectionDumpToFileDecorator::DumpIncomingToFile(const Packet& pa
boost::numeric_cast<std::streamsize>(packetLength));
success &= m_IncomingDumpFileStream.good();
- if (!(success || m_Settings.m_IgnoreFileErrors))
+ if (!(success || m_IgnoreFileErrors))
{
Fail("Error writing incoming packet of " + std::to_string(packetLength) + " bytes");
}
@@ -130,9 +132,9 @@ bool ProfilingConnectionDumpToFileDecorator::DumpOutgoingToFile(const unsigned c
{
// attempt to open dump file
success &= OpenOutgoingDumpFile();
- if (!(success || m_Settings.m_IgnoreFileErrors))
+ if (!(success || m_IgnoreFileErrors))
{
- Fail("Failed to open \"" + m_Settings.m_OutgoingDumpFileName + "\" for writing");
+ Fail("Failed to open \"" + m_Options.m_OutgoingCaptureFile + "\" for writing");
}
}
@@ -140,7 +142,7 @@ bool ProfilingConnectionDumpToFileDecorator::DumpOutgoingToFile(const unsigned c
m_OutgoingDumpFileStream.write(reinterpret_cast<const char*>(buffer),
boost::numeric_cast<std::streamsize>(length));
success &= m_OutgoingDumpFileStream.good();
- if (!(success || m_Settings.m_IgnoreFileErrors))
+ if (!(success || m_IgnoreFileErrors))
{
Fail("Error writing outgoing packet of " + std::to_string(length) + " bytes");
}
diff --git a/src/profiling/ProfilingConnectionDumpToFileDecorator.hpp b/src/profiling/ProfilingConnectionDumpToFileDecorator.hpp
index cc79d954d9..450c38a243 100644
--- a/src/profiling/ProfilingConnectionDumpToFileDecorator.hpp
+++ b/src/profiling/ProfilingConnectionDumpToFileDecorator.hpp
@@ -6,7 +6,9 @@
#pragma once
#include "IProfilingConnection.hpp"
+#include "ProfilingUtils.hpp"
+#include <Runtime.hpp>
#include <armnn/Optional.hpp>
#include <fstream>
@@ -23,29 +25,10 @@ namespace profiling
class ProfilingConnectionDumpToFileDecorator : public IProfilingConnection
{
public:
- struct Settings
- {
- Settings(const std::string& incomingDumpFileName = "",
- const std::string& outgoingDumpFileName = "",
- bool ignoreFileErrors = true)
- : m_IncomingDumpFileName(incomingDumpFileName)
- , m_OutgoingDumpFileName(outgoingDumpFileName)
- , m_DumpIncoming(!incomingDumpFileName.empty())
- , m_DumpOutgoing(!outgoingDumpFileName.empty())
- , m_IgnoreFileErrors(ignoreFileErrors)
- {}
-
- ~Settings() = default;
-
- std::string m_IncomingDumpFileName;
- std::string m_OutgoingDumpFileName;
- bool m_DumpIncoming;
- bool m_DumpOutgoing;
- bool m_IgnoreFileErrors;
- };
ProfilingConnectionDumpToFileDecorator(std::unique_ptr<IProfilingConnection> connection,
- const Settings& settings);
+ const Runtime::CreationOptions::ExternalProfilingOptions& options,
+ bool ignoreFailures);
~ProfilingConnectionDumpToFileDecorator();
@@ -68,14 +51,13 @@ private:
void Fail(const std::string& errorMessage);
- std::unique_ptr<IProfilingConnection> m_Connection;
- Settings m_Settings;
- std::ofstream m_IncomingDumpFileStream;
- std::ofstream m_OutgoingDumpFileStream;
+ std::unique_ptr<IProfilingConnection> m_Connection;
+ Runtime::CreationOptions::ExternalProfilingOptions m_Options;
+ std::ofstream m_IncomingDumpFileStream;
+ std::ofstream m_OutgoingDumpFileStream;
+ bool m_IgnoreFileErrors;
};
-using ProfilingConnectionDumpToFileDecoratorSettings = ProfilingConnectionDumpToFileDecorator::Settings;
-
} // namespace profiling
} // namespace armnn
diff --git a/src/profiling/ProfilingConnectionFactory.cpp b/src/profiling/ProfilingConnectionFactory.cpp
index faecea7526..759eb7a95e 100644
--- a/src/profiling/ProfilingConnectionFactory.cpp
+++ b/src/profiling/ProfilingConnectionFactory.cpp
@@ -5,6 +5,7 @@
#include "ProfilingConnectionFactory.hpp"
#include "SocketProfilingConnection.hpp"
+#include "ProfilingConnectionDumpToFileDecorator.hpp"
namespace armnn
{
@@ -15,7 +16,17 @@ namespace profiling
std::unique_ptr<IProfilingConnection> ProfilingConnectionFactory::GetProfilingConnection(
const Runtime::CreationOptions::ExternalProfilingOptions& options) const
{
- return std::make_unique<SocketProfilingConnection>();
+ if ( !options.m_IncomingCaptureFile.empty() || !options.m_OutgoingCaptureFile.empty() )
+ {
+ bool ignoreFailures = false;
+ return std::make_unique<ProfilingConnectionDumpToFileDecorator>(std::make_unique<SocketProfilingConnection>(),
+ options,
+ ignoreFailures);
+ }
+ else
+ {
+ return std::make_unique<SocketProfilingConnection>();
+ }
}
} // namespace profiling
diff --git a/src/profiling/test/ProfilingConnectionDumpToFileDecoratorTests.cpp b/src/profiling/test/ProfilingConnectionDumpToFileDecoratorTests.cpp
index a7acdd63cc..c42891d9bf 100644
--- a/src/profiling/test/ProfilingConnectionDumpToFileDecoratorTests.cpp
+++ b/src/profiling/test/ProfilingConnectionDumpToFileDecoratorTests.cpp
@@ -4,6 +4,7 @@
//
#include "../ProfilingConnectionDumpToFileDecorator.hpp"
+#include <Runtime.hpp>
#include <fstream>
#include <sstream>
@@ -80,36 +81,22 @@ std::vector<char> ReadDumpFile(const std::string& dumpFileName)
BOOST_AUTO_TEST_SUITE(ProfilingConnectionDumpToFileDecoratorTests)
-BOOST_AUTO_TEST_CASE(CheckSettings)
-{
- ProfilingConnectionDumpToFileDecoratorSettings settings0("", "");
- BOOST_CHECK(settings0.m_DumpIncoming == false);
- BOOST_CHECK(settings0.m_DumpOutgoing == false);
-
- ProfilingConnectionDumpToFileDecoratorSettings settings1("incomingDumpFile.dat", "");
- BOOST_CHECK(settings1.m_DumpIncoming == true);
- BOOST_CHECK(settings1.m_DumpOutgoing == false);
-
- ProfilingConnectionDumpToFileDecoratorSettings settings2("", "outgoingDumpFile.dat");
- BOOST_CHECK(settings2.m_DumpIncoming == false);
- BOOST_CHECK(settings2.m_DumpOutgoing == true);
-
- ProfilingConnectionDumpToFileDecoratorSettings settings3("incomingDumpFile.dat", "outgoingDumpFile.dat");
- BOOST_CHECK(settings3.m_DumpIncoming == true);
- BOOST_CHECK(settings3.m_DumpOutgoing == true);
-}
BOOST_AUTO_TEST_CASE(DumpIncomingInvalidFile)
{
- ProfilingConnectionDumpToFileDecoratorSettings settings("/", "", false);
- ProfilingConnectionDumpToFileDecorator decorator(std::make_unique<DummyProfilingConnection>(), settings);
+ armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
+ options.m_IncomingCaptureFile = "/";
+ options.m_OutgoingCaptureFile = "";
+ ProfilingConnectionDumpToFileDecorator decorator(std::make_unique<DummyProfilingConnection>(), options, false);
BOOST_CHECK_THROW(decorator.ReadPacket(0), armnn::RuntimeException);
}
BOOST_AUTO_TEST_CASE(DumpIncomingInvalidFileIgnoreErrors)
{
- ProfilingConnectionDumpToFileDecoratorSettings settings("/", "", true);
- ProfilingConnectionDumpToFileDecorator decorator(std::make_unique<DummyProfilingConnection>(), settings);
+ armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
+ options.m_IncomingCaptureFile = "/";
+ options.m_OutgoingCaptureFile = "";
+ ProfilingConnectionDumpToFileDecorator decorator(std::make_unique<DummyProfilingConnection>(), options, true);
BOOST_CHECK_NO_THROW(decorator.ReadPacket(0));
}
@@ -117,9 +104,11 @@ BOOST_AUTO_TEST_CASE(DumpIncomingValidFile)
{
std::stringstream fileName;
fileName << ARMNN_PROFILING_CONNECTION_TEST_DUMP_DIR << "/test_dump_file_incoming.dat";
+ armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
+ options.m_IncomingCaptureFile = fileName.str();
+ options.m_OutgoingCaptureFile = "";
- ProfilingConnectionDumpToFileDecoratorSettings settings(fileName.str(), "", false);
- ProfilingConnectionDumpToFileDecorator decorator(std::make_unique<DummyProfilingConnection>(), settings);
+ ProfilingConnectionDumpToFileDecorator decorator(std::make_unique<DummyProfilingConnection>(), options, false);
// NOTE: unique_ptr is needed here because operator=() is deleted for Packet
std::unique_ptr<Packet> packet;
@@ -127,7 +116,7 @@ BOOST_AUTO_TEST_CASE(DumpIncomingValidFile)
decorator.Close();
- std::vector<char> data = ReadDumpFile(settings.m_IncomingDumpFileName);
+ std::vector<char> data = ReadDumpFile(options.m_IncomingCaptureFile);
const char* packetData = reinterpret_cast<const char*>(packet->GetData());
// check if the data read back from the dump file matches the original
@@ -138,15 +127,20 @@ BOOST_AUTO_TEST_CASE(DumpIncomingValidFile)
BOOST_AUTO_TEST_CASE(DumpOutgoingInvalidFile)
{
- ProfilingConnectionDumpToFileDecoratorSettings settings("", "/", false);
- ProfilingConnectionDumpToFileDecorator decorator(std::make_unique<DummyProfilingConnection>(), settings);
+ armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
+ options.m_IncomingCaptureFile = "";
+ options.m_OutgoingCaptureFile = "/";
+ ProfilingConnectionDumpToFileDecorator decorator(std::make_unique<DummyProfilingConnection>(), options, false);
BOOST_CHECK_THROW(decorator.WritePacket(g_DataPtr, g_DataLength), armnn::RuntimeException);
}
BOOST_AUTO_TEST_CASE(DumpOutgoingInvalidFileIgnoreErrors)
{
- ProfilingConnectionDumpToFileDecoratorSettings settings("", "/", true);
- ProfilingConnectionDumpToFileDecorator decorator(std::make_unique<DummyProfilingConnection>(), settings);
+ armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
+ options.m_IncomingCaptureFile = "";
+ options.m_OutgoingCaptureFile = "/";
+
+ ProfilingConnectionDumpToFileDecorator decorator(std::make_unique<DummyProfilingConnection>(), options, true);
BOOST_CHECK_NO_THROW(decorator.WritePacket(g_DataPtr, g_DataLength));
bool success = decorator.WritePacket(g_DataPtr, g_DataLength);
@@ -158,8 +152,11 @@ BOOST_AUTO_TEST_CASE(DumpOutgoingValidFile)
std::stringstream fileName;
fileName << ARMNN_PROFILING_CONNECTION_TEST_DUMP_DIR << "/test_dump_file.dat";
- ProfilingConnectionDumpToFileDecoratorSettings settings("", fileName.str(), false);
- ProfilingConnectionDumpToFileDecorator decorator(std::make_unique<DummyProfilingConnection>(), settings);
+ armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
+ options.m_IncomingCaptureFile = "";
+ options.m_OutgoingCaptureFile = fileName.str();
+
+ ProfilingConnectionDumpToFileDecorator decorator(std::make_unique<DummyProfilingConnection>(), options, false);
bool success = false;
BOOST_CHECK_NO_THROW(success = decorator.WritePacket(g_DataPtr, g_DataLength));
@@ -167,7 +164,7 @@ BOOST_AUTO_TEST_CASE(DumpOutgoingValidFile)
decorator.Close();
- std::vector<char> data = ReadDumpFile(settings.m_OutgoingDumpFileName);
+ std::vector<char> data = ReadDumpFile(options.m_OutgoingCaptureFile);
// check if the data read back from the dump file matches the original
int diff = std::strncmp(data.data(), g_Data.data(), g_DataLength);