aboutsummaryrefslogtreecommitdiff
path: root/src/profiling/SendCounterPacket.hpp
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.hpp
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.hpp')
-rw-r--r--src/profiling/SendCounterPacket.hpp31
1 files changed, 25 insertions, 6 deletions
diff --git a/src/profiling/SendCounterPacket.hpp b/src/profiling/SendCounterPacket.hpp
index 2a2d5d4313..8dd44ecd81 100644
--- a/src/profiling/SendCounterPacket.hpp
+++ b/src/profiling/SendCounterPacket.hpp
@@ -7,7 +7,13 @@
#include "IBufferWrapper.hpp"
#include "ISendCounterPacket.hpp"
-#include "CounterDirectory.hpp"
+#include "ICounterDirectory.hpp"
+#include "IProfilingConnection.hpp"
+
+#include <atomic>
+#include <mutex>
+#include <thread>
+#include <condition_variable>
namespace armnn
{
@@ -25,10 +31,13 @@ public:
using IndexValuePairsVector = std::vector<std::pair<uint16_t, uint32_t>>;
- SendCounterPacket(IBufferWrapper& buffer)
- : m_Buffer(buffer),
- m_ReadyToRead(false)
+ SendCounterPacket(IProfilingConnection& profilingConnection, IBufferWrapper& buffer)
+ : m_ProfilingConnection(profilingConnection)
+ , m_Buffer(buffer)
+ , m_IsRunning(false)
+ , m_KeepRunning(false)
{}
+ ~SendCounterPacket() { Stop(); }
void SendStreamMetaDataPacket() override;
@@ -44,7 +53,13 @@ public:
static const unsigned int PIPE_MAGIC = 0x45495434;
static const unsigned int MAX_METADATA_PACKET_LENGTH = 4096;
+ void Start();
+ void Stop();
+ bool IsRunning() { return m_IsRunning.load(); }
+
private:
+ void Send();
+
template <typename ExceptionType>
void CancelOperationAndThrow(const std::string& errorMessage)
{
@@ -55,8 +70,13 @@ private:
throw ExceptionType(errorMessage);
}
+ IProfilingConnection& m_ProfilingConnection;
IBufferWrapper& m_Buffer;
- bool m_ReadyToRead;
+ std::mutex m_WaitMutex;
+ std::condition_variable m_WaitCondition;
+ std::thread m_SendThread;
+ std::atomic<bool> m_IsRunning;
+ std::atomic<bool> m_KeepRunning;
protected:
// Helper methods, protected for testing
@@ -78,4 +98,3 @@ protected:
} // namespace profiling
} // namespace armnn
-