blob: 12a87a15354dbd6b381ae4a5a3c19265fc4de7c0 [file] [log] [blame]
Keith Davis3201eea2019-10-24 17:30:41 +01001//
2// Copyright © 2019 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#pragma once
7
8#include "CounterDirectory.hpp"
9#include "DirectoryCaptureCommandHandler.hpp"
10#include "IProfilingConnection.hpp"
11#include "ProfilingUtils.hpp"
12#include "Runtime.hpp"
13
14#include <fstream>
15#include <queue>
16
17namespace armnn
18{
19
20namespace profiling
21{
22
23enum class TargetEndianness
24{
25 BeWire,
26 LeWire
27};
28
29enum class PackageActivity
30{
31 StreamMetaData,
32 CounterDirectory,
33 Unknown
34};
35
36class FileOnlyProfilingConnection : public IProfilingConnection
37{
38public:
39 FileOnlyProfilingConnection(const Runtime::CreationOptions::ExternalProfilingOptions& options,
40 const bool quietOp = true)
41 : m_Options(options)
42 , m_QuietOp(quietOp)
43 , m_Endianness(TargetEndianness::LeWire) // Set a sensible default. WaitForStreamMeta will set a real value.
44 {};
45
46 ~FileOnlyProfilingConnection();
47
48 bool IsOpen() const override;
49
50 void Close() override;
51
52 // This is effectively receiving a data packet from ArmNN.
53 bool WritePacket(const unsigned char* buffer, uint32_t length) override;
54
55 // Sending a packet back to ArmNN.
56 Packet ReadPacket(uint32_t timeout) override;
57
58private:
59 bool WaitForStreamMeta(const unsigned char* buffer, uint32_t length);
60
61 uint32_t ToUint32(const unsigned char* data, TargetEndianness endianness);
62
63 void SendConnectionAck();
64
65 bool SendCounterSelectionPacket();
66
67 PackageActivity GetPackageActivity(const unsigned char* buffer, uint32_t headerAsWords[2]);
68
69 void Fail(const std::string& errorMessage);
70
71 static const uint32_t PIPE_MAGIC = 0x45495434;
72
73 Runtime::CreationOptions::ExternalProfilingOptions m_Options;
74 bool m_QuietOp;
75 std::vector<uint16_t> m_IdList;
76 std::queue<Packet> m_PacketQueue;
77 TargetEndianness m_Endianness;
78};
79
80} // namespace profiling
81
82} // namespace armnn