Jim Flynn | 01d0281 | 2020-04-29 21:12:13 +0100 | [diff] [blame] | 1 | // |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame^] | 2 | // Copyright © 2020 Arm Ltd and Contributors. All rights reserved. |
Jim Flynn | 01d0281 | 2020-04-29 21:12:13 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "RequestCountersPacketHandler.hpp" |
| 7 | |
| 8 | #include "DirectoryCaptureCommandHandler.hpp" |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame^] | 9 | #include <common/include/PacketVersionResolver.hpp> |
Jim Flynn | 01d0281 | 2020-04-29 21:12:13 +0100 | [diff] [blame] | 10 | |
| 11 | #include <common/include/ProfilingException.hpp> |
| 12 | |
| 13 | namespace armnn |
| 14 | { |
| 15 | |
| 16 | namespace profiling |
| 17 | { |
| 18 | |
| 19 | std::vector<uint32_t> RequestCountersPacketHandler::GetHeadersAccepted() |
| 20 | { |
| 21 | std::vector<uint32_t> headers; |
| 22 | headers.push_back(m_CounterDirectoryMessageHeader); // counter directory |
| 23 | return headers; |
| 24 | } |
| 25 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame^] | 26 | void RequestCountersPacketHandler::HandlePacket(const arm::pipe::Packet& packet) |
Jim Flynn | 01d0281 | 2020-04-29 21:12:13 +0100 | [diff] [blame] | 27 | { |
| 28 | if (packet.GetHeader() != m_CounterDirectoryMessageHeader) |
| 29 | { |
| 30 | return; |
| 31 | } |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame^] | 32 | arm::pipe::PacketVersionResolver packetVersionResolver; |
Jim Flynn | 01d0281 | 2020-04-29 21:12:13 +0100 | [diff] [blame] | 33 | DirectoryCaptureCommandHandler directoryCaptureCommandHandler( |
| 34 | 0, 2, packetVersionResolver.ResolvePacketVersion(0, 2).GetEncodedValue()); |
| 35 | directoryCaptureCommandHandler.operator()(packet); |
| 36 | const ICounterDirectory& counterDirectory = directoryCaptureCommandHandler.GetCounterDirectory(); |
| 37 | for (auto& category : counterDirectory.GetCategories()) |
| 38 | { |
| 39 | // Remember we need to translate the Uid's from our CounterDirectory instance to the parent one. |
| 40 | std::vector<uint16_t> translatedCounters; |
| 41 | for (auto const& copyUid : category->m_Counters) |
| 42 | { |
| 43 | translatedCounters.emplace_back(directoryCaptureCommandHandler.TranslateUIDCopyToOriginal(copyUid)); |
| 44 | } |
| 45 | m_IdList.insert(std::end(m_IdList), std::begin(translatedCounters), std::end(translatedCounters)); |
| 46 | } |
| 47 | SendCounterSelectionPacket(); |
| 48 | } |
| 49 | |
| 50 | void RequestCountersPacketHandler::SendCounterSelectionPacket() |
| 51 | { |
| 52 | uint32_t uint16_t_size = sizeof(uint16_t); |
| 53 | uint32_t uint32_t_size = sizeof(uint32_t); |
| 54 | |
| 55 | uint32_t offset = 0; |
| 56 | uint32_t bodySize = uint32_t_size + boost::numeric_cast<uint32_t>(m_IdList.size()) * uint16_t_size; |
| 57 | |
| 58 | auto uniqueData = std::make_unique<unsigned char[]>(bodySize); |
| 59 | auto data = reinterpret_cast<unsigned char*>(uniqueData.get()); |
| 60 | |
| 61 | // Copy capturePeriod |
| 62 | WriteUint32(data, offset, m_CapturePeriod); |
| 63 | |
| 64 | // Copy m_IdList |
| 65 | offset += uint32_t_size; |
| 66 | for (const uint16_t& id : m_IdList) |
| 67 | { |
| 68 | WriteUint16(data, offset, id); |
| 69 | offset += uint16_t_size; |
| 70 | } |
| 71 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame^] | 72 | arm::pipe::Packet packet(0x40000, bodySize, uniqueData); |
Jim Flynn | 01d0281 | 2020-04-29 21:12:13 +0100 | [diff] [blame] | 73 | m_Connection->ReturnPacket(packet); |
| 74 | } |
| 75 | |
| 76 | } // namespace profiling |
| 77 | |
| 78 | } // namespace armnn |