aboutsummaryrefslogtreecommitdiff
path: root/src/profiling/PeriodicCounterCapture.cpp
diff options
context:
space:
mode:
authorMatteo Martincigh <matteo.martincigh@arm.com>2019-10-04 17:17:42 +0100
committerMatteo Martincigh <matteo.martincigh@arm.com>2019-10-07 10:08:58 +0000
commite0e6efc1072358b843f47d2ffffc3d873a4889c6 (patch)
treef328699a6cbce13f0b64d74692ee92be2a22477a /src/profiling/PeriodicCounterCapture.cpp
parent8a837179ad883e9b5dd982a25cc5e94f245f79ed (diff)
downloadarmnn-e0e6efc1072358b843f47d2ffffc3d873a4889c6.tar.gz
IVGCVSW-3937 Refactor and improve the PeriodicCounterCapture class
* Conformed the PeriodicCounterCapture class to the other thread-based classes * Code refactoring * Renamed CounterValues file to ICounterValues * Removed no longer used file * Updated unit tests accordingly Signed-off-by: Matteo Martincigh <matteo.martincigh@arm.com> Change-Id: I8c42aa17e17a90cda5cf86eb8ac2d13501ecdadc
Diffstat (limited to 'src/profiling/PeriodicCounterCapture.cpp')
-rw-r--r--src/profiling/PeriodicCounterCapture.cpp114
1 files changed, 57 insertions, 57 deletions
diff --git a/src/profiling/PeriodicCounterCapture.cpp b/src/profiling/PeriodicCounterCapture.cpp
index 5fbaa5d035..9002bfc065 100644
--- a/src/profiling/PeriodicCounterCapture.cpp
+++ b/src/profiling/PeriodicCounterCapture.cpp
@@ -11,82 +11,82 @@ namespace armnn
namespace profiling
{
-PeriodicCounterCapture::PeriodicCounterCapture(const Holder& data, ISendCounterPacket& packet,
- const IReadCounterValue& readCounterValue)
- : m_CaptureDataHolder(data)
- , m_IsRunning(false)
- , m_ReadCounterValue(readCounterValue)
- , m_SendCounterPacket(packet)
-{}
+void PeriodicCounterCapture::Start()
+{
+ // Check if the capture thread is already running
+ if (m_IsRunning.load())
+ {
+ // The capture thread is already running
+ return;
+ }
+
+ // Mark the capture thread as running
+ m_IsRunning.store(true);
+
+ // Keep the capture procedure going until the capture thread is signalled to stop
+ m_KeepRunning.store(true);
+
+ // Start the new capture thread.
+ m_PeriodCaptureThread = std::thread(&PeriodicCounterCapture::Capture,
+ this,
+ std::ref(m_ReadCounterValues));
+}
+
+void PeriodicCounterCapture::Stop()
+{
+ m_KeepRunning.store(false);
+
+ if (m_PeriodCaptureThread.joinable())
+ {
+ m_PeriodCaptureThread.join();
+ }
+}
CaptureData PeriodicCounterCapture::ReadCaptureData()
{
return m_CaptureDataHolder.GetCaptureData();
}
-void PeriodicCounterCapture::Functionality(const IReadCounterValue& readCounterValue)
+void PeriodicCounterCapture::Capture(const IReadCounterValues& readCounterValues)
{
- bool threadRunning = true;
-
- while(threadRunning)
+ while (m_KeepRunning.load())
{
auto currentCaptureData = ReadCaptureData();
std::vector<uint16_t> counterIds = currentCaptureData.GetCounterIds();
if (currentCaptureData.GetCapturePeriod() == 0 || counterIds.empty())
{
- threadRunning = false;
- m_IsRunning.store(false, std::memory_order_relaxed);
+ m_KeepRunning.store(false);
+ break;
}
- else
- {
- std::vector<std::pair<uint16_t, uint32_t>> values;
- auto numCounters = counterIds.size();
- values.reserve(numCounters);
-
- // Create vector of pairs of CounterIndexes and Values
- uint32_t counterValue;
- for (uint16_t index = 0; index < numCounters; ++index)
- {
- auto requestedId = counterIds[index];
- readCounterValue.GetCounterValue(requestedId, counterValue);
- values.emplace_back(std::make_pair(requestedId, counterValue));
- }
-
- #if USE_CLOCK_MONOTONIC_RAW
- using clock = MonotonicClockRaw;
- #else
- using clock = std::chrono::steady_clock;
- #endif
- // Take a timestamp
- auto timestamp = clock::now();
-
- m_SendCounterPacket.SendPeriodicCounterCapturePacket(
- static_cast<uint64_t>(timestamp.time_since_epoch().count()), values);
- std::this_thread::sleep_for(std::chrono::milliseconds(currentCaptureData.GetCapturePeriod()));
- }
- }
-}
-void PeriodicCounterCapture::Start()
-{
- bool tstVal = false;
+ std::vector<std::pair<uint16_t, uint32_t>> values;
+ auto numCounters = counterIds.size();
+ values.reserve(numCounters);
- if (m_IsRunning.compare_exchange_strong(tstVal, true, std::memory_order_relaxed))
- {
- // Check that the thread execution is finished.
- if (m_PeriodCaptureThread.joinable())
+ // Create vector of pairs of CounterIndexes and Values
+ uint32_t counterValue = 0;
+ for (uint16_t index = 0; index < numCounters; ++index)
{
- m_PeriodCaptureThread.join();
+ auto requestedId = counterIds[index];
+ counterValue = readCounterValues.GetCounterValue(requestedId);
+ values.emplace_back(std::make_pair(requestedId, counterValue));
}
- // Starts the new thread.
- m_PeriodCaptureThread = std::thread(&PeriodicCounterCapture::Functionality, this,
- std::ref(m_ReadCounterValue));
+
+ #if USE_CLOCK_MONOTONIC_RAW
+ using clock = MonotonicClockRaw;
+ #else
+ using clock = std::chrono::steady_clock;
+ #endif
+
+ // Take a timestamp
+ auto timestamp = clock::now();
+
+ m_SendCounterPacket.SendPeriodicCounterCapturePacket(
+ static_cast<uint64_t>(timestamp.time_since_epoch().count()), values);
+ std::this_thread::sleep_for(std::chrono::milliseconds(currentCaptureData.GetCapturePeriod()));
}
-}
-void PeriodicCounterCapture::Join()
-{
- m_PeriodCaptureThread.join();
+ m_IsRunning.store(false);
}
} // namespace profiling