aboutsummaryrefslogtreecommitdiff
path: root/src/profiling/ProfilingConnectionFactory.cpp
blob: 96f7ed4b0601cba1cbf9d3bf9690b6cb19008b28 (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
//
// Copyright © 2019 Arm Ltd and Contributors. All rights reserved.
// SPDX-License-Identifier: MIT
//

#include "ProfilingConnectionFactory.hpp"

#include "FileOnlyProfilingConnection.hpp"
#include "ProfilingConnectionDumpToFileDecorator.hpp"
#include "SocketProfilingConnection.hpp"

namespace armnn
{

namespace profiling
{

std::unique_ptr<IProfilingConnection> ProfilingConnectionFactory::GetProfilingConnection(
    const Runtime::CreationOptions::ExternalProfilingOptions& options) const
{
    // Before proceed to create the IProfilingConnection, check if the file format is supported
    if (!(options.m_FileFormat == "binary"))
    {
        throw armnn::UnimplementedException("Unsupported profiling file format, only binary is supported");
    }

    // We can create 3 different types of IProfilingConnection.
    // 1: If no relevant options are specified then a SocketProfilingConnection is returned.
    // 2: If both incoming and outgoing capture files are specified then a SocketProfilingConnection decorated by a
    //    ProfilingConnectionDumpToFileDecorator is returned.
    // 3: If both incoming and outgoing capture files are specified and "file only" then a FileOnlyProfilingConnection
    //    decorated by a ProfilingConnectionDumpToFileDecorator is returned.
    // 4. There is now another option if m_FileOnly == true and there are ILocalPacketHandlers specified
    //    we can create a FileOnlyProfilingConnection without a file dump
    if ((!options.m_IncomingCaptureFile.empty() || !options.m_OutgoingCaptureFile.empty()) && !options.m_FileOnly)
    {
        // This is type 2.
        return std::make_unique<ProfilingConnectionDumpToFileDecorator>(std::make_unique<SocketProfilingConnection>(),
                                                                        options);
    }
    else if ((!options.m_IncomingCaptureFile.empty() || !options.m_OutgoingCaptureFile.empty()) && options.m_FileOnly)
    {
        // This is type 3.
        return std::make_unique<ProfilingConnectionDumpToFileDecorator>(
            std::make_unique<FileOnlyProfilingConnection>(options), options);
    }
    else if (options.m_FileOnly && !options.m_LocalPacketHandlers.empty())
    {
        // This is the type 4.
        return std::make_unique<FileOnlyProfilingConnection>(options);
    }
    else
    {
        // This is type 1.
        return std::make_unique<SocketProfilingConnection>();
    }
}

}    // namespace profiling

}    // namespace armnn