virtual Status PrintGraph() = 0;
- virtual profiling::ProfilingGuid GetGuid() const = 0;
-
/// Adds an input layer to the network.
/// @param id - User generated id to uniquely identify a particular input. The same id needs to be specified.
/// when passing the inputs to the IRuntime::EnqueueWorkload() function.
class ProfilingGuid
{
public:
+ ProfilingGuid() : m_Guid(0) {}
+
ProfilingGuid(uint64_t guid) : m_Guid(guid) {}
operator uint64_t() const { return m_Guid; }
#include <armnn/BackendRegistry.hpp>
#include <armnn/Exceptions.hpp>
-#include <ProfilingService.hpp>
namespace armnn
{
std::string(id) + " already registered as IBackend factory",
CHECK_LOCATION());
}
- if (profiling::ProfilingService::Instance().IsProfilingEnabled())
- {
- profiling::ProfilingService::Instance().IncrementCounterValue(armnn::profiling::REGISTERED_BACKENDS);
- }
m_Factories[id] = factory;
}
void BackendRegistry::Deregister(const BackendId& id)
{
- if (profiling::ProfilingService::Instance().IsProfilingEnabled())
- {
- profiling::ProfilingService::Instance().IncrementCounterValue(armnn::profiling::UNREGISTERED_BACKENDS);
- }
m_Factories.erase(id);
}
, m_Type(type)
, m_BackendId()
, m_BackendHint(EmptyOptional())
-, m_Guid(profiling::ProfilingService::Instance().NextGuid())
+, m_Guid(profiling::ProfilingService::GetNextGuid())
{
IgnoreUnused(layout);
m_InputSlots.reserve(numInputSlots);
#include <backendsCommon/MemSyncWorkload.hpp>
#include <LabelsAndEventClasses.hpp>
-#include <ProfilingService.hpp>
#include <boost/polymorphic_cast.hpp>
#include <boost/assert.hpp>
std::unique_ptr<LoadedNetwork> LoadedNetwork::MakeLoadedNetwork(std::unique_ptr<OptimizedNetwork> net,
std::string& errorMessage,
- const INetworkProperties& networkProperties)
+ const INetworkProperties& networkProperties,
+ profiling::ProfilingService& profilingService)
{
std::unique_ptr<LoadedNetwork> loadedNetwork;
try
{
- loadedNetwork.reset(new LoadedNetwork(std::move(net), networkProperties));
+ loadedNetwork.reset(new LoadedNetwork(std::move(net), networkProperties, profilingService));
}
catch (const armnn::RuntimeException& error)
{
}
LoadedNetwork::LoadedNetwork(std::unique_ptr<OptimizedNetwork> net,
- const INetworkProperties& networkProperties) :
+ const INetworkProperties& networkProperties,
+ profiling::ProfilingService& profilingService) :
m_OptimizedNetwork(std::move(net)),
m_IsImportEnabled(networkProperties.m_ImportEnabled),
- m_IsExportEnabled(networkProperties.m_ExportEnabled)
+ m_IsExportEnabled(networkProperties.m_ExportEnabled),
+ m_ProfilingService(profilingService)
{
// Create a profiler and register it for the current thread.
m_Profiler = std::make_shared<Profiler>();
}
ProfilingGuid networkGuid = m_OptimizedNetwork->GetGuid();
- std::unique_ptr<TimelineUtilityMethods> timelineUtils = TimelineUtilityMethods::GetTimelineUtils();
+ std::unique_ptr<TimelineUtilityMethods> timelineUtils =
+ TimelineUtilityMethods::GetTimelineUtils(m_ProfilingService);
if (timelineUtils)
{
timelineUtils->CreateTypedEntity(networkGuid, LabelsAndEventClasses::NETWORK_GUID);
EnqueueOutput(*outputLayer, pin.GetTensorHandle(), pin.GetTensorInfo());
}
- std::unique_ptr<TimelineUtilityMethods> timelineUtils = TimelineUtilityMethods::GetTimelineUtils();
- ProfilingGuid inferenceGuid = ProfilingService::Instance().NextGuid();
+ std::unique_ptr<TimelineUtilityMethods> timelineUtils =
+ TimelineUtilityMethods::GetTimelineUtils(m_ProfilingService);
+ ProfilingGuid inferenceGuid = m_ProfilingService.GetNextGuid();
if (timelineUtils)
{
// Add inference timeline trace if profiling is enabled.
bool executionSucceeded = true;
{
- if (profiling::ProfilingService::Instance().IsProfilingEnabled())
+ if (m_ProfilingService.IsProfilingEnabled())
{
- profiling::ProfilingService::Instance().IncrementCounterValue(armnn::profiling::INFERENCES_RUN);
+ m_ProfilingService.IncrementCounterValue(armnn::profiling::INFERENCES_RUN);
}
ARMNN_SCOPED_PROFILING_EVENT(Compute::Undefined, "Execute");
ARMNN_SCOPED_HEAP_PROFILING("Executing");
BOOST_ASSERT_MSG(inputWorkload, "No input workload created");
- std::unique_ptr<TimelineUtilityMethods> timelineUtils = TimelineUtilityMethods::GetTimelineUtils();
+ std::unique_ptr<TimelineUtilityMethods> timelineUtils =
+ TimelineUtilityMethods::GetTimelineUtils(m_ProfilingService);
if (timelineUtils)
{
// Add Input Workload to the post-optimisation network structure
std::make_unique<CopyMemGenericWorkload>(outputQueueDescriptor, info);
BOOST_ASSERT_MSG(outputWorkload, "No output workload created");
- std::unique_ptr<TimelineUtilityMethods> timelineUtils = TimelineUtilityMethods::GetTimelineUtils();
+ std::unique_ptr<TimelineUtilityMethods> timelineUtils =
+ TimelineUtilityMethods::GetTimelineUtils(m_ProfilingService);
if (timelineUtils)
{
// Add Output Workload to the post-optimisation network structure
#include <backendsCommon/TensorHandleFactoryRegistry.hpp>
#include <backendsCommon/Workload.hpp>
#include <backendsCommon/WorkloadFactory.hpp>
+#include <ProfilingService.hpp>
#include <TimelineUtilityMethods.hpp>
#include <mutex>
static std::unique_ptr<LoadedNetwork> MakeLoadedNetwork(std::unique_ptr<OptimizedNetwork> net,
std::string & errorMessage,
- const INetworkProperties& networkProperties);
+ const INetworkProperties& networkProperties,
+ profiling::ProfilingService& profilingService);
// NOTE we return by reference as the purpose of this method is only to provide
// access to the private m_Profiler and in theory we should not need to increment
private:
void AllocateWorkingMemory();
- LoadedNetwork(std::unique_ptr<OptimizedNetwork> net, const INetworkProperties& networkProperties);
+ LoadedNetwork(std::unique_ptr<OptimizedNetwork> net,
+ const INetworkProperties& networkProperties,
+ profiling::ProfilingService& profilingService);
void EnqueueInput(const BindableLayer& layer, ITensorHandle* tensorHandle, const TensorInfo& tensorInfo);
bool m_IsExportEnabled=false;
TensorHandleFactoryRegistry m_TensorHandleFactoryRegistry;
+
+ profiling::ProfilingService& m_ProfilingService;
};
}
}
Network::Network()
-: m_Graph(std::make_unique<Graph>()),
- m_Guid(profiling::ProfilingService::Instance().NextGuid())
+: m_Graph(std::make_unique<Graph>())
{
}
}
OptimizedNetwork::OptimizedNetwork(std::unique_ptr<Graph> graph)
- : m_Graph(std::move(graph)),
- m_Guid(profiling::ProfilingService::Instance().NextGuid())
+ : m_Graph(std::move(graph)), m_Guid(profiling::ProfilingService::GetNextGuid())
{
}
Status PrintGraph() override;
- profiling::ProfilingGuid GetGuid() const final { return m_Guid; };
-
IConnectableLayer* AddInputLayer(LayerBindingId id, const char* name=nullptr) override;
IConnectableLayer* AddArgMinMaxLayer(const ArgMinMaxDescriptor& desc,
const char* name);
std::unique_ptr<Graph> m_Graph;
- profiling::ProfilingGuid m_Guid;
};
class OptimizedNetwork final : public IOptimizedNetwork
#include <armnn/backends/IBackendContext.hpp>
#include <backendsCommon/DynamicBackendUtils.hpp>
-#include <ProfilingService.hpp>
-
#include <iostream>
#include <boost/polymorphic_cast.hpp>
unique_ptr<LoadedNetwork> loadedNetwork = LoadedNetwork::MakeLoadedNetwork(
std::unique_ptr<OptimizedNetwork>(boost::polymorphic_downcast<OptimizedNetwork*>(rawNetwork)),
errorMessage,
- networkProperties);
+ networkProperties,
+ m_ProfilingService);
if (!loadedNetwork)
{
context.second->AfterLoadNetwork(networkIdOut);
}
- if (profiling::ProfilingService::Instance().IsProfilingEnabled())
+ if (m_ProfilingService.IsProfilingEnabled())
{
- profiling::ProfilingService::Instance().IncrementCounterValue(armnn::profiling::NETWORK_LOADS);
+ m_ProfilingService.IncrementCounterValue(armnn::profiling::NETWORK_LOADS);
}
return Status::Success;
ARMNN_LOG(warning) << "WARNING: Runtime::UnloadNetwork(): " << networkId << " not found!";
return Status::Failure;
}
- if (profiling::ProfilingService::Instance().IsProfilingEnabled())
+
+ if (m_ProfilingService.IsProfilingEnabled())
{
- profiling::ProfilingService::Instance().IncrementCounterValue(armnn::profiling::NETWORK_UNLOADS);
+ m_ProfilingService.IncrementCounterValue(armnn::profiling::NETWORK_UNLOADS);
}
}
ARMNN_LOG(info) << "ArmNN v" << ARMNN_VERSION << "\n";
// pass configuration info to the profiling service
- armnn::profiling::ProfilingService::Instance().ConfigureProfilingService(options.m_ProfilingOptions);
+ m_ProfilingService.ConfigureProfilingService(options.m_ProfilingOptions);
// Load any available/compatible dynamic backend before the runtime
// goes through the backend registry
unique_ptr<armnn::profiling::IBackendProfiling> profilingIface =
std::make_unique<armnn::profiling::BackendProfiling>(armnn::profiling::BackendProfiling(
- options, armnn::profiling::ProfilingService::Instance(), id));
+ options, m_ProfilingService, id));
// Backends may also provide a profiling context. Ask for it now.
auto profilingContext = backend->CreateBackendProfilingContext(options, profilingIface);
if(profilingContext->EnableProfiling(true))
{
// Pass the context onto the profiling service.
- armnn::profiling::ProfilingService::Instance().AddBackendProfilingContext(id, profilingContext);
+ m_ProfilingService.AddBackendProfilingContext(id, profilingContext);
}
else
{
#include <armnn/backends/DynamicBackend.hpp>
+#include <ProfilingService.hpp>
+
#include <mutex>
#include <unordered_map>
private:
friend void RuntimeLoadedNetworksReserve(armnn::Runtime* runtime); // See RuntimeTests.cpp
+ friend profiling::ProfilingService& GetProfilingService(armnn::Runtime* runtime); // See RuntimeTests.cpp
+
int GenerateNetworkId();
LoadedNetwork* GetLoadedNetworkPtr(NetworkId networkId) const;
/// List of dynamic backends loaded in the runtime
std::vector<DynamicBackendPtr> m_DynamicBackends;
+
+ /// Profiling Service Instance
+ profiling::ProfilingService m_ProfilingService;
};
} // namespace armnn
runtime->m_LoadedNetworks.reserve(1);
}
+profiling::ProfilingService& GetProfilingService(armnn::Runtime* runtime)
+{
+ return runtime->m_ProfilingService;
+}
+
}
BOOST_AUTO_TEST_SUITE(Runtime)
// Create runtime in which the test will run
armnn::IRuntime::CreationOptions options;
- armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options));
+ armnn::Runtime runtime(options);
// build up the structure of the network
INetworkPtr net(INetwork::Create());
// optimize the network
std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
- IOptimizedNetworkPtr optNet = Optimize(*net, backends, runtime->GetDeviceSpec());
+ IOptimizedNetworkPtr optNet = Optimize(*net, backends, runtime.GetDeviceSpec());
// Load it into the runtime. It should succeed.
armnn::NetworkId netId;
- BOOST_TEST(runtime->LoadNetwork(netId, std::move(optNet)) == Status::Success);
+ BOOST_TEST(runtime.LoadNetwork(netId, std::move(optNet)) == Status::Success);
- profiling::ProfilingServiceRuntimeHelper profilingServiceHelper;
+ profiling::ProfilingServiceRuntimeHelper profilingServiceHelper(GetProfilingService(&runtime));
profiling::BufferManager& bufferManager = profilingServiceHelper.GetProfilingBufferManager();
auto readableBuffer = bufferManager.GetReadableBuffer();
// Create runtime in which the test will run
armnn::IRuntime::CreationOptions options;
options.m_ProfilingOptions.m_EnableProfiling = true;
- armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options));
+ armnn::Runtime runtime(options);
// build up the structure of the network
INetworkPtr net(INetwork::Create());
// optimize the network
std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
- IOptimizedNetworkPtr optNet = Optimize(*net, backends, runtime->GetDeviceSpec());
+ IOptimizedNetworkPtr optNet = Optimize(*net, backends, runtime.GetDeviceSpec());
ProfilingGuid optNetGuid = optNet->GetGuid();
// Load it into the runtime. It should succeed.
armnn::NetworkId netId;
- BOOST_TEST(runtime->LoadNetwork(netId, std::move(optNet)) == Status::Success);
+ BOOST_TEST(runtime.LoadNetwork(netId, std::move(optNet)) == Status::Success);
- profiling::ProfilingServiceRuntimeHelper profilingServiceHelper;
+ profiling::ProfilingServiceRuntimeHelper profilingServiceHelper(GetProfilingService(&runtime));
profiling::BufferManager& bufferManager = profilingServiceHelper.GetProfilingBufferManager();
auto readableBuffer = bufferManager.GetReadableBuffer();
InputTensors inputTensors
{
- { 0, ConstTensor(runtime->GetInputTensorInfo(netId, 0), inputData.data()) }
+ {0, ConstTensor(runtime.GetInputTensorInfo(netId, 0), inputData.data())}
};
OutputTensors outputTensors
{
- { 0, Tensor(runtime->GetOutputTensorInfo(netId, 0), outputData.data()) }
+ {0, Tensor(runtime.GetOutputTensorInfo(netId, 0), outputData.data())}
};
// Does the inference.
- runtime->EnqueueWorkload(netId, inputTensors, outputTensors);
+ runtime.EnqueueWorkload(netId, inputTensors, outputTensors);
// Get readable buffer for inference timeline
auto inferenceReadableBuffer = bufferManager.GetReadableBuffer();
BaseWorkload(const QueueDescriptor& descriptor, const WorkloadInfo& info)
: m_Data(descriptor),
- m_Guid(profiling::ProfilingService::Instance().NextGuid())
+ m_Guid(profiling::ProfilingService::GetNextGuid())
{
m_Data.Validate(info);
}
#include "ProfilingUtils.hpp"
#include "RequestCounterDirectoryCommandHandler.hpp"
+#include <Runtime.hpp>
+
#include <armnn/utility/IgnoreUnused.hpp>
#include <armnn/BackendId.hpp>
#include <armnn/Logging.hpp>
{
// Reset the profiling service to the uninitialized state
armnn::IRuntime::CreationOptions options;
- options.m_ProfilingOptions.m_EnableProfiling = true;
- armnn::profiling::ProfilingService& profilingService = armnn::profiling::ProfilingService::Instance();
- profilingService.ConfigureProfilingService(options.m_ProfilingOptions, true);
+ options.m_ProfilingOptions.m_EnableProfiling = true;;
armnn::MockBackendInitialiser initialiser;
// Create a runtime
- armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options));
+// armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options));
+ armnn::Runtime runtime(options);
// Check if the MockBackends 3 dummy counters {0, 1, 2-5 (four cores)} are registered
armnn::BackendId mockId = armnn::MockBackendId();
- const armnn::profiling::ICounterMappings& counterMap = profilingService.GetCounterMappings();
+ const armnn::profiling::ICounterMappings& counterMap = GetProfilingService(&runtime).GetCounterMappings();
BOOST_CHECK(counterMap.GetGlobalId(0, mockId) == 5);
BOOST_CHECK(counterMap.GetGlobalId(1, mockId) == 6);
BOOST_CHECK(counterMap.GetGlobalId(2, mockId) == 7);
BOOST_CHECK(counterMap.GetGlobalId(4, mockId) == 9);
BOOST_CHECK(counterMap.GetGlobalId(5, mockId) == 10);
options.m_ProfilingOptions.m_EnableProfiling = false;
- profilingService.ResetExternalProfilingOptions(options.m_ProfilingOptions, true);
+ GetProfilingService(&runtime).ResetExternalProfilingOptions(options.m_ProfilingOptions, true);
}
BOOST_AUTO_TEST_CASE(TestBackendCounters)
armnn::IRuntime::CreationOptions options;
options.m_ProfilingOptions.m_EnableProfiling = true;
- armnn::profiling::ProfilingService& profilingService = armnn::profiling::ProfilingService::Instance();
+ armnn::profiling::ProfilingService profilingService;
std::unique_ptr<armnn::profiling::IBackendProfiling> cpuBackendProfilingPtr =
std::make_unique<BackendProfiling>(options, profilingService, cpuAccId);
armnn::IRuntime::CreationOptions options;
options.m_ProfilingOptions.m_EnableProfiling = true;
- armnn::profiling::ProfilingService& profilingService = armnn::profiling::ProfilingService::Instance();
+ armnn::profiling::ProfilingService profilingService;
std::unique_ptr<armnn::profiling::IBackendProfiling> cpuBackendProfilingPtr =
std::make_unique<BackendProfiling>(options, profilingService, cpuAccId);
// Reset the profiling service to the uninitialized state
armnn::IRuntime::CreationOptions options;
options.m_ProfilingOptions.m_EnableProfiling = true;
- armnn::profiling::ProfilingService& profilingService = armnn::profiling::ProfilingService::Instance();
+ armnn::profiling::ProfilingService profilingService;
profilingService.ConfigureProfilingService(options.m_ProfilingOptions, true);
armnn::MockBackendInitialiser initialiser;
// Reset the profiling service to the uninitialized state
armnn::IRuntime::CreationOptions options;
options.m_ProfilingOptions.m_EnableProfiling = true;
- armnn::profiling::ProfilingService& profilingService = armnn::profiling::ProfilingService::Instance();
- profilingService.ConfigureProfilingService(options.m_ProfilingOptions, true);
armnn::MockBackendInitialiser initialiser;
// Create a runtime. During this the mock backend will be registered and context returned.
// Reset the profiling servie after the test.
options.m_ProfilingOptions.m_EnableProfiling = false;
- profilingService.ResetExternalProfilingOptions(options.m_ProfilingOptions, true);
}
BOOST_AUTO_TEST_SUITE_END()
namespace profiling
{
+ProfilingGuidGenerator ProfilingService::m_GuidGenerator;
+
+ProfilingDynamicGuid ProfilingService::GetNextGuid()
+{
+ return m_GuidGenerator.NextGuid();
+}
+
+ProfilingStaticGuid ProfilingService::GetStaticId(const std::string& str)
+{
+ return m_GuidGenerator.GenerateStaticId(str);
+}
+
void ProfilingService::ResetExternalProfilingOptions(const ExternalProfilingOptions& options,
bool resetProfilingService)
{
ProfilingDynamicGuid ProfilingService::NextGuid()
{
- return m_GuidGenerator.NextGuid();
+ return ProfilingService::GetNextGuid();
}
ProfilingStaticGuid ProfilingService::GenerateStaticId(const std::string& str)
{
- return m_GuidGenerator.GenerateStaticId(str);
+ return ProfilingService::GetStaticId(str);
}
std::unique_ptr<ISendTimelinePacket> ProfilingService::GetSendTimelinePacket() const
using CounterIndices = std::vector<std::atomic<uint32_t>*>;
using CounterValues = std::list<std::atomic<uint32_t>>;
- // Getter for the singleton instance
- static ProfilingService& Instance()
+ // Default constructor/destructor kept protected for testing
+ ProfilingService()
+ : m_Options()
+ , m_CounterDirectory()
+ , m_ProfilingConnectionFactory(new ProfilingConnectionFactory())
+ , m_ProfilingConnection()
+ , m_StateMachine()
+ , m_CounterIndex()
+ , m_CounterValues()
+ , m_CommandHandlerRegistry()
+ , m_PacketVersionResolver()
+ , m_CommandHandler(1000,
+ false,
+ m_CommandHandlerRegistry,
+ m_PacketVersionResolver)
+ , m_BufferManager()
+ , m_SendCounterPacket(m_BufferManager)
+ , m_SendThread(m_StateMachine, m_BufferManager, m_SendCounterPacket)
+ , m_SendTimelinePacket(m_BufferManager)
+ , m_PeriodicCounterCapture(m_Holder, m_SendCounterPacket, *this, m_CounterIdMap, m_BackendProfilingContexts)
+ , m_ConnectionAcknowledgedCommandHandler(0,
+ 1,
+ m_PacketVersionResolver.ResolvePacketVersion(0, 1).GetEncodedValue(),
+ m_CounterDirectory,
+ m_SendCounterPacket,
+ m_SendTimelinePacket,
+ m_StateMachine)
+ , m_RequestCounterDirectoryCommandHandler(0,
+ 3,
+ m_PacketVersionResolver.ResolvePacketVersion(0, 3).GetEncodedValue(),
+ m_CounterDirectory,
+ m_SendCounterPacket,
+ m_SendTimelinePacket,
+ m_StateMachine)
+ , m_PeriodicCounterSelectionCommandHandler(0,
+ 4,
+ m_PacketVersionResolver.ResolvePacketVersion(0, 4).GetEncodedValue(),
+ m_BackendProfilingContexts,
+ m_CounterIdMap,
+ m_Holder,
+ MAX_ARMNN_COUNTER,
+ m_PeriodicCounterCapture,
+ *this,
+ m_SendCounterPacket,
+ m_StateMachine)
+ , m_PerJobCounterSelectionCommandHandler(0,
+ 5,
+ m_PacketVersionResolver.ResolvePacketVersion(0, 5).GetEncodedValue(),
+ m_StateMachine)
+ , m_TimelinePacketWriterFactory(m_BufferManager)
+ , m_MaxGlobalCounterId(armnn::profiling::INFERENCES_RUN)
{
- static ProfilingService instance;
- return instance;
+ // Register the "Connection Acknowledged" command handler
+ m_CommandHandlerRegistry.RegisterFunctor(&m_ConnectionAcknowledgedCommandHandler);
+
+ // Register the "Request Counter Directory" command handler
+ m_CommandHandlerRegistry.RegisterFunctor(&m_RequestCounterDirectoryCommandHandler);
+
+ // Register the "Periodic Counter Selection" command handler
+ m_CommandHandlerRegistry.RegisterFunctor(&m_PeriodicCounterSelectionCommandHandler);
+
+ // Register the "Per-Job Counter Selection" command handler
+ m_CommandHandlerRegistry.RegisterFunctor(&m_PerJobCounterSelectionCommandHandler);
}
+ ~ProfilingService();
+
// Resets the profiling options, optionally clears the profiling service entirely
void ResetExternalProfilingOptions(const ExternalProfilingOptions& options, bool resetProfilingService = false);
ProfilingState ConfigureProfilingService(const ExternalProfilingOptions& options,
/// Check if the profiling is enabled
bool IsEnabled() { return m_Options.m_EnableProfiling; }
+ static ProfilingDynamicGuid GetNextGuid();
+
+ static ProfilingStaticGuid GetStaticId(const std::string& str);
+
private:
- // Copy/move constructors/destructors and copy/move assignment operators are deleted
+ //Copy/move constructors/destructors and copy/move assignment operators are deleted
ProfilingService(const ProfilingService&) = delete;
ProfilingService(ProfilingService&&) = delete;
ProfilingService& operator=(const ProfilingService&) = delete;
RequestCounterDirectoryCommandHandler m_RequestCounterDirectoryCommandHandler;
PeriodicCounterSelectionCommandHandler m_PeriodicCounterSelectionCommandHandler;
PerJobCounterSelectionCommandHandler m_PerJobCounterSelectionCommandHandler;
- ProfilingGuidGenerator m_GuidGenerator;
+
TimelinePacketWriterFactory m_TimelinePacketWriterFactory;
std::unordered_map<BackendId,
std::shared_ptr<armnn::profiling::IBackendProfilingContext>> m_BackendProfilingContexts;
uint16_t m_MaxGlobalCounterId;
-protected:
- // Default constructor/destructor kept protected for testing
- ProfilingService()
- : m_Options()
- , m_CounterDirectory()
- , m_ProfilingConnectionFactory(new ProfilingConnectionFactory())
- , m_ProfilingConnection()
- , m_StateMachine()
- , m_CounterIndex()
- , m_CounterValues()
- , m_CommandHandlerRegistry()
- , m_PacketVersionResolver()
- , m_CommandHandler(1000,
- false,
- m_CommandHandlerRegistry,
- m_PacketVersionResolver)
- , m_BufferManager()
- , m_SendCounterPacket(m_BufferManager)
- , m_SendThread(m_StateMachine, m_BufferManager, m_SendCounterPacket)
- , m_SendTimelinePacket(m_BufferManager)
- , m_PeriodicCounterCapture(m_Holder, m_SendCounterPacket, *this, m_CounterIdMap, m_BackendProfilingContexts)
- , m_ConnectionAcknowledgedCommandHandler(0,
- 1,
- m_PacketVersionResolver.ResolvePacketVersion(0, 1).GetEncodedValue(),
- m_CounterDirectory,
- m_SendCounterPacket,
- m_SendTimelinePacket,
- m_StateMachine)
- , m_RequestCounterDirectoryCommandHandler(0,
- 3,
- m_PacketVersionResolver.ResolvePacketVersion(0, 3).GetEncodedValue(),
- m_CounterDirectory,
- m_SendCounterPacket,
- m_SendTimelinePacket,
- m_StateMachine)
- , m_PeriodicCounterSelectionCommandHandler(0,
- 4,
- m_PacketVersionResolver.ResolvePacketVersion(0, 4).GetEncodedValue(),
- m_BackendProfilingContexts,
- m_CounterIdMap,
- m_Holder,
- MAX_ARMNN_COUNTER,
- m_PeriodicCounterCapture,
- *this,
- m_SendCounterPacket,
- m_StateMachine)
- , m_PerJobCounterSelectionCommandHandler(0,
- 5,
- m_PacketVersionResolver.ResolvePacketVersion(0, 5).GetEncodedValue(),
- m_StateMachine)
- , m_TimelinePacketWriterFactory(m_BufferManager)
- , m_MaxGlobalCounterId(armnn::profiling::INFERENCES_RUN)
- {
- // Register the "Connection Acknowledged" command handler
- m_CommandHandlerRegistry.RegisterFunctor(&m_ConnectionAcknowledgedCommandHandler);
-
- // Register the "Request Counter Directory" command handler
- m_CommandHandlerRegistry.RegisterFunctor(&m_RequestCounterDirectoryCommandHandler);
+ static ProfilingGuidGenerator m_GuidGenerator;
- // Register the "Periodic Counter Selection" command handler
- m_CommandHandlerRegistry.RegisterFunctor(&m_PeriodicCounterSelectionCommandHandler);
-
- // Register the "Per-Job Counter Selection" command handler
- m_CommandHandlerRegistry.RegisterFunctor(&m_PerJobCounterSelectionCommandHandler);
- }
- ~ProfilingService();
+protected:
// Protected methods for testing
void SwapProfilingConnectionFactory(ProfilingService& instance,
counterSetUid);
m_CurrentMaxGlobalCounterID = counterPtr->m_MaxCounterUid;
// register mappings
- IRegisterCounterMapping& counterIdMap = ProfilingService::Instance().GetCounterMappingRegistry();
+ IRegisterCounterMapping& counterIdMap = m_ProfilingService.GetCounterMappingRegistry();
uint16_t globalCounterId = counterPtr->m_Uid;
if (globalCounterId == counterPtr->m_MaxCounterUid)
{
{
public:
- RegisterBackendCounters(uint16_t currentMaxGlobalCounterID, const BackendId& backendId)
- : m_CurrentMaxGlobalCounterID(currentMaxGlobalCounterID),
- m_CounterDirectory(ProfilingService::Instance().GetCounterRegistry()),
- m_BackendId(backendId) {}
+ RegisterBackendCounters(
+ uint16_t currentMaxGlobalCounterID, const BackendId& backendId, ProfilingService& profilingService)
+ : m_CurrentMaxGlobalCounterID(currentMaxGlobalCounterID),
+ m_BackendId(backendId),
+ m_ProfilingService(profilingService),
+ m_CounterDirectory(m_ProfilingService.GetCounterRegistry()) {}
~RegisterBackendCounters() = default;
private:
uint16_t m_CurrentMaxGlobalCounterID;
- ICounterRegistry& m_CounterDirectory;
const BackendId& m_BackendId;
+ ProfilingService& m_ProfilingService;
+ ICounterRegistry& m_CounterDirectory;
};
} // namespace profiling
//
#include "TimelineUtilityMethods.hpp"
-#include "ProfilingService.hpp"
#include "LabelsAndEventClasses.hpp"
namespace armnn
namespace profiling
{
-std::unique_ptr<TimelineUtilityMethods> TimelineUtilityMethods::GetTimelineUtils()
+std::unique_ptr<TimelineUtilityMethods> TimelineUtilityMethods::GetTimelineUtils(ProfilingService& profilingService)
{
- if (ProfilingService::Instance().IsEnabled())
+ if (profilingService.IsProfilingEnabled())
{
- std::unique_ptr<ISendTimelinePacket> sendTimelinepacket = ProfilingService::Instance().GetSendTimelinePacket();
- return std::make_unique<TimelineUtilityMethods>(sendTimelinepacket);
+ std::unique_ptr<ISendTimelinePacket> sendTimelinepacket = profilingService.GetSendTimelinePacket();
+ return std::make_unique<TimelineUtilityMethods>(sendTimelinepacket, profilingService);
}
else
{
}
// Generate dynamic GUID of the entity
- ProfilingDynamicGuid entityGuid = ProfilingService::Instance().NextGuid();
+ ProfilingDynamicGuid entityGuid = m_ProfilingService.GetNextGuid();
CreateNamedTypedEntity(entityGuid, name, type);
}
// Generate a static GUID for the given label name
- ProfilingStaticGuid labelGuid = ProfilingService::Instance().GenerateStaticId(labelName);
+ ProfilingStaticGuid labelGuid = m_ProfilingService.GetStaticId(labelName);
// Send the new label to the external profiling service, this call throws in case of error
m_SendTimelinePacket->SendTimelineLabelBinaryPacket(labelGuid, labelName);
ProfilingStaticGuid labelGuid = DeclareLabel(labelName);
// Generate a GUID for the label relationship
- ProfilingDynamicGuid relationshipGuid = ProfilingService::Instance().NextGuid();
+ ProfilingDynamicGuid relationshipGuid = m_ProfilingService.GetNextGuid();
// Send the new label link to the external profiling service, this call throws in case of error
m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink,
labelGuid);
// Generate a GUID for the label relationship
- ProfilingDynamicGuid relationshipLabelGuid = ProfilingService::Instance().NextGuid();
+ ProfilingDynamicGuid relationshipLabelGuid = m_ProfilingService.GetNextGuid();
// Send the new label link to the external profiling service, this call throws in case of error
m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink,
ProfilingStaticGuid typeNameGuid)
{
// Generate a GUID for the label relationship
- ProfilingDynamicGuid relationshipGuid = ProfilingService::Instance().NextGuid();
+ ProfilingDynamicGuid relationshipGuid = m_ProfilingService.GetNextGuid();
// Send the new label link to the external profiling service, this call throws in case of error
m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink,
typeNameGuid);
// Generate a GUID for the label relationship
- ProfilingDynamicGuid relationshipLabelGuid = ProfilingService::Instance().NextGuid();
+ ProfilingDynamicGuid relationshipLabelGuid = m_ProfilingService.GetNextGuid();
// Send the new label link to the external profiling service, this call throws in case of error
m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink,
ProfilingDynamicGuid childEntityGuid = CreateNamedTypedEntity(entityName, entityType);
// Generate a GUID for the retention link relationship
- ProfilingDynamicGuid retentionLinkGuid = ProfilingService::Instance().NextGuid();
+ ProfilingDynamicGuid retentionLinkGuid = m_ProfilingService.GetNextGuid();
// Send the new retention link to the external profiling service, this call throws in case of error
m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::RetentionLink,
CreateNamedTypedEntity(childEntityGuid, entityName, entityType);
// Generate a GUID for the retention link relationship
- ProfilingDynamicGuid retentionLinkGuid = ProfilingService::Instance().NextGuid();
+ ProfilingDynamicGuid retentionLinkGuid = m_ProfilingService.GetNextGuid();
// Send the new retention link to the external profiling service, this call throws in case of error
m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::RetentionLink,
CreateNamedTypedEntity(childEntityGuid, entityName, typeGuid);
// Generate a GUID for the retention link relationship
- ProfilingDynamicGuid retentionLinkGuid = ProfilingService::Instance().NextGuid();
+ ProfilingDynamicGuid retentionLinkGuid = m_ProfilingService.GetNextGuid();
// Send the new retention link to the external profiling service, this call throws in case of error
m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::RetentionLink,
ProfilingGuid tailGuid)
{
// Generate a GUID for the relationship
- ProfilingDynamicGuid relationshipGuid = ProfilingService::Instance().NextGuid();
+ ProfilingDynamicGuid relationshipGuid = m_ProfilingService.GetNextGuid();
// Send the new retention link to the external profiling service, this call throws in case of error
m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(relationshipType,
ProfilingGuid tailGuid)
{
// Generate a GUID for the relationship
- ProfilingDynamicGuid relationshipGuid = ProfilingService::Instance().NextGuid();
+ ProfilingDynamicGuid relationshipGuid = m_ProfilingService.GetNextGuid();
// Send the new retention link to the external profiling service, this call throws in case of error
m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(relationshipType,
std::thread::id threadId = std::this_thread::get_id();
// Generate a GUID for the event
- ProfilingDynamicGuid eventGuid = ProfilingService::Instance().NextGuid();
+ ProfilingDynamicGuid eventGuid = m_ProfilingService.GetNextGuid();
// Send the new timeline event to the external profiling service, this call throws in case of error
m_SendTimelinePacket->SendTimelineEventBinaryPacket(timestamp, threadId, eventGuid);
// Generate a GUID for the execution link
- ProfilingDynamicGuid executionLinkId = ProfilingService::Instance().NextGuid();
+ ProfilingDynamicGuid executionLinkId = m_ProfilingService.GetNextGuid();
// Send the new execution link to the external profiling service, this call throws in case of error
m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::ExecutionLink,
eventGuid);
// Generate a GUID for the data relationship link
- ProfilingDynamicGuid eventClassLinkId = ProfilingService::Instance().NextGuid();
+ ProfilingDynamicGuid eventClassLinkId = m_ProfilingService.GetNextGuid();
// Send the new data relationship link to the external profiling service, this call throws in case of error
m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::DataLink,
ProfilingDynamicGuid TimelineUtilityMethods::RecordWorkloadInferenceAndStartOfLifeEvent(ProfilingGuid workloadGuid,
ProfilingGuid inferenceGuid)
{
- ProfilingDynamicGuid workloadInferenceGuid = ProfilingService::Instance().NextGuid();
+ ProfilingDynamicGuid workloadInferenceGuid = m_ProfilingService.GetNextGuid();
CreateTypedEntity(workloadInferenceGuid, LabelsAndEventClasses::WORKLOAD_EXECUTION_GUID);
CreateRelationship(ProfilingRelationshipType::RetentionLink, inferenceGuid, workloadInferenceGuid);
CreateRelationship(ProfilingRelationshipType::RetentionLink, workloadGuid, workloadInferenceGuid);
#pragma once
+#include "ProfilingService.hpp"
#include "armnn/profiling/ISendTimelinePacket.hpp"
+
#include <armnn/Types.hpp>
namespace armnn
// static factory method which will return a pointer to a timelie utility methods
// object if profiling is enabled. Otherwise will return a null unique_ptr
- static std::unique_ptr<TimelineUtilityMethods> GetTimelineUtils();
+ static std::unique_ptr<TimelineUtilityMethods> GetTimelineUtils(ProfilingService& profilingService);
- TimelineUtilityMethods(std::unique_ptr<ISendTimelinePacket>& sendTimelinePacket)
- : m_SendTimelinePacket(std::move(sendTimelinePacket)) {}
+ TimelineUtilityMethods(
+ std::unique_ptr<ISendTimelinePacket>& sendTimelinePacket, ProfilingService& profilingService)
+ : m_SendTimelinePacket(std::move(sendTimelinePacket)), m_ProfilingService(profilingService) {}
TimelineUtilityMethods(TimelineUtilityMethods&& other)
- : m_SendTimelinePacket(std::move(other.m_SendTimelinePacket)) {}
+ : m_SendTimelinePacket(std::move(other.m_SendTimelinePacket)), m_ProfilingService(other.m_ProfilingService) {}
TimelineUtilityMethods(const TimelineUtilityMethods& other) = delete;
private:
std::unique_ptr<ISendTimelinePacket> m_SendTimelinePacket;
+ profiling::ProfilingService& m_ProfilingService;
};
} // namespace profiling
std::unique_ptr<IRegisterBackendCounters>
BackendProfiling::GetCounterRegistrationInterface(uint16_t currentMaxGlobalCounterID)
{
- return std::make_unique<RegisterBackendCounters>(RegisterBackendCounters(currentMaxGlobalCounterID, m_BackendId));
+ return std::make_unique<RegisterBackendCounters>(
+ RegisterBackendCounters(currentMaxGlobalCounterID, m_BackendId, m_ProfilingService));
}
std::unique_ptr<ISendTimelinePacket> BackendProfiling::GetSendTimelinePacket()
for (auto globalCounterId : globalCounterIds) {
// Get pair of local counterId and backendId using globalCounterId
const std::pair<uint16_t, armnn::BackendId>& backendCounterIdPair =
- ProfilingService::Instance().GetCounterMappings().GetBackendId(globalCounterId);
+ m_ProfilingService.GetCounterMappings().GetBackendId(globalCounterId);
if (backendCounterIdPair.second == m_BackendId)
{
activeCounterIds.emplace_back(backendCounterIdPair.first,
#pragma once
-#include "IProfilingService.hpp"
+#include "ProfilingService.hpp"
#include <armnn/backends/profiling/IBackendProfiling.hpp>
namespace armnn
{
public:
BackendProfiling(const IRuntime::CreationOptions& options,
- IProfilingService& profilingService,
+ ProfilingService& profilingService,
const BackendId& backendId)
: m_Options(options),
m_ProfilingService(profilingService),
private:
IRuntime::CreationOptions m_Options;
- IProfilingService& m_ProfilingService;
+ ProfilingService& m_ProfilingService;
BackendId m_BackendId;
};
} // namespace profiling
// Wait for a notification from the send thread
bool WaitForPacketsSent(uint32_t timeout = 1000)
{
- return ProfilingService::WaitForPacketSent(ProfilingService::Instance(), timeout);
+ return ProfilingService::WaitForPacketSent(m_ProfilingService, timeout);
}
+ armnn::profiling::ProfilingService m_ProfilingService;
};
BOOST_AUTO_TEST_SUITE(FileOnlyProfilingDecoratorTests)
FileOnlyHelperService helper;
// Enable the profiling service
- ProfilingService& profilingService = ProfilingService::Instance();
+ armnn::profiling::ProfilingService profilingService;
profilingService.ResetExternalProfilingOptions(options, true);
// Bring the profiling service to the "WaitingForAck" state
profilingService.Update();
#include <Holder.hpp>
#include <IProfilingConnectionFactory.hpp>
-#include <IProfilingService.hpp>
+#include <ProfilingService.hpp>
#include <ProfilingGuidGenerator.hpp>
#include <ProfilingUtils.hpp>
#include <SendCounterPacket.hpp>
Counters m_Counters;
};
-class MockProfilingService : public IProfilingService, public IRegisterCounterMapping
+class MockProfilingService : public ProfilingService
{
public:
MockProfilingService(MockBufferManager& mockBufferManager,
void RegisterMapping(uint16_t globalCounterId,
uint16_t backendCounterId,
- const armnn::BackendId& backendId) override
+ const armnn::BackendId& backendId)
{
m_CounterMapping.RegisterMapping(globalCounterId, backendCounterId, backendId);
}
- void Reset() override
+ void Reset()
{
m_CounterMapping.Reset();
}
#include <armnn/Descriptors.hpp>
#include <LabelsAndEventClasses.hpp>
#include <ProfilingService.hpp>
+#include <Runtime.hpp>
#include <boost/test/unit_test.hpp>
}
else
{
- BOOST_CHECK(readProfilingGuid == ProfilingService::Instance().GenerateStaticId(label));
+ armnn::profiling::ProfilingService profilingService;
+ BOOST_CHECK(readProfilingGuid == profilingService.GetStaticId(label));
}
// Check the SWTrace label
// Create runtime in which test will run
armnn::IRuntime::CreationOptions options;
options.m_ProfilingOptions.m_EnableProfiling = true;
- armnn::profiling::ProfilingService& profilingService = armnn::profiling::ProfilingService::Instance();
- profilingService.ConfigureProfilingService(options.m_ProfilingOptions, true);
- armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options));
+// armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options));
+ armnn::Runtime runtime(options);
// build up the structure of the network
INetworkPtr net(INetwork::Create());
// optimize the network
std::vector<armnn::BackendId> backends = { backendId };
- IOptimizedNetworkPtr optNet = Optimize(*net, backends, runtime->GetDeviceSpec());
+ IOptimizedNetworkPtr optNet = Optimize(*net, backends, runtime.GetDeviceSpec());
ProfilingGuid optNetGuid = optNet->GetGuid();
// Load it into the runtime. It should success.
armnn::NetworkId netId;
- BOOST_TEST(runtime->LoadNetwork(netId, std::move(optNet)) == Status::Success);
+ BOOST_TEST(runtime.LoadNetwork(netId, std::move(optNet)) == Status::Success);
- profiling::ProfilingServiceRuntimeHelper profilingServiceHelper;
+ profiling::ProfilingServiceRuntimeHelper profilingServiceHelper(GetProfilingService(&runtime));
profiling::BufferManager& bufferManager = profilingServiceHelper.GetProfilingBufferManager();
auto readableBuffer = bufferManager.GetReadableBuffer();
InputTensors inputTensors
{
- { 0, ConstTensor(runtime->GetInputTensorInfo(netId, 0), inputData.data()) }
+ {0, ConstTensor(runtime.GetInputTensorInfo(netId, 0), inputData.data())}
};
OutputTensors outputTensors
{
- { 0, Tensor(runtime->GetOutputTensorInfo(netId, 0), outputData.data()) }
+ {0, Tensor(runtime.GetOutputTensorInfo(netId, 0), outputData.data())}
};
// Does the inference.
- runtime->EnqueueWorkload(netId, inputTensors, outputTensors);
+ runtime.EnqueueWorkload(netId, inputTensors, outputTensors);
// Get readable buffer for inference timeline
auto inferenceReadableBuffer = bufferManager.GetReadableBuffer();
class ProfilingServiceRuntimeHelper : public ProfilingService
{
public:
- ProfilingServiceRuntimeHelper() = default;
+ ProfilingServiceRuntimeHelper(ProfilingService& profilingService)
+ : m_ProfilingService(profilingService) {}
~ProfilingServiceRuntimeHelper() = default;
BufferManager& GetProfilingBufferManager()
{
- return GetBufferManager(ProfilingService::Instance());
+ return GetBufferManager(m_ProfilingService);
}
+ armnn::profiling::ProfilingService& m_ProfilingService;
};
} // namespace profiling
BOOST_AUTO_TEST_CASE(CheckProfilingServiceDisabled)
{
armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
- ProfilingService& profilingService = ProfilingService::Instance();
+ armnn::profiling::ProfilingService profilingService;
profilingService.ResetExternalProfilingOptions(options, true);
BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
profilingService.Update();
BOOST_AUTO_TEST_CASE(CheckProfilingServiceCounterDirectory)
{
armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
- ProfilingService& profilingService = ProfilingService::Instance();
+ armnn::profiling::ProfilingService profilingService;
profilingService.ResetExternalProfilingOptions(options, true);
const ICounterDirectory& counterDirectory0 = profilingService.GetCounterDirectory();
{
armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
options.m_EnableProfiling = true;
- ProfilingService& profilingService = ProfilingService::Instance();
+ armnn::profiling::ProfilingService profilingService;
profilingService.ResetExternalProfilingOptions(options, true);
profilingService.Update();
BOOST_AUTO_TEST_CASE(CheckProfilingServiceGoodConnectionAcknowledgedPacket)
{
- // Swap the profiling connection factory in the profiling service instance with our mock one
- SwapProfilingConnectionFactoryHelper helper;
-
// Calculate the size of a Stream Metadata packet
std::string processName = GetProcessName().substr(0, 60);
unsigned int processNameSize = processName.empty() ? 0 : boost::numeric_cast<unsigned int>(processName.size()) + 1;
// Reset the profiling service to the uninitialized state
armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
options.m_EnableProfiling = true;
- ProfilingService& profilingService = ProfilingService::Instance();
+ armnn::profiling::ProfilingService profilingService;
profilingService.ResetExternalProfilingOptions(options, true);
+ // Swap the profiling connection factory in the profiling service instance with our mock one
+ SwapProfilingConnectionFactoryHelper helper(profilingService);
+
// Bring the profiling service to the "WaitingForAck" state
BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
profilingService.Update(); // Initialize the counter directory
BOOST_AUTO_TEST_CASE(CheckProfilingServiceGoodRequestCounterDirectoryPacket)
{
- // Swap the profiling connection factory in the profiling service instance with our mock one
- SwapProfilingConnectionFactoryHelper helper;
-
// Reset the profiling service to the uninitialized state
armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
options.m_EnableProfiling = true;
- ProfilingService& profilingService = ProfilingService::Instance();
+ armnn::profiling::ProfilingService profilingService;
profilingService.ResetExternalProfilingOptions(options, true);
+ // Swap the profiling connection factory in the profiling service instance with our mock one
+ SwapProfilingConnectionFactoryHelper helper(profilingService);
+
// Bring the profiling service to the "Active" state
BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
profilingService.Update(); // Initialize the counter directory
BOOST_AUTO_TEST_CASE(CheckProfilingServiceBadPeriodicCounterSelectionPacketInvalidCounterUid)
{
- // Swap the profiling connection factory in the profiling service instance with our mock one
- SwapProfilingConnectionFactoryHelper helper;
-
// Reset the profiling service to the uninitialized state
armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
options.m_EnableProfiling = true;
- ProfilingService& profilingService = ProfilingService::Instance();
+ armnn::profiling::ProfilingService profilingService;
profilingService.ResetExternalProfilingOptions(options, true);
+ // Swap the profiling connection factory in the profiling service instance with our mock one
+ SwapProfilingConnectionFactoryHelper helper(profilingService);
+
// Bring the profiling service to the "Active" state
BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
profilingService.Update(); // Initialize the counter directory
BOOST_AUTO_TEST_CASE(CheckProfilingServiceGoodPeriodicCounterSelectionPacketNoCounters)
{
- // Swap the profiling connection factory in the profiling service instance with our mock one
- SwapProfilingConnectionFactoryHelper helper;
-
// Reset the profiling service to the uninitialized state
armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
options.m_EnableProfiling = true;
- ProfilingService& profilingService = ProfilingService::Instance();
+ armnn::profiling::ProfilingService profilingService;
profilingService.ResetExternalProfilingOptions(options, true);
+ // Swap the profiling connection factory in the profiling service instance with our mock one
+ SwapProfilingConnectionFactoryHelper helper(profilingService);
+
// Bring the profiling service to the "Active" state
BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
profilingService.Update(); // Initialize the counter directory
BOOST_AUTO_TEST_CASE(CheckProfilingServiceGoodPeriodicCounterSelectionPacketSingleCounter)
{
- // Swap the profiling connection factory in the profiling service instance with our mock one
- SwapProfilingConnectionFactoryHelper helper;
-
// Reset the profiling service to the uninitialized state
armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
options.m_EnableProfiling = true;
- ProfilingService& profilingService = ProfilingService::Instance();
+ armnn::profiling::ProfilingService profilingService;
profilingService.ResetExternalProfilingOptions(options, true);
+ // Swap the profiling connection factory in the profiling service instance with our mock one
+ SwapProfilingConnectionFactoryHelper helper(profilingService);
+
// Bring the profiling service to the "Active" state
BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
profilingService.Update(); // Initialize the counter directory
BOOST_AUTO_TEST_CASE(CheckProfilingServiceGoodPeriodicCounterSelectionPacketMultipleCounters)
{
- // Swap the profiling connection factory in the profiling service instance with our mock one
- SwapProfilingConnectionFactoryHelper helper;
// Reset the profiling service to the uninitialized state
armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
options.m_EnableProfiling = true;
- ProfilingService& profilingService = ProfilingService::Instance();
+ armnn::profiling::ProfilingService profilingService;
profilingService.ResetExternalProfilingOptions(options, true);
+ // Swap the profiling connection factory in the profiling service instance with our mock one
+ SwapProfilingConnectionFactoryHelper helper(profilingService);
+
// Bring the profiling service to the "Active" state
BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
profilingService.Update(); // Initialize the counter directory
BOOST_AUTO_TEST_CASE(CheckProfilingServiceDisconnect)
{
- // Swap the profiling connection factory in the profiling service instance with our mock one
- SwapProfilingConnectionFactoryHelper helper;
// Reset the profiling service to the uninitialized state
armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
options.m_EnableProfiling = true;
- ProfilingService& profilingService = ProfilingService::Instance();
+ armnn::profiling::ProfilingService profilingService;
profilingService.ResetExternalProfilingOptions(options, true);
+ // Swap the profiling connection factory in the profiling service instance with our mock one
+ SwapProfilingConnectionFactoryHelper helper(profilingService);
+
// Try to disconnect the profiling service while in the "Uninitialised" state
BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
profilingService.Disconnect();
BOOST_AUTO_TEST_CASE(CheckProfilingServiceGoodPerJobCounterSelectionPacket)
{
- // Swap the profiling connection factory in the profiling service instance with our mock one
- SwapProfilingConnectionFactoryHelper helper;
// Reset the profiling service to the uninitialized state
armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
options.m_EnableProfiling = true;
- ProfilingService& profilingService = ProfilingService::Instance();
+ armnn::profiling::ProfilingService profilingService;
profilingService.ResetExternalProfilingOptions(options, true);
+ // Swap the profiling connection factory in the profiling service instance with our mock one
+ SwapProfilingConnectionFactoryHelper helper(profilingService);
+
// Bring the profiling service to the "Active" state
BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
profilingService.Update(); // Initialize the counter directory
{
armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
options.m_EnableProfiling = true;
- ProfilingService& profilingService = ProfilingService::Instance();
+ armnn::profiling::ProfilingService profilingService;
BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
profilingService.ConfigureProfilingService(options);
// should get as far as NOT_CONNECTED
BOOST_AUTO_TEST_CASE(CheckConfigureProfilingServiceOff)
{
armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
- ProfilingService& profilingService = ProfilingService::Instance();
+ armnn::profiling::ProfilingService profilingService;
BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
profilingService.ConfigureProfilingService(options);
// should not move from Uninitialised
LogLevelSwapper logLevelSwapper(armnn::LogSeverity::Warning);
armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
options.m_EnableProfiling = true;
- ProfilingService& profilingService = ProfilingService::Instance();
+ armnn::profiling::ProfilingService profilingService;
profilingService.ResetExternalProfilingOptions(options, true);
BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
profilingService.Update();
// Locally reduce log level to "Warning", as this test needs to parse a warning message from the standard output
LogLevelSwapper logLevelSwapper(armnn::LogSeverity::Warning);
armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
- ProfilingService& profilingService = ProfilingService::Instance();
+ armnn::profiling::ProfilingService profilingService;
profilingService.ResetExternalProfilingOptions(options, true);
BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
profilingService.Update();
{
// Locally reduce log level to "Warning", as this test needs to parse a warning message from the standard output
LogLevelSwapper logLevelSwapper(armnn::LogSeverity::Warning);
- // Swap the profiling connection factory in the profiling service instance with our mock one
- SwapProfilingConnectionFactoryHelper helper;
+
// Redirect the standard output to a local stream so that we can parse the warning message
std::stringstream ss;
// Reset the profiling service to the uninitialized state
armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
options.m_EnableProfiling = true;
- ProfilingService& profilingService = ProfilingService::Instance();
+ armnn::profiling::ProfilingService profilingService;
profilingService.ResetExternalProfilingOptions(options, true);
+ // Swap the profiling connection factory in the profiling service instance with our mock one
+ SwapProfilingConnectionFactoryHelper helper(profilingService);
+
// Bring the profiling service to the "WaitingForAck" state
BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
profilingService.Update(); // Initialize the counter directory
{
// Locally reduce log level to "Warning", as this test needs to parse a warning message from the standard output
LogLevelSwapper logLevelSwapper(armnn::LogSeverity::Warning);
- // Swap the profiling connection factory in the profiling service instance with our mock one
- SwapProfilingConnectionFactoryHelper helper;
// Redirect the standard output to a local stream so that we can parse the warning message
std::stringstream ss;
// Reset the profiling service to the uninitialized state
armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
options.m_EnableProfiling = true;
- ProfilingService& profilingService = ProfilingService::Instance();
+ armnn::profiling::ProfilingService profilingService;
profilingService.ResetExternalProfilingOptions(options, true);
+ // Swap the profiling connection factory in the profiling service instance with our mock one
+ SwapProfilingConnectionFactoryHelper helper(profilingService);
+
// Bring the profiling service to the "Active" state
BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
helper.ForceTransitionToState(ProfilingState::NotConnected);
{
// Locally reduce log level to "Warning", as this test needs to parse a warning message from the standard output
LogLevelSwapper logLevelSwapper(armnn::LogSeverity::Warning);
- // Swap the profiling connection factory in the profiling service instance with our mock one
- SwapProfilingConnectionFactoryHelper helper;
// Redirect the standard output to a local stream so that we can parse the warning message
std::stringstream ss;
// Reset the profiling service to the uninitialized state
armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
options.m_EnableProfiling = true;
- ProfilingService& profilingService = ProfilingService::Instance();
+ armnn::profiling::ProfilingService profilingService;
profilingService.ResetExternalProfilingOptions(options, true);
+ // Swap the profiling connection factory in the profiling service instance with our mock one
+ SwapProfilingConnectionFactoryHelper helper(profilingService);
+
// Bring the profiling service to the "Active" state
BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
profilingService.Update(); // Initialize the counter directory
uint16_t globalCounterIds = armnn::profiling::INFERENCES_RUN;
armnn::BackendId cpuRefId(armnn::Compute::CpuRef);
- RegisterBackendCounters registerBackendCounters(globalCounterIds, cpuRefId);
-
// Reset the profiling service to the uninitialized state
armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
options.m_EnableProfiling = true;
- ProfilingService& profilingService = ProfilingService::Instance();
+ ProfilingService profilingService;
profilingService.ResetExternalProfilingOptions(options, true);
+ RegisterBackendCounters registerBackendCounters(globalCounterIds, cpuRefId, profilingService);
+
+
+
BOOST_CHECK(profilingService.GetCounterDirectory().GetCategories().empty());
registerBackendCounters.RegisterCategory("categoryOne");
auto categoryOnePtr = profilingService.GetCounterDirectory().GetCategory("categoryOne");
options.m_ProfilingOptions.m_EnableProfiling = true;
// Reset the profiling service to the uninitialized state
- ProfilingService& profilingService = ProfilingService::Instance();
+ ProfilingService profilingService;
profilingService.ResetExternalProfilingOptions(options.m_ProfilingOptions, true);
const armnn::BackendId cpuRefId(armnn::Compute::CpuRef);
uint16_t initialNumGlobalCounterIds = armnn::profiling::INFERENCES_RUN;
// Create RegisterBackendCounters for CpuRef
- RegisterBackendCounters registerBackendCountersCpuRef(initialNumGlobalCounterIds, cpuRefId);
+ RegisterBackendCounters registerBackendCountersCpuRef(initialNumGlobalCounterIds, cpuRefId, profilingService);
// Create 'testCategory' in CounterDirectory (backend agnostic)
BOOST_CHECK(profilingService.GetCounterDirectory().GetCategories().empty());
BOOST_CHECK(backendMapping.second == cpuRefId);
// Create RegisterBackendCounters for CpuAcc
- RegisterBackendCounters registerBackendCountersCpuAcc(currentNumGlobalCounterIds, cpuAccId);
+ RegisterBackendCounters registerBackendCountersCpuAcc(currentNumGlobalCounterIds, cpuAccId, profilingService);
// Register the backend counter for CpuAcc and validate GetGlobalId and GetBackendId
currentNumGlobalCounterIds = registerBackendCountersCpuAcc.RegisterCounter(
armnn::Runtime::CreationOptions options;
options.m_ProfilingOptions.m_EnableProfiling = true;
MockBufferManager mockBuffer(1024);
+
CaptureData captureData;
MockProfilingService mockProfilingService(
mockBuffer, options.m_ProfilingOptions.m_EnableProfiling, captureData);
public:
using MockProfilingConnectionFactoryPtr = std::unique_ptr<MockProfilingConnectionFactory>;
- SwapProfilingConnectionFactoryHelper()
+ SwapProfilingConnectionFactoryHelper(armnn::profiling::ProfilingService& profilingService)
: ProfilingService()
+ , m_ProfilingService(profilingService)
, m_MockProfilingConnectionFactory(new MockProfilingConnectionFactory())
, m_BackupProfilingConnectionFactory(nullptr)
+
{
BOOST_CHECK(m_MockProfilingConnectionFactory);
- SwapProfilingConnectionFactory(ProfilingService::Instance(),
+ SwapProfilingConnectionFactory(m_ProfilingService,
m_MockProfilingConnectionFactory.get(),
m_BackupProfilingConnectionFactory);
BOOST_CHECK(m_BackupProfilingConnectionFactory);
{
BOOST_CHECK(m_BackupProfilingConnectionFactory);
IProfilingConnectionFactory* temp = nullptr;
- SwapProfilingConnectionFactory(ProfilingService::Instance(),
+ SwapProfilingConnectionFactory(m_ProfilingService,
m_BackupProfilingConnectionFactory,
temp);
}
MockProfilingConnection* GetMockProfilingConnection()
{
- IProfilingConnection* profilingConnection = GetProfilingConnection(ProfilingService::Instance());
+ IProfilingConnection* profilingConnection = GetProfilingConnection(m_ProfilingService);
return boost::polymorphic_downcast<MockProfilingConnection*>(profilingConnection);
}
void ForceTransitionToState(ProfilingState newState)
{
- TransitionToState(ProfilingService::Instance(), newState);
+ TransitionToState(m_ProfilingService, newState);
}
long WaitForPacketsSent(MockProfilingConnection* mockProfilingConnection,
{
std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now();
// Wait for a notification from the send thread
- ProfilingService::WaitForPacketSent(ProfilingService::Instance(), timeout);
+ ProfilingService::WaitForPacketSent(m_ProfilingService, timeout);
std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();
}
private:
+ armnn::profiling::ProfilingService& m_ProfilingService;
MockProfilingConnectionFactoryPtr m_MockProfilingConnectionFactory;
IProfilingConnectionFactory* m_BackupProfilingConnectionFactory;
};
{
armnn::IRuntime::CreationOptions::ExternalProfilingOptions options;
options.m_EnableProfiling = true;
- ProfilingService& profilingService = ProfilingService::Instance();
+ armnn::profiling::ProfilingService profilingService;
profilingService.ResetExternalProfilingOptions(options, true);
- ProfilingStaticGuid staticGuid = profilingService.GenerateStaticId("dummy");
+ ProfilingStaticGuid staticGuid = profilingService.GetStaticId("dummy");
std::hash<std::string> hasher;
uint64_t hash = static_cast<uint64_t>(hasher("dummy"));
ProfilingStaticGuid expectedStaticValue(hash | MIN_STATIC_GUID);
BOOST_CHECK(staticGuid == expectedStaticValue);
- ProfilingDynamicGuid dynamicGuid = profilingService.NextGuid();
+ ProfilingDynamicGuid dynamicGuid = profilingService.GetNextGuid();
uint64_t dynamicGuidValue = static_cast<uint64_t>(dynamicGuid);
++dynamicGuidValue;
ProfilingDynamicGuid expectedDynamicValue(dynamicGuidValue);
- dynamicGuid = profilingService.NextGuid();
+ dynamicGuid = profilingService.GetNextGuid();
BOOST_CHECK(dynamicGuid == expectedDynamicValue);
}
{
armnn::IRuntime::CreationOptions::ExternalProfilingOptions options;
options.m_EnableProfiling = true;
- ProfilingService& profilingService = ProfilingService::Instance();
+ armnn::profiling::ProfilingService profilingService;
profilingService.ResetExternalProfilingOptions(options, true);
std::unique_ptr<ISendTimelinePacket> writer = profilingService.GetSendTimelinePacket();
BOOST_AUTO_TEST_CASE(CreateTypedLabelTest)
{
MockBufferManager mockBufferManager(1024);
+ ProfilingService profilingService;
+
std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = std::make_unique<SendTimelinePacket>(mockBufferManager);
- TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket);
+ TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket, profilingService);
// Generate first guid to ensure that the named typed entity guid is not 0 on local single test.
- ProfilingService::Instance().NextGuid();
+ profilingService.NextGuid();
ProfilingGuid entityGuid(123);
const std::string entityName = "some entity";
BOOST_AUTO_TEST_CASE(SendWellKnownLabelsAndEventClassesTest)
{
MockBufferManager mockBufferManager(1024);
+ ProfilingService profilingService;
std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = std::make_unique<SendTimelinePacket>(mockBufferManager);
- TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket);
+ TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket, profilingService);
BOOST_CHECK_NO_THROW(timelineUtilityMethods.SendWellKnownLabelsAndEventClasses());
BOOST_AUTO_TEST_CASE(CreateNamedTypedChildEntityTest)
{
MockBufferManager mockBufferManager(1024);
+ ProfilingService profilingService;
std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = std::make_unique<SendTimelinePacket>(mockBufferManager);
- TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket);
+ TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket, profilingService);
ProfilingDynamicGuid childEntityGuid(0);
ProfilingGuid parentEntityGuid(123);
const std::string entityType = "some type";
// Generate first guid to ensure that the named typed entity guid is not 0 on local single test.
- ProfilingService::Instance().NextGuid();
+ profilingService.NextGuid();
BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedChildEntity(parentEntityGuid, "", entityType),
InvalidArgumentException);
BOOST_AUTO_TEST_CASE(DeclareLabelTest)
{
MockBufferManager mockBufferManager(1024);
+ ProfilingService profilingService;
std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = std::make_unique<SendTimelinePacket>(mockBufferManager);
- TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket);
+ TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket, profilingService);
// Generate first guid to ensure that the named typed entity guid is not 0 on local single test.
- ProfilingService::Instance().NextGuid();
+ profilingService.NextGuid();
// Try declaring an invalid (empty) label
BOOST_CHECK_THROW(timelineUtilityMethods.DeclareLabel(""), InvalidArgumentException);
BOOST_AUTO_TEST_CASE(CreateNameTypeEntityInvalidTest)
{
MockBufferManager mockBufferManager(1024);
+ ProfilingService profilingService;
std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = std::make_unique<SendTimelinePacket>(mockBufferManager);
- TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket);
+ TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket, profilingService);
// Invalid name
BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedEntity("", "Type"), InvalidArgumentException);
// Invalid type
BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedEntity("Name", ""), InvalidArgumentException);
- ProfilingDynamicGuid guid = ProfilingService::Instance().NextGuid();
+ ProfilingDynamicGuid guid = profilingService.NextGuid();
// CreatedNamedTypedEntity with Guid - Invalid name
BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedEntity(guid, "", "Type"),
BOOST_AUTO_TEST_CASE(CreateNameTypeEntityTest)
{
MockBufferManager mockBufferManager(1024);
+ ProfilingService profilingService;
std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = std::make_unique<SendTimelinePacket>(mockBufferManager);
- TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket);
+ TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket, profilingService);
const std::string entityName = "Entity0";
const std::string entityType = "Type0";
// Generate first guid to ensure that the named typed entity guid is not 0 on local single test.
- ProfilingService::Instance().NextGuid();
+ profilingService.NextGuid();
ProfilingDynamicGuid guid = timelineUtilityMethods.CreateNamedTypedEntity(entityName, entityType);
BOOST_CHECK(guid != ProfilingGuid(0));
BOOST_AUTO_TEST_CASE(RecordEventTest)
{
MockBufferManager mockBufferManager(1024);
+ ProfilingService profilingService;
std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = std::make_unique<SendTimelinePacket>(mockBufferManager);
- TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket);
+ TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket, profilingService);
// Generate first guid to ensure that the named typed entity guid is not 0 on local single test.
- ProfilingService::Instance().NextGuid();
+ profilingService.NextGuid();
ProfilingGuid entityGuid(123);
ProfilingStaticGuid eventClassGuid(456);
// Enable the profiling service.
armnn::IRuntime::CreationOptions::ExternalProfilingOptions options;
options.m_EnableProfiling = true;
- profiling::ProfilingService& profilingService = profiling::ProfilingService::Instance();
+ armnn::profiling::ProfilingService profilingService;
profilingService.ResetExternalProfilingOptions(options, true);
// Bring the profiling service to the "WaitingForAck" state