diff options
author | Finn Williams <Finn.Williams@arm.com> | 2019-10-14 15:55:18 +0100 |
---|---|---|
committer | Jim Flynn Arm <jim.flynn@arm.com> | 2019-10-15 09:22:03 +0000 |
commit | f4d59a678d8ef8420f52d341bb60f1a583269e24 (patch) | |
tree | 5a36aec70269d0194440aa3224b2187c86bf8c5b /src/profiling/PeriodicCounterCapture.cpp | |
parent | 91e1de786ddeee7fcd702a756ef47a475ff1bd46 (diff) | |
download | armnn-f4d59a678d8ef8420f52d341bb60f1a583269e24.tar.gz |
IVGCVSW-3984 Fix CheckPeriodicCounterCaptureThread
* PerodicCounterCapture now sleeps instead of terminating
when reading empty counter data
* m_IsRunning is now set to false after the thread is joined and
is no longer atomic
* removed usages of find() (not thread safe)
Signed-off-by: Finn Williams <Finn.Williams@arm.com>
Change-Id: Ie65d5a9a7e42a31653ec8eed064849355661ef56
Diffstat (limited to 'src/profiling/PeriodicCounterCapture.cpp')
-rw-r--r-- | src/profiling/PeriodicCounterCapture.cpp | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/src/profiling/PeriodicCounterCapture.cpp b/src/profiling/PeriodicCounterCapture.cpp index 0ccb516ae2..5ba1318a77 100644 --- a/src/profiling/PeriodicCounterCapture.cpp +++ b/src/profiling/PeriodicCounterCapture.cpp @@ -6,6 +6,7 @@ #include "PeriodicCounterCapture.hpp" #include <boost/log/trivial.hpp> +#include <iostream> namespace armnn { @@ -16,14 +17,14 @@ namespace profiling void PeriodicCounterCapture::Start() { // Check if the capture thread is already running - if (m_IsRunning.load()) + if (m_IsRunning) { // The capture thread is already running return; } // Mark the capture thread as running - m_IsRunning.store(true); + m_IsRunning = true; // Keep the capture procedure going until the capture thread is signalled to stop m_KeepRunning.store(true); @@ -45,6 +46,8 @@ void PeriodicCounterCapture::Stop() // Wait for the capture thread to complete operations m_PeriodCaptureThread.join(); } + + m_IsRunning = false; } CaptureData PeriodicCounterCapture::ReadCaptureData() @@ -54,16 +57,17 @@ CaptureData PeriodicCounterCapture::ReadCaptureData() void PeriodicCounterCapture::Capture(const IReadCounterValues& readCounterValues) { - while (m_KeepRunning.load()) + do { // Check if the current capture data indicates that there's data capture auto currentCaptureData = ReadCaptureData(); 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; + // No data capture, wait the indicated capture period (milliseconds) + std::this_thread::sleep_for(std::chrono::milliseconds(5)); + continue; } std::vector<std::pair<uint16_t, uint32_t>> values; @@ -107,9 +111,10 @@ void PeriodicCounterCapture::Capture(const IReadCounterValues& readCounterValues // Wait the indicated capture period (microseconds) std::this_thread::sleep_for(std::chrono::microseconds(currentCaptureData.GetCapturePeriod())); + } + while (m_KeepRunning.load()); - m_IsRunning.store(false); } } // namespace profiling |