ArmNN
 20.08
RequestCountersPacketHandler.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
7 
9 #include <common/include/PacketVersionResolver.hpp>
10 
11 #include <common/include/ProfilingException.hpp>
12 
13 namespace armnn
14 {
15 
16 namespace profiling
17 {
18 
20 {
21  std::vector<uint32_t> headers;
22  headers.push_back(m_CounterDirectoryMessageHeader); // counter directory
23  return headers;
24 }
25 
26 void RequestCountersPacketHandler::HandlePacket(const arm::pipe::Packet& packet)
27 {
28  if (packet.GetHeader() != m_CounterDirectoryMessageHeader)
29  {
30  return;
31  }
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())
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 
72  arm::pipe::Packet packet(0x40000, bodySize, uniqueData);
73  m_Connection->ReturnPacket(packet);
74 }
75 
76 } // namespace profiling
77 
78 } // namespace armnn
void WriteUint16(const IPacketBufferPtr &packetBuffer, unsigned int offset, uint16_t value)
void WriteUint32(const IPacketBufferPtr &packetBuffer, unsigned int offset, uint32_t value)
Copyright (c) 2020 ARM Limited.
virtual const Categories & GetCategories() const =0
virtual void ReturnPacket(arm::pipe::Packet &packet)=0
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
Definition: NumericCast.hpp:33
void HandlePacket(const arm::pipe::Packet &packet) override
process the packet