Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2019 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "PeriodicCounterSelectionCommandHandler.hpp" |
| 7 | #include "ProfilingUtils.hpp" |
| 8 | |
| 9 | #include <boost/numeric/conversion/cast.hpp> |
| 10 | |
| 11 | namespace armnn |
| 12 | { |
| 13 | |
| 14 | namespace profiling |
| 15 | { |
| 16 | |
| 17 | using namespace std; |
| 18 | using boost::numeric_cast; |
| 19 | |
| 20 | void PeriodicCounterSelectionCommandHandler::ParseData(const Packet& packet, CaptureData& captureData) |
| 21 | { |
| 22 | std::vector<uint16_t> counterIds; |
| 23 | uint32_t sizeOfUint32 = numeric_cast<uint32_t>(sizeof(uint32_t)); |
| 24 | uint32_t sizeOfUint16 = numeric_cast<uint32_t>(sizeof(uint16_t)); |
| 25 | uint32_t offset = 0; |
| 26 | |
| 27 | if (packet.GetLength() > 0) |
| 28 | { |
| 29 | if (packet.GetLength() >= 4) |
| 30 | { |
| 31 | captureData.SetCapturePeriod(ReadUint32(reinterpret_cast<const unsigned char*>(packet.GetData()), offset)); |
| 32 | |
| 33 | unsigned int counters = (packet.GetLength() - 4) / 2; |
| 34 | |
| 35 | if (counters > 0) |
| 36 | { |
| 37 | counterIds.reserve(counters); |
| 38 | offset += sizeOfUint32; |
| 39 | for(unsigned int pos = 0; pos < counters; ++pos) |
| 40 | { |
| 41 | counterIds.emplace_back(ReadUint16(reinterpret_cast<const unsigned char*>(packet.GetData()), |
| 42 | offset)); |
| 43 | offset += sizeOfUint16; |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | captureData.SetCounterIds(counterIds); |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | void PeriodicCounterSelectionCommandHandler::operator()(const Packet& packet) |
| 53 | { |
| 54 | CaptureData captureData; |
| 55 | |
| 56 | ParseData(packet, captureData); |
| 57 | |
| 58 | vector<uint16_t> counterIds = captureData.GetCounterIds(); |
| 59 | |
| 60 | m_CaptureDataHolder.SetCaptureData(captureData.GetCapturePeriod(), counterIds); |
| 61 | |
| 62 | m_CaptureThread.Start(); |
| 63 | |
| 64 | // Write packet to Counter Stream Buffer |
| 65 | m_SendCounterPacket.SendPeriodicCounterSelectionPacket(captureData.GetCapturePeriod(), captureData.GetCounterIds()); |
| 66 | } |
| 67 | |
| 68 | } // namespace profiling |
| 69 | |
| 70 | } // namespace armnn |