From 5d737fb3b06c17ff6b65fb307343ca1c0c680401 Mon Sep 17 00:00:00 2001 From: Matteo Martincigh Date: Mon, 7 Oct 2019 13:05:13 +0100 Subject: IVGCVSW-3937 Update the Send thread to send out the Metadata packet * The Send thread now automatically sends out Stream Metadata packets when the Profiling Service is in WaitingForAck state * Added a reference to the profiling state in the SendCounterPacket class * Moving the RuntimeException thrown in the Send thread to the main thread for rethrowing * The Stop method now rethrows the exception occurred in the send thread * The Stop method does not rethrow when destructing the object * Added unit tests Signed-off-by: Matteo Martincigh Change-Id: Ice7080bff63199eac84fc4fa1d37fb1a6fcdff89 --- src/profiling/SendCounterPacket.hpp | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'src/profiling/SendCounterPacket.hpp') diff --git a/src/profiling/SendCounterPacket.hpp b/src/profiling/SendCounterPacket.hpp index ed76937cc3..9361efbc74 100644 --- a/src/profiling/SendCounterPacket.hpp +++ b/src/profiling/SendCounterPacket.hpp @@ -6,9 +6,10 @@ #pragma once #include "IBufferManager.hpp" -#include "ISendCounterPacket.hpp" #include "ICounterDirectory.hpp" +#include "ISendCounterPacket.hpp" #include "IProfilingConnection.hpp" +#include "ProfilingStateMachine.hpp" #include "ProfilingUtils.hpp" #include @@ -26,20 +27,25 @@ namespace profiling class SendCounterPacket : public ISendCounterPacket { public: - using CategoryRecord = std::vector; - using DeviceRecord = std::vector; - using CounterSetRecord = std::vector; - using EventRecord = std::vector; - + using CategoryRecord = std::vector; + using DeviceRecord = std::vector; + using CounterSetRecord = std::vector; + using EventRecord = std::vector; using IndexValuePairsVector = std::vector>; - SendCounterPacket(IBufferManager& buffer, int timeout = 1000) - : m_BufferManager(buffer) + SendCounterPacket(ProfilingStateMachine& profilingStateMachine, IBufferManager& buffer, int timeout = 1000) + : m_StateMachine(profilingStateMachine) + , m_BufferManager(buffer) , m_Timeout(timeout) , m_IsRunning(false) , m_KeepRunning(false) + , m_SendThreadException(nullptr) {} - ~SendCounterPacket() { Stop(); } + ~SendCounterPacket() + { + // Don't rethrow when destructing the object + Stop(false); + } void SendStreamMetaDataPacket() override; @@ -56,7 +62,7 @@ public: static const unsigned int MAX_METADATA_PACKET_LENGTH = 4096; void Start(IProfilingConnection& profilingConnection); - void Stop(); + void Stop(bool rethrowSendThreadExceptions = true); bool IsRunning() { return m_IsRunning.load(); } private: @@ -76,6 +82,7 @@ private: { SetReadyToRead(); } + if (writerBuffer != nullptr) { // Cancel the operation @@ -88,6 +95,7 @@ private: void FlushBuffer(IProfilingConnection& profilingConnection); + ProfilingStateMachine& m_StateMachine; IBufferManager& m_BufferManager; int m_Timeout; std::mutex m_WaitMutex; @@ -95,6 +103,7 @@ private: std::thread m_SendThread; std::atomic m_IsRunning; std::atomic m_KeepRunning; + std::exception_ptr m_SendThreadException; protected: // Helper methods, protected for testing -- cgit v1.2.1