1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
//
// Copyright © 2017 Arm Ltd. All rights reserved.
// SPDX-License-Identifier: MIT
//
#pragma once
#include "IBufferWrapper.hpp"
#include "ISendCounterPacket.hpp"
#include "CounterDirectory.hpp"
namespace armnn
{
namespace profiling
{
class SendCounterPacket : public ISendCounterPacket
{
public:
using CategoryRecord = std::vector<uint32_t>;
using DeviceRecord = std::vector<uint32_t>;
using CounterSetRecord = std::vector<uint32_t>;
using EventRecord = std::vector<uint32_t>;
using IndexValuePairsVector = std::vector<std::pair<uint16_t, uint32_t>>;
SendCounterPacket(IBufferWrapper& buffer)
: m_Buffer(buffer),
m_ReadyToRead(false)
{}
void SendStreamMetaDataPacket() override;
void SendCounterDirectoryPacket(const ICounterDirectory& counterDirectory) override;
void SendPeriodicCounterCapturePacket(uint64_t timestamp, const IndexValuePairsVector& values) override;
void SendPeriodicCounterSelectionPacket(uint32_t capturePeriod,
const std::vector<uint16_t>& selectedCounterIds) override;
void SetReadyToRead() override;
static const unsigned int PIPE_MAGIC = 0x45495434;
static const unsigned int MAX_METADATA_PACKET_LENGTH = 4096;
private:
template <typename ExceptionType>
void CancelOperationAndThrow(const std::string& errorMessage)
{
// Cancel the operation
m_Buffer.Commit(0);
// Throw a runtime exception with the given error message
throw ExceptionType(errorMessage);
}
IBufferWrapper& m_Buffer;
bool m_ReadyToRead;
protected:
// Helper methods, protected for testing
bool CreateCategoryRecord(const CategoryPtr& category,
const Counters& counters,
CategoryRecord& categoryRecord,
std::string& errorMessage);
bool CreateDeviceRecord(const DevicePtr& device,
DeviceRecord& deviceRecord,
std::string& errorMessage);
bool CreateCounterSetRecord(const CounterSetPtr& counterSet,
CounterSetRecord& counterSetRecord,
std::string& errorMessage);
bool CreateEventRecord(const CounterPtr& counter,
EventRecord& eventRecord,
std::string& errorMessage);
};
} // namespace profiling
} // namespace armnn
|