aboutsummaryrefslogtreecommitdiff
path: root/src/profiling/SendCounterPacket.cpp
diff options
context:
space:
mode:
authorMatteo Martincigh <matteo.martincigh@arm.com>2019-09-19 11:57:46 +0100
committerNarumol Prangnawarat <narumol.prangnawarat@arm.com>2019-09-25 12:01:22 +0100
commit24e8f9209249c9d41e57748a1b9d2f5f978db4ee (patch)
tree8b5cd94a7196e1c5cf88dfa79e61569d36119caf /src/profiling/SendCounterPacket.cpp
parentf6e534a82d167403c5980e3ea3b67135ff9be78b (diff)
downloadarmnn-24e8f9209249c9d41e57748a1b9d2f5f978db4ee.tar.gz
IVGCVSW-3905 Create a first implementation of the send thread
* Added the send thread directly to the SendCounterPacket class * Updated the SendCounterPacket class constructor to also take a reference of a IProfilingConnection object, used to send packets out * Added Start and Stop methods to SendCounterPacket to start and stop the send thread * Added mutex and wait condition to make the send thread waiting for something to send * This implementation used the old IBufferWrapper interface * Added defult (empty) constructor for the Packet class * Refactoring of IPeriodicCounterCapture and SocketProfilingConnection * Modified WritePacket to make it match IBufferWrapper::GetReadBuffer * Added unit test for regular and stress testing of the send thread Signed-off-by: Matteo Martincigh <matteo.martincigh@arm.com> Change-Id: I8175619ff4e65c0d5be99bcd8bd9d8dd87f717c6
Diffstat (limited to 'src/profiling/SendCounterPacket.cpp')
-rw-r--r--src/profiling/SendCounterPacket.cpp74
1 files changed, 73 insertions, 1 deletions
diff --git a/src/profiling/SendCounterPacket.cpp b/src/profiling/SendCounterPacket.cpp
index b41f53ca24..b222270546 100644
--- a/src/profiling/SendCounterPacket.cpp
+++ b/src/profiling/SendCounterPacket.cpp
@@ -919,7 +919,79 @@ void SendCounterPacket::SendPeriodicCounterSelectionPacket(uint32_t capturePerio
void SendCounterPacket::SetReadyToRead()
{
- m_ReadyToRead = true;
+ // Signal the send thread that there's something to read in the buffer
+ m_WaitCondition.notify_one();
+}
+
+void SendCounterPacket::Start()
+{
+ // Check is the send thread is already running
+ if (m_IsRunning.load())
+ {
+ // The send thread is already running
+ return;
+ }
+
+ // Mark the send thread as running
+ m_IsRunning.store(true);
+
+ // Keep the send procedure going until the the send thread is signalled to stop
+ m_KeepRunning.store(true);
+
+ // Start the send thread
+ m_SendThread = std::thread(&SendCounterPacket::Send, this);
+}
+
+void SendCounterPacket::Stop()
+{
+ // Signal the send thread to stop
+ m_KeepRunning.store(false);
+
+ // Check that the send thread is running
+ if (m_SendThread.joinable())
+ {
+ // Kick the send thread out of the wait condition
+ m_WaitCondition.notify_one();
+
+ // Wait for the send thread to complete operations
+ m_SendThread.join();
+ }
+}
+
+void SendCounterPacket::Send()
+{
+ // Keep the sending procedure looping until the thread is signalled to stop
+ while (m_KeepRunning.load())
+ {
+ // Wait condition lock scope - Begin
+ {
+ // Lock the mutex to wait on it
+ std::unique_lock<std::mutex> lock(m_WaitMutex);
+
+ // Wait until the thread is notified of something to read from the buffer, or check anyway after a second
+ m_WaitCondition.wait_for(lock, std::chrono::seconds(1));
+ }
+ // Wait condition lock scope - End
+
+ // Get the data to send from the buffer
+ unsigned int readBufferSize = 0;
+ const unsigned char* readBuffer = m_Buffer.GetReadBuffer(readBufferSize);
+ if (readBuffer == nullptr || readBufferSize == 0)
+ {
+ // Nothing to send, ignore and continue
+ continue;
+ }
+
+ // Check that the profiling connection is open, silently drop the data and continue if it's closed
+ if (m_ProfilingConnection.IsOpen())
+ {
+ // Write a packet to the profiling connection. Silently ignore any write error and continue
+ m_ProfilingConnection.WritePacket(readBuffer, boost::numeric_cast<uint32_t>(readBufferSize));
+ }
+ }
+
+ // Mark the send thread as not running
+ m_IsRunning.store(false);
}
} // namespace profiling