2 // Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
6 #include "RequestCountersPacketHandler.hpp"
8 #include "DirectoryCaptureCommandHandler.hpp"
9 #include <common/include/PacketVersionResolver.hpp>
11 #include <common/include/ProfilingException.hpp>
19 std::vector<uint32_t> RequestCountersPacketHandler::GetHeadersAccepted()
21 std::vector<uint32_t> headers;
22 headers.push_back(m_CounterDirectoryMessageHeader); // counter directory
26 void RequestCountersPacketHandler::HandlePacket(const arm::pipe::Packet& packet)
28 if (packet.GetHeader() != m_CounterDirectoryMessageHeader)
32 arm::pipe::PacketVersionResolver packetVersionResolver;
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())
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)
43 translatedCounters.emplace_back(directoryCaptureCommandHandler.TranslateUIDCopyToOriginal(copyUid));
45 m_IdList.insert(std::end(m_IdList), std::begin(translatedCounters), std::end(translatedCounters));
47 SendCounterSelectionPacket();
50 void RequestCountersPacketHandler::SendCounterSelectionPacket()
52 uint32_t uint16_t_size = sizeof(uint16_t);
53 uint32_t uint32_t_size = sizeof(uint32_t);
56 uint32_t bodySize = uint32_t_size + boost::numeric_cast<uint32_t>(m_IdList.size()) * uint16_t_size;
58 auto uniqueData = std::make_unique<unsigned char[]>(bodySize);
59 auto data = reinterpret_cast<unsigned char*>(uniqueData.get());
62 WriteUint32(data, offset, m_CapturePeriod);
65 offset += uint32_t_size;
66 for (const uint16_t& id : m_IdList)
68 WriteUint16(data, offset, id);
69 offset += uint16_t_size;
72 arm::pipe::Packet packet(0x40000, bodySize, uniqueData);
73 m_Connection->ReturnPacket(packet);
76 } // namespace profiling