1*89c4ff92SAndroid Build Coastguard Worker // 2*89c4ff92SAndroid Build Coastguard Worker // Copyright © 2019 Arm Ltd and Contributors. All rights reserved. 3*89c4ff92SAndroid Build Coastguard Worker // SPDX-License-Identifier: MIT 4*89c4ff92SAndroid Build Coastguard Worker // 5*89c4ff92SAndroid Build Coastguard Worker 6*89c4ff92SAndroid Build Coastguard Worker #include "ProfilingConnectionFactory.hpp" 7*89c4ff92SAndroid Build Coastguard Worker 8*89c4ff92SAndroid Build Coastguard Worker #include "FileOnlyProfilingConnection.hpp" 9*89c4ff92SAndroid Build Coastguard Worker #include "ProfilingConnectionDumpToFileDecorator.hpp" 10*89c4ff92SAndroid Build Coastguard Worker #include "SocketProfilingConnection.hpp" 11*89c4ff92SAndroid Build Coastguard Worker 12*89c4ff92SAndroid Build Coastguard Worker namespace arm 13*89c4ff92SAndroid Build Coastguard Worker { 14*89c4ff92SAndroid Build Coastguard Worker 15*89c4ff92SAndroid Build Coastguard Worker namespace pipe 16*89c4ff92SAndroid Build Coastguard Worker { 17*89c4ff92SAndroid Build Coastguard Worker GetProfilingConnection(const ProfilingOptions & options) const18*89c4ff92SAndroid Build Coastguard Workerstd::unique_ptr<IProfilingConnection> ProfilingConnectionFactory::GetProfilingConnection( 19*89c4ff92SAndroid Build Coastguard Worker const ProfilingOptions& options) const 20*89c4ff92SAndroid Build Coastguard Worker { 21*89c4ff92SAndroid Build Coastguard Worker // Before proceed to create the IProfilingConnection, check if the file format is supported 22*89c4ff92SAndroid Build Coastguard Worker if (!(options.m_FileFormat == "binary")) 23*89c4ff92SAndroid Build Coastguard Worker { 24*89c4ff92SAndroid Build Coastguard Worker throw arm::pipe::UnimplementedException("Unsupported profiling file format, only binary is supported"); 25*89c4ff92SAndroid Build Coastguard Worker } 26*89c4ff92SAndroid Build Coastguard Worker 27*89c4ff92SAndroid Build Coastguard Worker // We can create 3 different types of IProfilingConnection. 28*89c4ff92SAndroid Build Coastguard Worker // 1: If no relevant options are specified then a SocketProfilingConnection is returned. 29*89c4ff92SAndroid Build Coastguard Worker // 2: If both incoming and outgoing capture files are specified then a SocketProfilingConnection decorated by a 30*89c4ff92SAndroid Build Coastguard Worker // ProfilingConnectionDumpToFileDecorator is returned. 31*89c4ff92SAndroid Build Coastguard Worker // 3: If both incoming and outgoing capture files are specified and "file only" then a FileOnlyProfilingConnection 32*89c4ff92SAndroid Build Coastguard Worker // decorated by a ProfilingConnectionDumpToFileDecorator is returned. 33*89c4ff92SAndroid Build Coastguard Worker // 4. There is now another option if m_FileOnly == true and there are ILocalPacketHandlers specified 34*89c4ff92SAndroid Build Coastguard Worker // we can create a FileOnlyProfilingConnection without a file dump 35*89c4ff92SAndroid Build Coastguard Worker if ((!options.m_IncomingCaptureFile.empty() || !options.m_OutgoingCaptureFile.empty()) && !options.m_FileOnly) 36*89c4ff92SAndroid Build Coastguard Worker { 37*89c4ff92SAndroid Build Coastguard Worker // This is type 2. 38*89c4ff92SAndroid Build Coastguard Worker return std::make_unique<ProfilingConnectionDumpToFileDecorator>(std::make_unique<SocketProfilingConnection>(), 39*89c4ff92SAndroid Build Coastguard Worker options); 40*89c4ff92SAndroid Build Coastguard Worker } 41*89c4ff92SAndroid Build Coastguard Worker else if ((!options.m_IncomingCaptureFile.empty() || !options.m_OutgoingCaptureFile.empty()) && options.m_FileOnly) 42*89c4ff92SAndroid Build Coastguard Worker { 43*89c4ff92SAndroid Build Coastguard Worker // This is type 3. 44*89c4ff92SAndroid Build Coastguard Worker return std::make_unique<ProfilingConnectionDumpToFileDecorator>( 45*89c4ff92SAndroid Build Coastguard Worker std::make_unique<FileOnlyProfilingConnection>(options), options); 46*89c4ff92SAndroid Build Coastguard Worker } 47*89c4ff92SAndroid Build Coastguard Worker else if (options.m_FileOnly && !options.m_LocalPacketHandlers.empty()) 48*89c4ff92SAndroid Build Coastguard Worker { 49*89c4ff92SAndroid Build Coastguard Worker // This is the type 4. 50*89c4ff92SAndroid Build Coastguard Worker return std::make_unique<FileOnlyProfilingConnection>(options); 51*89c4ff92SAndroid Build Coastguard Worker } 52*89c4ff92SAndroid Build Coastguard Worker else 53*89c4ff92SAndroid Build Coastguard Worker { 54*89c4ff92SAndroid Build Coastguard Worker // This is type 1. 55*89c4ff92SAndroid Build Coastguard Worker return std::make_unique<SocketProfilingConnection>(); 56*89c4ff92SAndroid Build Coastguard Worker } 57*89c4ff92SAndroid Build Coastguard Worker } 58*89c4ff92SAndroid Build Coastguard Worker 59*89c4ff92SAndroid Build Coastguard Worker } // namespace pipe 60*89c4ff92SAndroid Build Coastguard Worker 61*89c4ff92SAndroid Build Coastguard Worker } // namespace arm 62