aboutsummaryrefslogtreecommitdiff
path: root/src/profiling/ProfilingConnectionDumpToFileDecorator.hpp
blob: bf79adc60324960181b82426a933790252d83064 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//
// Copyright © 2019 Arm Ltd and Contributors. All rights reserved.
// SPDX-License-Identifier: MIT
//

#pragma once

#include "IProfilingConnection.hpp"
#include "ProfilingUtils.hpp"

#include <Runtime.hpp>
#include <armnn/Optional.hpp>

#include <fstream>
#include <memory>
#include <string>
#include <vector>

namespace armnn
{

namespace profiling
{

class ProfilingConnectionDumpToFileDecorator : public IProfilingConnection
{
public:

    ProfilingConnectionDumpToFileDecorator(std::unique_ptr<IProfilingConnection> connection,
                                           const ProfilingOptions& options,
                                           bool ignoreFailures = false);

    ~ProfilingConnectionDumpToFileDecorator();

    bool IsOpen() const override;

    void Close() override;

    bool WritePacket(const unsigned char* buffer, uint32_t length) override;

    arm::pipe::Packet ReadPacket(uint32_t timeout) override;

private:
    bool OpenIncomingDumpFile();

    bool OpenOutgoingDumpFile();

    void DumpIncomingToFile(const arm::pipe::Packet& packet);

    bool DumpOutgoingToFile(const unsigned char* buffer, uint32_t length);

    void Fail(const std::string& errorMessage);

    std::unique_ptr<IProfilingConnection> m_Connection;
    ProfilingOptions                      m_Options;
    std::ofstream                         m_IncomingDumpFileStream;
    std::ofstream                         m_OutgoingDumpFileStream;
    bool                                  m_IgnoreFileErrors;
};

} // namespace profiling

} // namespace armnn