aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTeresa Charlin <teresa.charlinreyes@arm.com>2019-09-06 12:28:35 +0100
committerTeresa Charlin <teresa.charlinreyes@arm.com>2019-09-12 12:39:49 +0000
commit9bab49686a091d61fd06a05bbf7286f559fdae3d (patch)
tree9a56bcbc3268c4f4792583aaccbdff4af688d4d3 /src
parent0280785b00cd84f14249d3545a15b93627acf57b (diff)
downloadarmnn-9bab49686a091d61fd06a05bbf7286f559fdae3d.tar.gz
IVGCVSW-3580: Extend the IProfilingConnection to connect to a Socket
Signed-off-by: Teresa Charlin <teresa.charlinreyes@arm.com> Signed-off-by: Aron Virginas-Tar <aron.virginas-tar@arm.com> Change-Id: I72e099ee00052f7a0907c055c7bff02c7d8fde86
Diffstat (limited to 'src')
-rw-r--r--src/profiling/SocketProfilingConnection.cpp77
-rw-r--r--src/profiling/SocketProfilingConnection.hpp33
-rw-r--r--src/profiling/test/ProfilingTests.cpp11
3 files changed, 120 insertions, 1 deletions
diff --git a/src/profiling/SocketProfilingConnection.cpp b/src/profiling/SocketProfilingConnection.cpp
new file mode 100644
index 0000000000..21a7a1d53c
--- /dev/null
+++ b/src/profiling/SocketProfilingConnection.cpp
@@ -0,0 +1,77 @@
+//
+// Copyright © 2019 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include "SocketProfilingConnection.hpp"
+
+#include <fcntl.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <cerrno>
+#include <string>
+
+namespace armnn
+{
+namespace profiling
+{
+
+SocketProfilingConnection::SocketProfilingConnection()
+{
+ memset(m_Socket, 0, sizeof(m_Socket));
+ // Note: we're using Linux specific SOCK_CLOEXEC flag.
+ m_Socket[0].fd = socket(PF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
+ if (m_Socket[0].fd == -1)
+ {
+ throw armnn::Exception(std::string(": Socket construction failed: ") + strerror(errno));
+ }
+
+ // Connect to the named unix domain socket.
+ struct sockaddr_un server{};
+ memset(&server, 0, sizeof(sockaddr_un));
+ // As m_GatorNamespace begins with a null character we need to ignore that when getting its length.
+ memcpy(server.sun_path, m_GatorNamespace, strlen(m_GatorNamespace + 1) + 1);
+ server.sun_family = AF_UNIX;
+ if (0 != connect(m_Socket[0].fd, reinterpret_cast<const sockaddr*>(&server), sizeof(sockaddr_un)))
+ {
+ close(m_Socket[0].fd);
+ throw armnn::Exception(std::string(": Cannot connect to stream socket: ") + strerror(errno));
+ }
+
+ // Our socket will only be interested in polling reads.
+ m_Socket[0].events = POLLIN;
+
+ // Make the socket non blocking.
+ const int currentFlags = fcntl(m_Socket[0].fd, F_GETFL);
+ if (0 != fcntl(m_Socket[0].fd, F_SETFL, currentFlags | O_NONBLOCK))
+ {
+ close(m_Socket[0].fd);
+ throw armnn::Exception(std::string(": Failed to set socket as non blocking: ") + strerror(errno));
+ }
+}
+
+bool SocketProfilingConnection::IsOpen()
+{
+ // Dummy return value, function not implemented
+ return true;
+}
+
+void SocketProfilingConnection::Close()
+{
+ // Function not implemented
+}
+
+bool SocketProfilingConnection::WritePacket(const char* buffer, uint32_t length)
+{
+ // Dummy return value, function not implemented
+ return true;
+}
+
+Packet SocketProfilingConnection::ReadPacket(uint32_t timeout)
+{
+ // Dummy return value, function not implemented
+ return {472580096, 0, nullptr};
+}
+
+} // namespace profiling
+} // namespace armnn
diff --git a/src/profiling/SocketProfilingConnection.hpp b/src/profiling/SocketProfilingConnection.hpp
new file mode 100644
index 0000000000..f58e1f4d5d
--- /dev/null
+++ b/src/profiling/SocketProfilingConnection.hpp
@@ -0,0 +1,33 @@
+//
+// Copyright © 2019 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include "IProfilingConnection.hpp"
+
+#include <poll.h>
+#include <Runtime.hpp>
+
+#pragma once
+
+namespace armnn
+{
+namespace profiling
+{
+
+class SocketProfilingConnection : public IProfilingConnection
+{
+public:
+ SocketProfilingConnection();
+ bool IsOpen() final;
+ void Close() final;
+ bool WritePacket(const char* buffer, uint32_t length) final;
+ Packet ReadPacket(uint32_t timeout) final;
+private:
+ // To indicate we want to use an abstract UDS ensure the first character of the address is 0.
+ const char* m_GatorNamespace = "\0gatord_namespace";
+ struct pollfd m_Socket[1]{};
+};
+
+} // namespace profiling
+} // namespace armnn
diff --git a/src/profiling/test/ProfilingTests.cpp b/src/profiling/test/ProfilingTests.cpp
index fe94092c7f..25fae6c478 100644
--- a/src/profiling/test/ProfilingTests.cpp
+++ b/src/profiling/test/ProfilingTests.cpp
@@ -10,9 +10,12 @@
#include "../Holder.hpp"
#include "../Packet.hpp"
#include "../PacketVersionResolver.hpp"
+#include "../ProfilingService.hpp"
#include "../ProfilingStateMachine.hpp"
#include "../ProfilingUtils.hpp"
-#include "../ProfilingService.hpp"
+#include "../SocketProfilingConnection.hpp"
+
+#include <Runtime.hpp>
#include <boost/test/unit_test.hpp>
@@ -528,4 +531,10 @@ BOOST_AUTO_TEST_CASE(GetNextUidTest)
BOOST_TEST(uid1 != uid2);
}
+BOOST_AUTO_TEST_CASE(CheckSocketProfilingConnection)
+{
+ // Check that creating a SocketProfilingConnection results in an exception as the Gator UDS doesn't exist.
+ BOOST_CHECK_THROW(new SocketProfilingConnection(), armnn::Exception);
+}
+
BOOST_AUTO_TEST_SUITE_END()