aboutsummaryrefslogtreecommitdiff
path: root/src/profiling/PeriodicCounterSelectionCommandHandler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/profiling/PeriodicCounterSelectionCommandHandler.cpp')
-rw-r--r--src/profiling/PeriodicCounterSelectionCommandHandler.cpp70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/profiling/PeriodicCounterSelectionCommandHandler.cpp b/src/profiling/PeriodicCounterSelectionCommandHandler.cpp
new file mode 100644
index 0000000000..9be37fcfd2
--- /dev/null
+++ b/src/profiling/PeriodicCounterSelectionCommandHandler.cpp
@@ -0,0 +1,70 @@
+//
+// Copyright © 2019 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include "PeriodicCounterSelectionCommandHandler.hpp"
+#include "ProfilingUtils.hpp"
+
+#include <boost/numeric/conversion/cast.hpp>
+
+namespace armnn
+{
+
+namespace profiling
+{
+
+using namespace std;
+using boost::numeric_cast;
+
+void PeriodicCounterSelectionCommandHandler::ParseData(const Packet& packet, CaptureData& captureData)
+{
+ std::vector<uint16_t> counterIds;
+ uint32_t sizeOfUint32 = numeric_cast<uint32_t>(sizeof(uint32_t));
+ uint32_t sizeOfUint16 = numeric_cast<uint32_t>(sizeof(uint16_t));
+ uint32_t offset = 0;
+
+ if (packet.GetLength() > 0)
+ {
+ if (packet.GetLength() >= 4)
+ {
+ captureData.SetCapturePeriod(ReadUint32(reinterpret_cast<const unsigned char*>(packet.GetData()), offset));
+
+ unsigned int counters = (packet.GetLength() - 4) / 2;
+
+ if (counters > 0)
+ {
+ counterIds.reserve(counters);
+ offset += sizeOfUint32;
+ for(unsigned int pos = 0; pos < counters; ++pos)
+ {
+ counterIds.emplace_back(ReadUint16(reinterpret_cast<const unsigned char*>(packet.GetData()),
+ offset));
+ offset += sizeOfUint16;
+ }
+ }
+
+ captureData.SetCounterIds(counterIds);
+ }
+ }
+}
+
+void PeriodicCounterSelectionCommandHandler::operator()(const Packet& packet)
+{
+ CaptureData captureData;
+
+ ParseData(packet, captureData);
+
+ vector<uint16_t> counterIds = captureData.GetCounterIds();
+
+ m_CaptureDataHolder.SetCaptureData(captureData.GetCapturePeriod(), counterIds);
+
+ m_CaptureThread.Start();
+
+ // Write packet to Counter Stream Buffer
+ m_SendCounterPacket.SendPeriodicCounterSelectionPacket(captureData.GetCapturePeriod(), captureData.GetCounterIds());
+}
+
+} // namespace profiling
+
+} // namespace armnn \ No newline at end of file