Aron Virginas-Tar | dfa1477 | 2019-09-24 18:24:47 +0100 | [diff] [blame] | 1 | // |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 2 | // Copyright © 2019 Arm Ltd and Contributors. All rights reserved. |
Aron Virginas-Tar | dfa1477 | 2019-09-24 18:24:47 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #pragma once |
| 7 | |
| 8 | #include "IProfilingConnection.hpp" |
Keith Davis | b10e081 | 2019-10-17 09:52:50 +0100 | [diff] [blame] | 9 | #include "ProfilingUtils.hpp" |
Aron Virginas-Tar | dfa1477 | 2019-09-24 18:24:47 +0100 | [diff] [blame] | 10 | |
Keith Davis | b10e081 | 2019-10-17 09:52:50 +0100 | [diff] [blame] | 11 | #include <Runtime.hpp> |
Aron Virginas-Tar | dfa1477 | 2019-09-24 18:24:47 +0100 | [diff] [blame] | 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: |
Aron Virginas-Tar | dfa1477 | 2019-09-24 18:24:47 +0100 | [diff] [blame] | 28 | |
| 29 | ProfilingConnectionDumpToFileDecorator(std::unique_ptr<IProfilingConnection> connection, |
Kevin May | d92a6e4 | 2021-02-04 10:27:41 +0000 | [diff] [blame] | 30 | const IRuntime::CreationOptions::ExternalProfilingOptions& options, |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 31 | bool ignoreFailures = false); |
Aron Virginas-Tar | dfa1477 | 2019-09-24 18:24:47 +0100 | [diff] [blame] | 32 | |
| 33 | ~ProfilingConnectionDumpToFileDecorator(); |
| 34 | |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 35 | bool IsOpen() const override; |
Aron Virginas-Tar | dfa1477 | 2019-09-24 18:24:47 +0100 | [diff] [blame] | 36 | |
| 37 | void Close() override; |
| 38 | |
| 39 | bool WritePacket(const unsigned char* buffer, uint32_t length) override; |
| 40 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 41 | arm::pipe::Packet ReadPacket(uint32_t timeout) override; |
Aron Virginas-Tar | dfa1477 | 2019-09-24 18:24:47 +0100 | [diff] [blame] | 42 | |
| 43 | private: |
| 44 | bool OpenIncomingDumpFile(); |
| 45 | |
| 46 | bool OpenOutgoingDumpFile(); |
| 47 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 48 | void DumpIncomingToFile(const arm::pipe::Packet& packet); |
Aron Virginas-Tar | dfa1477 | 2019-09-24 18:24:47 +0100 | [diff] [blame] | 49 | |
Matteo Martincigh | 67ef2a5 | 2019-10-10 13:29:02 +0100 | [diff] [blame] | 50 | bool DumpOutgoingToFile(const unsigned char* buffer, uint32_t length); |
Aron Virginas-Tar | dfa1477 | 2019-09-24 18:24:47 +0100 | [diff] [blame] | 51 | |
| 52 | void Fail(const std::string& errorMessage); |
| 53 | |
Kevin May | d92a6e4 | 2021-02-04 10:27:41 +0000 | [diff] [blame] | 54 | std::unique_ptr<IProfilingConnection> m_Connection; |
| 55 | IRuntime::CreationOptions::ExternalProfilingOptions m_Options; |
| 56 | std::ofstream m_IncomingDumpFileStream; |
| 57 | std::ofstream m_OutgoingDumpFileStream; |
| 58 | bool m_IgnoreFileErrors; |
Aron Virginas-Tar | dfa1477 | 2019-09-24 18:24:47 +0100 | [diff] [blame] | 59 | }; |
| 60 | |
Aron Virginas-Tar | dfa1477 | 2019-09-24 18:24:47 +0100 | [diff] [blame] | 61 | } // namespace profiling |
| 62 | |
| 63 | } // namespace armnn |