2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
6 #include "SendCounterPacket.hpp"
7 #include "EncodeVersion.hpp"
8 #include "ProfilingUtils.hpp"
10 #include <armnn/Exceptions.hpp>
12 #include <boost/format.hpp>
13 #include <boost/numeric/conversion/cast.hpp>
23 using boost::numeric_cast;
25 void SendCounterPacket::SendStreamMetaDataPacket()
27 throw armnn::UnimplementedException();
30 void SendCounterPacket::SendCounterDirectoryPacket(const Category& category, const std::vector<Counter>& counters)
32 throw armnn::UnimplementedException();
35 void SendCounterPacket::SendPeriodicCounterCapturePacket(uint64_t timestamp, const std::vector<uint32_t>& counterValues,
36 const std::vector<uint16_t>& counterUids)
38 throw armnn::UnimplementedException();
41 void SendCounterPacket::SendPeriodicCounterSelectionPacket(uint32_t capturePeriod,
42 const std::vector<uint16_t>& selectedCounterIds)
44 uint32_t packetFamily = 0;
45 uint32_t packetId = 4;
46 uint32_t headerSize = numeric_cast<uint32_t>(2 * sizeof(uint32_t));
47 uint32_t bodySize = numeric_cast<uint32_t>((1 * sizeof(uint32_t)) + (selectedCounterIds.size() * sizeof(uint16_t)));
48 uint32_t totalSize = headerSize + bodySize;
50 uint32_t reserved = 0;
52 unsigned char* writeBuffer = m_Buffer.Reserve(totalSize, reserved);
54 if (reserved < totalSize)
56 // Cancel the operation.
58 throw RuntimeException(boost::str(boost::format("No space left in buffer. Unable to reserve (%1%) bytes.")
62 if (writeBuffer == nullptr)
64 // Cancel the operation.
66 throw RuntimeException("Error reserving buffer memory.");
70 WriteUint32(writeBuffer, offset, ((packetFamily & 0x3F) << 26) | ((packetId & 0x3FF) << 16));
71 offset += numeric_cast<uint32_t>(sizeof(uint32_t));
72 WriteUint32(writeBuffer, offset, bodySize);
74 // Copy capturePeriod.
75 offset += numeric_cast<uint32_t>(sizeof(uint32_t));
76 WriteUint32(writeBuffer, offset, capturePeriod);
78 // Copy selectedCounterIds.
79 offset += numeric_cast<uint32_t>(sizeof(uint32_t));
80 for(const uint16_t& id: selectedCounterIds)
82 WriteUint16(writeBuffer, offset, id);
83 offset += numeric_cast<uint32_t>(sizeof(uint16_t));
86 m_Buffer.Commit(totalSize);
89 void SendCounterPacket::SetReadyToRead()
94 } // namespace profiling