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 <Runtime.hpp> 12 #include <armnn/Optional.hpp> 13 14 #include <fstream> 15 #include <memory> 16 #include <string> 17 #include <vector> 18 19 namespace armnn 20 { 21 22 namespace profiling 23 { 24 25 class ProfilingConnectionDumpToFileDecorator : public IProfilingConnection 26 { 27 public: 28 29 ProfilingConnectionDumpToFileDecorator(std::unique_ptr<IProfilingConnection> connection, 30 const Runtime::CreationOptions::ExternalProfilingOptions& options, 31 bool ignoreFailures = false); 32 33 ~ProfilingConnectionDumpToFileDecorator(); 34 35 bool IsOpen() const override; 36 37 void Close() override; 38 39 bool WritePacket(const unsigned char* buffer, uint32_t length) override; 40 41 arm::pipe::Packet ReadPacket(uint32_t timeout) override; 42 43 private: 44 bool OpenIncomingDumpFile(); 45 46 bool OpenOutgoingDumpFile(); 47 48 void DumpIncomingToFile(const arm::pipe::Packet& packet); 49 50 bool DumpOutgoingToFile(const unsigned char* buffer, uint32_t length); 51 52 void Fail(const std::string& errorMessage); 53 54 std::unique_ptr<IProfilingConnection> m_Connection; 55 Runtime::CreationOptions::ExternalProfilingOptions m_Options; 56 std::ofstream m_IncomingDumpFileStream; 57 std::ofstream m_OutgoingDumpFileStream; 58 bool m_IgnoreFileErrors; 59 }; 60 61 } // namespace profiling 62 63 } // namespace armnn 64