blob: 3238b351a37fd6824fafda4bee2834d879b8cc3a [file] [log] [blame]
Ferran Balaguer73882172019-09-02 16:39:42 +01001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#pragma once
7
8#include "IBufferWrapper.hpp"
9#include "ISendCounterPacket.hpp"
10#include "CounterDirectory.hpp"
11
12namespace armnn
13{
14
15namespace profiling
16{
17
18class SendCounterPacket : public ISendCounterPacket
19{
20public:
Francis Murtagh3a161982019-09-04 15:25:02 +010021 using IndexValuePairsVector = std::vector<std::pair<uint16_t, uint32_t>>;
22
Matteo Martincigh149528e2019-09-05 12:02:04 +010023 SendCounterPacket(IBufferWrapper& buffer)
24 : m_Buffer(buffer),
25 m_ReadyToRead(false)
26 {}
Ferran Balaguer73882172019-09-02 16:39:42 +010027
28 void SendStreamMetaDataPacket() override;
29
Matteo Martincigh149528e2019-09-05 12:02:04 +010030 void SendCounterDirectoryPacket(const CounterDirectory& counterDirectory) override;
Ferran Balaguer73882172019-09-02 16:39:42 +010031
Francis Murtagh3a161982019-09-04 15:25:02 +010032 void SendPeriodicCounterCapturePacket(uint64_t timestamp, const IndexValuePairsVector& values) override;
Ferran Balaguer73882172019-09-02 16:39:42 +010033
34 void SendPeriodicCounterSelectionPacket(uint32_t capturePeriod,
35 const std::vector<uint16_t>& selectedCounterIds) override;
36
37 void SetReadyToRead() override;
38
Ferran Balaguer47d0fe92019-09-04 16:47:34 +010039 static const unsigned int PIPE_MAGIC = 0x45495434;
40 static const unsigned int MAX_METADATA_PACKET_LENGTH = 4096;
41
Ferran Balaguer73882172019-09-02 16:39:42 +010042private:
Matteo Martincigh149528e2019-09-05 12:02:04 +010043 template <typename ExceptionType>
44 void CancelOperationAndThrow(const std::string& errorMessage)
45 {
46 // Cancel the operation
47 m_Buffer.Commit(0);
48
49 // Throw a runtime exception with the given error message
50 throw ExceptionType(errorMessage);
51 }
52
Ferran Balaguer73882172019-09-02 16:39:42 +010053 IBufferWrapper& m_Buffer;
54 bool m_ReadyToRead;
55};
56
57} // namespace profiling
58
59} // namespace armnn
60