blob: 93ecff2e996f4fe85de8729d179931c85347e9a5 [file] [log] [blame]
Aron Virginas-Tar1a0f6912019-08-23 15:18:44 +01001//
Jim Flynnbbfe6032020-07-20 16:57:44 +01002// Copyright © 2019 Arm Ltd and Contributors. All rights reserved.
Aron Virginas-Tar1a0f6912019-08-23 15:18:44 +01003// SPDX-License-Identifier: MIT
4//
5
6#include "ProfilingConnectionFactory.hpp"
Keith Davis3201eea2019-10-24 17:30:41 +01007
8#include "FileOnlyProfilingConnection.hpp"
Keith Davisb10e0812019-10-17 09:52:50 +01009#include "ProfilingConnectionDumpToFileDecorator.hpp"
Keith Davis3201eea2019-10-24 17:30:41 +010010#include "SocketProfilingConnection.hpp"
Aron Virginas-Tar1a0f6912019-08-23 15:18:44 +010011
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000012namespace arm
Aron Virginas-Tar1a0f6912019-08-23 15:18:44 +010013{
14
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000015namespace pipe
Aron Virginas-Tar1a0f6912019-08-23 15:18:44 +010016{
17
18std::unique_ptr<IProfilingConnection> ProfilingConnectionFactory::GetProfilingConnection(
Jim Flynn4c9ed1d2022-01-23 23:57:20 +000019 const ProfilingOptions& options) const
Aron Virginas-Tar1a0f6912019-08-23 15:18:44 +010020{
Isabella Gottardia0687ee2020-03-11 18:04:20 +000021 // Before proceed to create the IProfilingConnection, check if the file format is supported
22 if (!(options.m_FileFormat == "binary"))
23 {
24 throw armnn::UnimplementedException("Unsupported profiling file format, only binary is supported");
25 }
26
Keith Davis3201eea2019-10-24 17:30:41 +010027 // We can create 3 different types of IProfilingConnection.
28 // 1: If no relevant options are specified then a SocketProfilingConnection is returned.
29 // 2: If both incoming and outgoing capture files are specified then a SocketProfilingConnection decorated by a
30 // ProfilingConnectionDumpToFileDecorator is returned.
31 // 3: If both incoming and outgoing capture files are specified and "file only" then a FileOnlyProfilingConnection
32 // decorated by a ProfilingConnectionDumpToFileDecorator is returned.
Jim Flynn4e755a52020-03-29 17:48:26 +010033 // 4. There is now another option if m_FileOnly == true and there are ILocalPacketHandlers specified
34 // we can create a FileOnlyProfilingConnection without a file dump
Keith Davis3201eea2019-10-24 17:30:41 +010035 if ((!options.m_IncomingCaptureFile.empty() || !options.m_OutgoingCaptureFile.empty()) && !options.m_FileOnly)
Keith Davisb10e0812019-10-17 09:52:50 +010036 {
Keith Davis3201eea2019-10-24 17:30:41 +010037 // This is type 2.
Keith Davisb10e0812019-10-17 09:52:50 +010038 return std::make_unique<ProfilingConnectionDumpToFileDecorator>(std::make_unique<SocketProfilingConnection>(),
Keith Davis3201eea2019-10-24 17:30:41 +010039 options);
40 }
41 else if ((!options.m_IncomingCaptureFile.empty() || !options.m_OutgoingCaptureFile.empty()) && options.m_FileOnly)
42 {
43 // This is type 3.
44 return std::make_unique<ProfilingConnectionDumpToFileDecorator>(
45 std::make_unique<FileOnlyProfilingConnection>(options), options);
Keith Davisb10e0812019-10-17 09:52:50 +010046 }
Jim Flynn4e755a52020-03-29 17:48:26 +010047 else if (options.m_FileOnly && !options.m_LocalPacketHandlers.empty())
48 {
49 // This is the type 4.
50 return std::make_unique<FileOnlyProfilingConnection>(options);
51 }
Keith Davisb10e0812019-10-17 09:52:50 +010052 else
53 {
Keith Davis3201eea2019-10-24 17:30:41 +010054 // This is type 1.
Keith Davisb10e0812019-10-17 09:52:50 +010055 return std::make_unique<SocketProfilingConnection>();
56 }
Aron Virginas-Tar1a0f6912019-08-23 15:18:44 +010057}
58
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000059} // namespace pipe
Aron Virginas-Tar1a0f6912019-08-23 15:18:44 +010060
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000061} // namespace arm