Aron Virginas-Tar | 1a0f691 | 2019-08-23 15:18:44 +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 | 1a0f691 | 2019-08-23 15:18:44 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "ProfilingConnectionFactory.hpp" |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 7 | |
| 8 | #include "FileOnlyProfilingConnection.hpp" |
Keith Davis | b10e081 | 2019-10-17 09:52:50 +0100 | [diff] [blame] | 9 | #include "ProfilingConnectionDumpToFileDecorator.hpp" |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 10 | #include "SocketProfilingConnection.hpp" |
Aron Virginas-Tar | 1a0f691 | 2019-08-23 15:18:44 +0100 | [diff] [blame] | 11 | |
| 12 | namespace armnn |
| 13 | { |
| 14 | |
| 15 | namespace profiling |
| 16 | { |
| 17 | |
| 18 | std::unique_ptr<IProfilingConnection> ProfilingConnectionFactory::GetProfilingConnection( |
Kevin May | d92a6e4 | 2021-02-04 10:27:41 +0000 | [diff] [blame] | 19 | const IRuntime::CreationOptions::ExternalProfilingOptions& options) const |
Aron Virginas-Tar | 1a0f691 | 2019-08-23 15:18:44 +0100 | [diff] [blame] | 20 | { |
Isabella Gottardi | a0687ee | 2020-03-11 18:04:20 +0000 | [diff] [blame] | 21 | // 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 Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 27 | // 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 Flynn | 4e755a5 | 2020-03-29 17:48:26 +0100 | [diff] [blame] | 33 | // 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 Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 35 | if ((!options.m_IncomingCaptureFile.empty() || !options.m_OutgoingCaptureFile.empty()) && !options.m_FileOnly) |
Keith Davis | b10e081 | 2019-10-17 09:52:50 +0100 | [diff] [blame] | 36 | { |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 37 | // This is type 2. |
Keith Davis | b10e081 | 2019-10-17 09:52:50 +0100 | [diff] [blame] | 38 | return std::make_unique<ProfilingConnectionDumpToFileDecorator>(std::make_unique<SocketProfilingConnection>(), |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 39 | 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 Davis | b10e081 | 2019-10-17 09:52:50 +0100 | [diff] [blame] | 46 | } |
Jim Flynn | 4e755a5 | 2020-03-29 17:48:26 +0100 | [diff] [blame] | 47 | 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 Davis | b10e081 | 2019-10-17 09:52:50 +0100 | [diff] [blame] | 52 | else |
| 53 | { |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 54 | // This is type 1. |
Keith Davis | b10e081 | 2019-10-17 09:52:50 +0100 | [diff] [blame] | 55 | return std::make_unique<SocketProfilingConnection>(); |
| 56 | } |
Aron Virginas-Tar | 1a0f691 | 2019-08-23 15:18:44 +0100 | [diff] [blame] | 57 | } |
| 58 | |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 59 | } // namespace profiling |
Aron Virginas-Tar | 1a0f691 | 2019-08-23 15:18:44 +0100 | [diff] [blame] | 60 | |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 61 | } // namespace armnn |