aboutsummaryrefslogtreecommitdiff
path: root/src/profiling/SocketProfilingConnection.cpp
diff options
context:
space:
mode:
authorMatteo Martincigh <matteo.martincigh@arm.com>2019-10-15 09:35:29 +0100
committerMatteo Martincigh <matteo.martincigh@arm.com>2019-10-15 15:20:31 +0000
commit8d9590e5510b8ebdc4e0b2b31ce4b653b46fc02a (patch)
tree0521297dae9ebbf4b012df52313abe44d66d4c42 /src/profiling/SocketProfilingConnection.cpp
parent672d06eac5b0842c22f9f219e9b65efcd5883d33 (diff)
downloadarmnn-8d9590e5510b8ebdc4e0b2b31ce4b653b46fc02a.tar.gz
IVGCVSW-3939 Code refactoring and minor fixes
* Fixed value masking in SendPeriodicCounterCapturePacket and updated the pertinent unit tests * Code refactoring and cleanup * Added extra comments to the ProfilingService stop/reset procedure Signed-off-by: Matteo Martincigh <matteo.martincigh@arm.com> Change-Id: Ibaf2fede76e06d5b8ce7258a4820a60e5993559f
Diffstat (limited to 'src/profiling/SocketProfilingConnection.cpp')
-rw-r--r--src/profiling/SocketProfilingConnection.cpp53
1 files changed, 26 insertions, 27 deletions
diff --git a/src/profiling/SocketProfilingConnection.cpp b/src/profiling/SocketProfilingConnection.cpp
index 6f7101b254..2c4ff76dc8 100644
--- a/src/profiling/SocketProfilingConnection.cpp
+++ b/src/profiling/SocketProfilingConnection.cpp
@@ -78,44 +78,42 @@ bool SocketProfilingConnection::WritePacket(const unsigned char* buffer, uint32_
Packet SocketProfilingConnection::ReadPacket(uint32_t timeout)
{
- // Is there currently at least a headers worth of data waiting to be read?
- int bytes_available;
+ // Is there currently at least a header worth of data waiting to be read?
+ int bytes_available = 0;
ioctl(m_Socket[0].fd, FIONREAD, &bytes_available);
if (bytes_available >= 8)
{
// Yes there is. Read it:
return ReceivePacket();
}
- else
- {
- // Poll for data on the socket or until timeout occurs
- int pollResult = poll(m_Socket, 1, static_cast<int>(timeout));
- switch (pollResult)
- {
- case -1: // Error
- throw armnn::RuntimeException(std::string("Read failure from socket: ") + strerror(errno));
+ // Poll for data on the socket or until timeout occurs
+ int pollResult = poll(m_Socket, 1, static_cast<int>(timeout));
- case 0: // Timeout
- throw TimeoutException("Timeout while reading from socket");
+ switch (pollResult)
+ {
+ case -1: // Error
+ throw armnn::RuntimeException(std::string("Read failure from socket: ") + strerror(errno));
- default: // Normal poll return but it could still contain an error signal
+ case 0: // Timeout
+ throw TimeoutException("Timeout while reading from socket");
- // Check if the socket reported an error
- if (m_Socket[0].revents & (POLLNVAL | POLLERR | POLLHUP))
- {
- throw armnn::RuntimeException(std::string("Socket reported an error: ") + strerror(errno));
- }
+ default: // Normal poll return but it could still contain an error signal
- // Check if there is data to read
- if (!(m_Socket[0].revents & (POLLIN)))
- {
- // This is a very odd case. The file descriptor was woken up but no data was written.
- throw armnn::RuntimeException("Poll resulted in : no data to read");
- }
+ // Check if the socket reported an error
+ if (m_Socket[0].revents & (POLLNVAL | POLLERR | POLLHUP))
+ {
+ throw armnn::RuntimeException(std::string("Socket reported an error: ") + strerror(errno));
+ }
- return ReceivePacket();
+ // Check if there is data to read
+ if (!(m_Socket[0].revents & (POLLIN)))
+ {
+ // This is a very odd case. The file descriptor was woken up but no data was written.
+ throw armnn::RuntimeException("Poll resulted in : no data to read");
}
+
+ return ReceivePacket();
}
}
@@ -127,6 +125,7 @@ Packet SocketProfilingConnection::ReceivePacket()
// What do we do here if there's not a valid 8 byte header to read?
throw armnn::RuntimeException("The received packet did not contains a valid MIPE header");
}
+
// stream_metadata_identifier is the first 4 bytes
uint32_t metadataIdentifier = 0;
std::memcpy(&metadataIdentifier, header, sizeof(metadataIdentifier));
@@ -135,10 +134,10 @@ Packet SocketProfilingConnection::ReceivePacket()
uint32_t dataLength = 0;
std::memcpy(&dataLength, header + 4u, sizeof(dataLength));
- std::unique_ptr<unsigned char[]> packetData;
+ std::unique_ptr<unsigned char[]> packetData;
if (dataLength > 0)
{
- packetData = std::make_unique<unsigned char[]>(dataLength);
+ packetData = std::make_unique<unsigned char[]>(dataLength);
ssize_t receivedLength = recv(m_Socket[0].fd, packetData.get(), dataLength, 0);
if (receivedLength < 0)
{