1 // 2 // Copyright © 2019 Arm Ltd and Contributors. All rights reserved. 3 // SPDX-License-Identifier: MIT 4 // 5 6 #include "ProfilingConnectionFactory.hpp" 7 8 #include "FileOnlyProfilingConnection.hpp" 9 #include "ProfilingConnectionDumpToFileDecorator.hpp" 10 #include "SocketProfilingConnection.hpp" 11 12 namespace arm 13 { 14 15 namespace pipe 16 { 17 GetProfilingConnection(const ProfilingOptions & options) const18std::unique_ptr<IProfilingConnection> ProfilingConnectionFactory::GetProfilingConnection( 19 const ProfilingOptions& options) const 20 { 21 // Before proceed to create the IProfilingConnection, check if the file format is supported 22 if (!(options.m_FileFormat == "binary")) 23 { 24 throw arm::pipe::UnimplementedException("Unsupported profiling file format, only binary is supported"); 25 } 26 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. 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 35 if ((!options.m_IncomingCaptureFile.empty() || !options.m_OutgoingCaptureFile.empty()) && !options.m_FileOnly) 36 { 37 // This is type 2. 38 return std::make_unique<ProfilingConnectionDumpToFileDecorator>(std::make_unique<SocketProfilingConnection>(), 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); 46 } 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 } 52 else 53 { 54 // This is type 1. 55 return std::make_unique<SocketProfilingConnection>(); 56 } 57 } 58 59 } // namespace pipe 60 61 } // namespace arm 62