From 032bc74ca4bc6589a33f23db31accddc5b20baaa Mon Sep 17 00:00:00 2001 From: Finn Williams Date: Wed, 12 Feb 2020 11:02:34 +0000 Subject: IVGCVSW-4338 Implement the Activation of Counters in backends Signed-off-by: Finn Williams Change-Id: I4a2465f06e046f78242ff0a246c651638b205498 --- src/profiling/PeriodicCounterCapture.cpp | 86 +++++++++++++++++++++----------- 1 file changed, 57 insertions(+), 29 deletions(-) (limited to 'src/profiling/PeriodicCounterCapture.cpp') diff --git a/src/profiling/PeriodicCounterCapture.cpp b/src/profiling/PeriodicCounterCapture.cpp index d60cbd7d15..b143295bc1 100644 --- a/src/profiling/PeriodicCounterCapture.cpp +++ b/src/profiling/PeriodicCounterCapture.cpp @@ -55,6 +55,24 @@ CaptureData PeriodicCounterCapture::ReadCaptureData() return m_CaptureDataHolder.GetCaptureData(); } +void PeriodicCounterCapture::DispatchPeriodicCounterCapturePacket( + const armnn::BackendId& backendId, const std::vector& timestampValues) +{ + // Report counter values + for (const auto timestampInfo : timestampValues) + { + std::vector backendCounterValues = timestampInfo.counterValues; + for_each(backendCounterValues.begin(), backendCounterValues.end(), [&](CounterValue& backendCounterValue) + { + // translate the counterId to globalCounterId + backendCounterValue.counterId = m_CounterIdMap.GetGlobalId(backendCounterValue.counterId, backendId); + }); + + // Send Periodic Counter Capture Packet for the Timestamp + m_SendCounterPacket.SendPeriodicCounterCapturePacket(timestampInfo.timestamp, backendCounterValues); + } +} + void PeriodicCounterCapture::Capture(const IReadCounterValues& readCounterValues) { do @@ -62,50 +80,60 @@ void PeriodicCounterCapture::Capture(const IReadCounterValues& readCounterValues // Check if the current capture data indicates that there's data capture auto currentCaptureData = ReadCaptureData(); const std::vector& counterIds = currentCaptureData.GetCounterIds(); + const uint32_t capturePeriod = currentCaptureData.GetCapturePeriod(); - if (currentCaptureData.GetCapturePeriod() == 0 || counterIds.empty()) + if (capturePeriod == 0) { - // No data capture, wait the indicated capture period (milliseconds) - std::this_thread::sleep_for(std::chrono::milliseconds(5)); + // No data capture, wait the indicated capture period (milliseconds), if it is not zero + std::this_thread::sleep_for(std::chrono::milliseconds(50u)); continue; } - std::vector> values; - auto numCounters = counterIds.size(); - values.reserve(numCounters); - - // Create a vector of pairs of CounterIndexes and Values - for (uint16_t index = 0; index < numCounters; ++index) + if(counterIds.size() != 0) { - auto requestedId = counterIds[index]; - uint32_t counterValue = 0; - try - { - counterValue = readCounterValues.GetCounterValue(requestedId); - } - catch (const Exception& e) + std::vector counterValues; + + auto numCounters = counterIds.size(); + counterValues.reserve(numCounters); + + // Create a vector of pairs of CounterIndexes and Values + for (uint16_t index = 0; index < numCounters; ++index) { - // Report the error and continue - ARMNN_LOG(warning) << "An error has occurred when getting a counter value: " - << e.what(); - continue; + auto requestedId = counterIds[index]; + uint32_t counterValue = 0; + try + { + counterValue = readCounterValues.GetCounterValue(requestedId); + } + catch (const Exception& e) + { + // Report the error and continue + ARMNN_LOG(warning) << "An error has occurred when getting a counter value: " + << e.what(); + continue; + } + + counterValues.emplace_back(CounterValue {requestedId, counterValue }); } - values.emplace_back(std::make_pair(requestedId, counterValue)); - } - // Take a timestamp - uint64_t timestamp = GetTimestamp(); + // Send Periodic Counter Capture Packet for the Timestamp + m_SendCounterPacket.SendPeriodicCounterCapturePacket(GetTimestamp(), counterValues); + } - // Write a Periodic Counter Capture packet to the Counter Stream Buffer - m_SendCounterPacket.SendPeriodicCounterCapturePacket(timestamp, values); + // Report counter values for each active backend + auto activeBackends = currentCaptureData.GetActiveBackends(); + for_each(activeBackends.begin(), activeBackends.end(), [&](const armnn::BackendId& backendId) + { + DispatchPeriodicCounterCapturePacket( + backendId, m_BackendProfilingContext.at(backendId)->ReportCounterValues()); + }); // Wait the indicated capture period (microseconds) - std::this_thread::sleep_for(std::chrono::microseconds(currentCaptureData.GetCapturePeriod())); - + std::this_thread::sleep_for(std::chrono::microseconds(capturePeriod)); } while (m_KeepRunning.load()); } } // namespace profiling -} // namespace armnn +} // namespace armnn \ No newline at end of file -- cgit v1.2.1