From 3e9bc19ad523361e6b18057849e30c0c48183915 Mon Sep 17 00:00:00 2001 From: Jim Flynn Date: Wed, 23 Mar 2022 23:01:26 +0000 Subject: IVGCVSW-6706 Create the libpipeClient library Change-Id: I2368aade38ad3808fab55d8a86cd659d4e95d91e Signed-off-by: Jim Flynn --- profiling/client/src/backends/BackendProfiling.cpp | 97 ++++++++++++++++++++++ profiling/client/src/backends/BackendProfiling.hpp | 53 ++++++++++++ .../client/src/backends/IBackendProfiling.cpp | 24 ++++++ 3 files changed, 174 insertions(+) create mode 100644 profiling/client/src/backends/BackendProfiling.cpp create mode 100644 profiling/client/src/backends/BackendProfiling.hpp create mode 100644 profiling/client/src/backends/IBackendProfiling.cpp (limited to 'profiling/client/src/backends') diff --git a/profiling/client/src/backends/BackendProfiling.cpp b/profiling/client/src/backends/BackendProfiling.cpp new file mode 100644 index 0000000000..c33d5a738a --- /dev/null +++ b/profiling/client/src/backends/BackendProfiling.cpp @@ -0,0 +1,97 @@ +// +// Copyright © 2020 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include "BackendProfiling.hpp" +#include + +namespace arm +{ + +namespace pipe +{ + +std::unique_ptr + BackendProfiling::GetCounterRegistrationInterface(uint16_t currentMaxGlobalCounterID) +{ + return std::make_unique( + RegisterBackendCounters(currentMaxGlobalCounterID, m_BackendId, m_ProfilingService)); +} + +std::unique_ptr BackendProfiling::GetSendTimelinePacket() +{ + return m_ProfilingService.GetSendTimelinePacket(); +} + +IProfilingGuidGenerator& BackendProfiling::GetProfilingGuidGenerator() +{ + // The profiling service is our Guid Generator. + return m_ProfilingService; +} + +void BackendProfiling::ReportCounters(const std::vector& timestamps) +{ + for (const auto& timestampInfo : timestamps) + { + std::vector backendCounterValues = timestampInfo.counterValues; + for_each(backendCounterValues.begin(), backendCounterValues.end(), [&](CounterValue& backendCounterValue) + { + // translate the counterId to globalCounterId + backendCounterValue.counterId = m_ProfilingService.GetCounterMappings().GetGlobalId( + backendCounterValue.counterId, m_BackendId); + }); + + // Send Periodic Counter Capture Packet for the Timestamp + m_ProfilingService.GetSendCounterPacket().SendPeriodicCounterCapturePacket( + timestampInfo.timestamp, backendCounterValues); + } +} + +CounterStatus BackendProfiling::GetCounterStatus(uint16_t backendCounterId) +{ + uint16_t globalCounterId = m_ProfilingService.GetCounterMappings().GetGlobalId(backendCounterId, m_BackendId); + CaptureData captureData = m_ProfilingService.GetCaptureData(); + + CounterStatus counterStatus(backendCounterId, globalCounterId, false, 0); + + if (captureData.IsCounterIdInCaptureData(globalCounterId)) + { + counterStatus.m_Enabled = true; + counterStatus.m_SamplingRateInMicroseconds = captureData.GetCapturePeriod(); + } + + return counterStatus; +} + +std::vector BackendProfiling::GetActiveCounters() +{ + CaptureData captureData = m_ProfilingService.GetCaptureData(); + + const std::vector& globalCounterIds = captureData.GetCounterIds(); + std::vector activeCounterIds; + + for (auto globalCounterId : globalCounterIds) { + // Get pair of local counterId and backendId using globalCounterId + const std::pair& backendCounterIdPair = + m_ProfilingService.GetCounterMappings().GetBackendId(globalCounterId); + if (backendCounterIdPair.second == m_BackendId) + { + activeCounterIds.emplace_back(backendCounterIdPair.first, + globalCounterId, + true, + captureData.GetCapturePeriod()); + } + } + + return activeCounterIds; +} + +bool BackendProfiling::IsProfilingEnabled() const +{ + return m_ProfilingService.IsProfilingEnabled(); +} + +} // namespace pipe + +} // namespace arm diff --git a/profiling/client/src/backends/BackendProfiling.hpp b/profiling/client/src/backends/BackendProfiling.hpp new file mode 100644 index 0000000000..4db02f9573 --- /dev/null +++ b/profiling/client/src/backends/BackendProfiling.hpp @@ -0,0 +1,53 @@ +// +// Copyright © 2020 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#pragma once + +#include +#include + +namespace arm +{ + +namespace pipe +{ + +class BackendProfiling : public IBackendProfiling +{ +public: + BackendProfiling(const ProfilingOptions& options, + IProfilingService& profilingService, + const std::string& backendId) + : m_Options(options), + m_ProfilingService(profilingService), + m_BackendId(backendId) {} + + ~BackendProfiling() + {} + + std::unique_ptr + GetCounterRegistrationInterface(uint16_t currentMaxGlobalCounterID) override; + + std::unique_ptr GetSendTimelinePacket() override; + + IProfilingGuidGenerator& GetProfilingGuidGenerator() override; + + void ReportCounters(const std::vector&) override; + + CounterStatus GetCounterStatus(uint16_t backendCounterId) override; + + std::vector GetActiveCounters() override; + + bool IsProfilingEnabled() const override; + +private: + ProfilingOptions m_Options; + IProfilingService& m_ProfilingService; + std::string m_BackendId; +}; + +} // namespace pipe + +} // namespace arm diff --git a/profiling/client/src/backends/IBackendProfiling.cpp b/profiling/client/src/backends/IBackendProfiling.cpp new file mode 100644 index 0000000000..f172be9f51 --- /dev/null +++ b/profiling/client/src/backends/IBackendProfiling.cpp @@ -0,0 +1,24 @@ +// +// Copyright © 2022 Arm Ltd and Contributors. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include "BackendProfiling.hpp" + +#include + +namespace arm +{ + +namespace pipe +{ + +std::unique_ptr IBackendProfiling::CreateBackendProfiling(const ProfilingOptions& options, + IProfilingService& profilingService, + const std::string& backendId) +{ + return std::make_unique(options, profilingService, backendId); +} + +} // namespace pipe +} // namespace arm -- cgit v1.2.1