Aron Virginas-Tar | dfa1477 | 2019-09-24 18:24:47 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2019 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #pragma once |
| 7 | |
| 8 | #include "IProfilingConnection.hpp" |
| 9 | |
| 10 | #include <armnn/Optional.hpp> |
| 11 | |
| 12 | #include <fstream> |
| 13 | #include <memory> |
| 14 | #include <string> |
| 15 | #include <vector> |
| 16 | |
| 17 | namespace armnn |
| 18 | { |
| 19 | |
| 20 | namespace profiling |
| 21 | { |
| 22 | |
| 23 | class ProfilingConnectionDumpToFileDecorator : public IProfilingConnection |
| 24 | { |
| 25 | public: |
| 26 | struct Settings |
| 27 | { |
| 28 | Settings(const std::string& incomingDumpFileName = "", |
| 29 | const std::string& outgoingDumpFileName = "", |
| 30 | bool ignoreFileErrors = true) |
| 31 | : m_IncomingDumpFileName(incomingDumpFileName) |
| 32 | , m_OutgoingDumpFileName(outgoingDumpFileName) |
| 33 | , m_DumpIncoming(!incomingDumpFileName.empty()) |
| 34 | , m_DumpOutgoing(!outgoingDumpFileName.empty()) |
| 35 | , m_IgnoreFileErrors(ignoreFileErrors) |
| 36 | {} |
| 37 | |
| 38 | ~Settings() = default; |
| 39 | |
| 40 | std::string m_IncomingDumpFileName; |
| 41 | std::string m_OutgoingDumpFileName; |
| 42 | bool m_DumpIncoming; |
| 43 | bool m_DumpOutgoing; |
| 44 | bool m_IgnoreFileErrors; |
| 45 | }; |
| 46 | |
| 47 | ProfilingConnectionDumpToFileDecorator(std::unique_ptr<IProfilingConnection> connection, |
| 48 | const Settings& settings); |
| 49 | |
| 50 | ~ProfilingConnectionDumpToFileDecorator(); |
| 51 | |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame^] | 52 | bool IsOpen() const override; |
Aron Virginas-Tar | dfa1477 | 2019-09-24 18:24:47 +0100 | [diff] [blame] | 53 | |
| 54 | void Close() override; |
| 55 | |
| 56 | bool WritePacket(const unsigned char* buffer, uint32_t length) override; |
| 57 | |
| 58 | Packet ReadPacket(uint32_t timeout) override; |
| 59 | |
| 60 | private: |
| 61 | bool OpenIncomingDumpFile(); |
| 62 | |
| 63 | bool OpenOutgoingDumpFile(); |
| 64 | |
| 65 | void DumpIncomingToFile(const Packet& packet); |
| 66 | |
| 67 | bool DumpOutgoingToFile(const char* buffer, uint32_t length); |
| 68 | |
| 69 | void Fail(const std::string& errorMessage); |
| 70 | |
| 71 | std::unique_ptr<IProfilingConnection> m_Connection; |
| 72 | Settings m_Settings; |
| 73 | std::ofstream m_IncomingDumpFileStream; |
| 74 | std::ofstream m_OutgoingDumpFileStream; |
| 75 | }; |
| 76 | |
| 77 | using ProfilingConnectionDumpToFileDecoratorSettings = ProfilingConnectionDumpToFileDecorator::Settings; |
| 78 | |
| 79 | } // namespace profiling |
| 80 | |
| 81 | } // namespace armnn |