aboutsummaryrefslogtreecommitdiff
path: root/src/profiling/SocketProfilingConnection.cpp
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/profiling/SocketProfilingConnection.cpp
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/profiling/SocketProfilingConnection.cpp')
-rw-r--r--src/profiling/SocketProfilingConnection.cpp77
1 files changed, 77 insertions, 0 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