diff options
author | Matteo Martincigh <matteo.martincigh@arm.com> | 2019-10-10 14:08:21 +0100 |
---|---|---|
committer | Matteo Martincigh <matteo.martincigh@arm.com> | 2019-10-11 16:33:29 +0100 |
commit | e848538efbdf01aa0b067da942c3c214f8e62826 (patch) | |
tree | d700239f1316a098849fcfc39ec70e926f86fd62 /src/profiling/PeriodicCounterCapture.cpp | |
parent | f982deaefbe5fe5814487b27f7099829839b8666 (diff) | |
download | armnn-e848538efbdf01aa0b067da942c3c214f8e62826.tar.gz |
IVGCVSW-3964 Implement the Periodic Counter Selection command handler
* Improved the PeriodicCounterPacket class to handle errors properly
* Improved the PeriodicCounterSelectionCommandHandler to handle
invalid counter UIDs in the selection packet
* Added the Periodic Counter Selection command handler to the
ProfilingService class
* Code refactoring and added comments
* Added WaitForPacketSent method to the SendCounterPacket class
to allow waiting for the packets to be sent (useful in the
unit tests)
* Added unit tests and updated the old ones accordingly
* Fixed threading issues with a number of unit tests
Signed-off-by: Matteo Martincigh <matteo.martincigh@arm.com>
Change-Id: I271b7b0bfa801d88fe1725b934d24e30cd839ed7
Diffstat (limited to 'src/profiling/PeriodicCounterCapture.cpp')
-rw-r--r-- | src/profiling/PeriodicCounterCapture.cpp | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/src/profiling/PeriodicCounterCapture.cpp b/src/profiling/PeriodicCounterCapture.cpp index 9002bfc065..0ccb516ae2 100644 --- a/src/profiling/PeriodicCounterCapture.cpp +++ b/src/profiling/PeriodicCounterCapture.cpp @@ -5,6 +5,8 @@ #include "PeriodicCounterCapture.hpp" +#include <boost/log/trivial.hpp> + namespace armnn { @@ -34,10 +36,13 @@ void PeriodicCounterCapture::Start() void PeriodicCounterCapture::Stop() { + // Signal the capture thread to stop m_KeepRunning.store(false); + // Check that the capture thread is running if (m_PeriodCaptureThread.joinable()) { + // Wait for the capture thread to complete operations m_PeriodCaptureThread.join(); } } @@ -51,10 +56,12 @@ void PeriodicCounterCapture::Capture(const IReadCounterValues& readCounterValues { while (m_KeepRunning.load()) { + // Check if the current capture data indicates that there's data capture auto currentCaptureData = ReadCaptureData(); - std::vector<uint16_t> counterIds = currentCaptureData.GetCounterIds(); + const std::vector<uint16_t>& counterIds = currentCaptureData.GetCounterIds(); if (currentCaptureData.GetCapturePeriod() == 0 || counterIds.empty()) { + // No data capture, terminate the thread m_KeepRunning.store(false); break; } @@ -63,12 +70,22 @@ void PeriodicCounterCapture::Capture(const IReadCounterValues& readCounterValues auto numCounters = counterIds.size(); values.reserve(numCounters); - // Create vector of pairs of CounterIndexes and Values - uint32_t counterValue = 0; + // Create a vector of pairs of CounterIndexes and Values for (uint16_t index = 0; index < numCounters; ++index) { auto requestedId = counterIds[index]; - counterValue = readCounterValues.GetCounterValue(requestedId); + uint32_t counterValue = 0; + try + { + counterValue = readCounterValues.GetCounterValue(requestedId); + } + catch (const Exception& e) + { + // Report the error and continue + BOOST_LOG_TRIVIAL(warning) << "An error has occurred when getting a counter value: " + << e.what() << std::endl; + continue; + } values.emplace_back(std::make_pair(requestedId, counterValue)); } @@ -81,9 +98,15 @@ void PeriodicCounterCapture::Capture(const IReadCounterValues& readCounterValues // Take a timestamp auto timestamp = clock::now(); + // Write a Periodic Counter Capture packet to the Counter Stream Buffer m_SendCounterPacket.SendPeriodicCounterCapturePacket( static_cast<uint64_t>(timestamp.time_since_epoch().count()), values); - std::this_thread::sleep_for(std::chrono::milliseconds(currentCaptureData.GetCapturePeriod())); + + // Notify the Send Thread that new data is available in the Counter Stream Buffer + m_SendCounterPacket.SetReadyToRead(); + + // Wait the indicated capture period (microseconds) + std::this_thread::sleep_for(std::chrono::microseconds(currentCaptureData.GetCapturePeriod())); } m_IsRunning.store(false); |