blob: 76c4b0cdc61f0cdee4a8a4fbe7513e166f47a394 [file] [log] [blame]
Jim Flynn01d02812020-04-29 21:12:13 +01001//
2// Copyright © 2020 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include "RequestCountersPacketHandler.hpp"
7
8#include "DirectoryCaptureCommandHandler.hpp"
9#include "PacketVersionResolver.hpp"
10
11#include <common/include/ProfilingException.hpp>
12
13namespace armnn
14{
15
16namespace profiling
17{
18
19std::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
26void RequestCountersPacketHandler::HandlePacket(const Packet& packet)
27{
28 if (packet.GetHeader() != m_CounterDirectoryMessageHeader)
29 {
30 return;
31 }
32 armnn::profiling::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())
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
50void 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
72 Packet packet(0x40000, bodySize, uniqueData);
73 m_Connection->ReturnPacket(packet);
74}
75
76} // namespace profiling
77
78} // namespace armnn