xref: /aosp_15_r20/external/armnn/profiling/client/src/ProfilingConnectionDumpToFileDecorator.hpp (revision 89c4ff92f2867872bb9e2354d150bf0c8c502810)
1 //
2 // Copyright © 2019 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #pragma once
7 
8 #include "IProfilingConnection.hpp"
9 #include "ProfilingUtils.hpp"
10 
11 #include <client/include/ProfilingOptions.hpp>
12 
13 #include <fstream>
14 #include <memory>
15 #include <string>
16 #include <vector>
17 
18 namespace arm
19 {
20 
21 namespace pipe
22 {
23 
24 class ProfilingConnectionDumpToFileDecorator : public IProfilingConnection
25 {
26 public:
27 
28     ProfilingConnectionDumpToFileDecorator(std::unique_ptr<IProfilingConnection> connection,
29                                            const ProfilingOptions& options,
30                                            bool ignoreFailures = false);
31 
32     ~ProfilingConnectionDumpToFileDecorator();
33 
34     bool IsOpen() const override;
35 
36     void Close() override;
37 
38     bool WritePacket(const unsigned char* buffer, uint32_t length) override;
39 
40     arm::pipe::Packet ReadPacket(uint32_t timeout) override;
41 
42 private:
43     bool OpenIncomingDumpFile();
44 
45     bool OpenOutgoingDumpFile();
46 
47     void DumpIncomingToFile(const arm::pipe::Packet& packet);
48 
49     bool DumpOutgoingToFile(const unsigned char* buffer, uint32_t length);
50 
51     void Fail(const std::string& errorMessage);
52 
53     std::unique_ptr<IProfilingConnection> m_Connection;
54     ProfilingOptions                      m_Options;
55     std::ofstream                         m_IncomingDumpFileStream;
56     std::ofstream                         m_OutgoingDumpFileStream;
57     bool                                  m_IgnoreFileErrors;
58 };
59 
60 } // namespace pipe
61 
62 } // namespace arm
63