Keith Davis | 02356de | 2019-08-26 18:28:17 +0100 | [diff] [blame] | 1 | // |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 2 | // Copyright © 2019 Arm Ltd and Contributors. All rights reserved. |
Keith Davis | 02356de | 2019-08-26 18:28:17 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #pragma once |
| 7 | |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 8 | #include "ActivateTimelineReportingCommandHandler.hpp" |
Jim Flynn | 8b20065 | 2019-10-24 18:07:44 +0100 | [diff] [blame] | 9 | #include "BufferManager.hpp" |
| 10 | #include "CommandHandler.hpp" |
| 11 | #include "ConnectionAcknowledgedCommandHandler.hpp" |
FinnWilliamsArm | ce2d9d1 | 2019-09-18 10:28:16 +0100 | [diff] [blame] | 12 | #include "CounterDirectory.hpp" |
Jim Flynn | 8e0c7a6 | 2020-01-30 14:10:55 +0000 | [diff] [blame] | 13 | #include "CounterIdMap.hpp" |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 14 | #include "DeactivateTimelineReportingCommandHandler.hpp" |
Jim Flynn | 9789702 | 2020-02-02 12:52:59 +0000 | [diff] [blame] | 15 | #include "ICounterRegistry.hpp" |
Matteo Martincigh | e0e6efc | 2019-10-04 17:17:42 +0100 | [diff] [blame] | 16 | #include "ICounterValues.hpp" |
Jim Flynn | 4e755a5 | 2020-03-29 17:48:26 +0100 | [diff] [blame] | 17 | #include <armnn/profiling/ILocalPacketHandler.hpp> |
Jim Flynn | 6406355 | 2020-02-14 10:18:08 +0000 | [diff] [blame] | 18 | #include "IProfilingService.hpp" |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 19 | #include "IReportStructure.hpp" |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 20 | #include "PeriodicCounterCapture.hpp" |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 21 | #include "PeriodicCounterSelectionCommandHandler.hpp" |
Matteo Martincigh | 994b534 | 2019-10-11 17:19:56 +0100 | [diff] [blame] | 22 | #include "PerJobCounterSelectionCommandHandler.hpp" |
Jim Flynn | 8b20065 | 2019-10-24 18:07:44 +0100 | [diff] [blame] | 23 | #include "ProfilingConnectionFactory.hpp" |
Jim Flynn | 8b20065 | 2019-10-24 18:07:44 +0100 | [diff] [blame] | 24 | #include "ProfilingStateMachine.hpp" |
| 25 | #include "RequestCounterDirectoryCommandHandler.hpp" |
| 26 | #include "SendCounterPacket.hpp" |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 27 | #include "SendThread.hpp" |
Matteo Martincigh | cdfb941 | 2019-11-08 11:23:06 +0000 | [diff] [blame] | 28 | #include "SendTimelinePacket.hpp" |
Jim Flynn | 8b20065 | 2019-10-24 18:07:44 +0100 | [diff] [blame] | 29 | #include "TimelinePacketWriterFactory.hpp" |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 30 | #include "INotifyBackends.hpp" |
Colm Donelan | 1aff393 | 2020-02-05 17:48:59 +0000 | [diff] [blame] | 31 | #include <armnn/backends/profiling/IBackendProfilingContext.hpp> |
Keith Davis | 02356de | 2019-08-26 18:28:17 +0100 | [diff] [blame] | 32 | |
Nikhil Raj | 5b1bcc9 | 2021-06-08 12:31:50 +0100 | [diff] [blame] | 33 | #include <common/include/ProfilingGuidGenerator.hpp> |
| 34 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 35 | #include <list> |
| 36 | |
Keith Davis | 02356de | 2019-08-26 18:28:17 +0100 | [diff] [blame] | 37 | namespace armnn |
| 38 | { |
| 39 | |
| 40 | namespace profiling |
| 41 | { |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 42 | // Static constants describing ArmNN's counter UID's |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 43 | static const uint16_t NETWORK_LOADS = 0; |
| 44 | static const uint16_t NETWORK_UNLOADS = 1; |
| 45 | static const uint16_t REGISTERED_BACKENDS = 2; |
| 46 | static const uint16_t UNREGISTERED_BACKENDS = 3; |
| 47 | static const uint16_t INFERENCES_RUN = 4; |
| 48 | static const uint16_t MAX_ARMNN_COUNTER = INFERENCES_RUN; |
Keith Davis | 02356de | 2019-08-26 18:28:17 +0100 | [diff] [blame] | 49 | |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 50 | class ProfilingService : public IReadWriteCounterValues, public IProfilingService, public INotifyBackends |
Keith Davis | 02356de | 2019-08-26 18:28:17 +0100 | [diff] [blame] | 51 | { |
| 52 | public: |
Narumol Prangnawarat | 85ad78c | 2019-11-18 15:34:23 +0000 | [diff] [blame] | 53 | using ExternalProfilingOptions = IRuntime::CreationOptions::ExternalProfilingOptions; |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 54 | using IProfilingConnectionFactoryPtr = std::unique_ptr<IProfilingConnectionFactory>; |
Matteo Martincigh | a84edee | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 55 | using IProfilingConnectionPtr = std::unique_ptr<IProfilingConnection>; |
| 56 | using CounterIndices = std::vector<std::atomic<uint32_t>*>; |
| 57 | using CounterValues = std::list<std::atomic<uint32_t>>; |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 58 | using BackendProfilingContext = std::unordered_map<BackendId, |
| 59 | std::shared_ptr<armnn::profiling::IBackendProfilingContext>>; |
Keith Davis | 02356de | 2019-08-26 18:28:17 +0100 | [diff] [blame] | 60 | |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 61 | ProfilingService(Optional<IReportStructure&> reportStructure = EmptyOptional()) |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 62 | : m_Options() |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 63 | , m_TimelineReporting(false) |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 64 | , m_CounterDirectory() |
| 65 | , m_ProfilingConnectionFactory(new ProfilingConnectionFactory()) |
| 66 | , m_ProfilingConnection() |
| 67 | , m_StateMachine() |
| 68 | , m_CounterIndex() |
| 69 | , m_CounterValues() |
| 70 | , m_CommandHandlerRegistry() |
| 71 | , m_PacketVersionResolver() |
| 72 | , m_CommandHandler(1000, |
| 73 | false, |
| 74 | m_CommandHandlerRegistry, |
| 75 | m_PacketVersionResolver) |
| 76 | , m_BufferManager() |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 77 | , m_SendCounterPacket(m_BufferManager) |
| 78 | , m_SendThread(m_StateMachine, m_BufferManager, m_SendCounterPacket) |
Matteo Martincigh | cdfb941 | 2019-11-08 11:23:06 +0000 | [diff] [blame] | 79 | , m_SendTimelinePacket(m_BufferManager) |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 80 | , m_PeriodicCounterCapture(m_Holder, m_SendCounterPacket, *this, m_CounterIdMap, m_BackendProfilingContexts) |
Jim Flynn | 397043f | 2019-10-17 17:37:10 +0100 | [diff] [blame] | 81 | , m_ConnectionAcknowledgedCommandHandler(0, |
| 82 | 1, |
Jim Flynn | ed25e0e | 2019-10-18 13:21:43 +0100 | [diff] [blame] | 83 | m_PacketVersionResolver.ResolvePacketVersion(0, 1).GetEncodedValue(), |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 84 | m_CounterDirectory, |
| 85 | m_SendCounterPacket, |
Matteo Martincigh | cdfb941 | 2019-11-08 11:23:06 +0000 | [diff] [blame] | 86 | m_SendTimelinePacket, |
Finn Williams | fe5a24b | 2020-04-09 16:05:28 +0100 | [diff] [blame] | 87 | m_StateMachine, |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 88 | *this, |
Finn Williams | fe5a24b | 2020-04-09 16:05:28 +0100 | [diff] [blame] | 89 | m_BackendProfilingContexts) |
Jim Flynn | 397043f | 2019-10-17 17:37:10 +0100 | [diff] [blame] | 90 | , m_RequestCounterDirectoryCommandHandler(0, |
| 91 | 3, |
Jim Flynn | ed25e0e | 2019-10-18 13:21:43 +0100 | [diff] [blame] | 92 | m_PacketVersionResolver.ResolvePacketVersion(0, 3).GetEncodedValue(), |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 93 | m_CounterDirectory, |
| 94 | m_SendCounterPacket, |
Matteo Martincigh | 9723d02 | 2019-11-13 10:56:41 +0000 | [diff] [blame] | 95 | m_SendTimelinePacket, |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 96 | m_StateMachine) |
Jim Flynn | 397043f | 2019-10-17 17:37:10 +0100 | [diff] [blame] | 97 | , m_PeriodicCounterSelectionCommandHandler(0, |
| 98 | 4, |
Jim Flynn | ed25e0e | 2019-10-18 13:21:43 +0100 | [diff] [blame] | 99 | m_PacketVersionResolver.ResolvePacketVersion(0, 4).GetEncodedValue(), |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 100 | m_BackendProfilingContexts, |
| 101 | m_CounterIdMap, |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 102 | m_Holder, |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 103 | MAX_ARMNN_COUNTER, |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 104 | m_PeriodicCounterCapture, |
| 105 | *this, |
| 106 | m_SendCounterPacket, |
| 107 | m_StateMachine) |
Jim Flynn | 397043f | 2019-10-17 17:37:10 +0100 | [diff] [blame] | 108 | , m_PerJobCounterSelectionCommandHandler(0, |
| 109 | 5, |
Jim Flynn | ed25e0e | 2019-10-18 13:21:43 +0100 | [diff] [blame] | 110 | m_PacketVersionResolver.ResolvePacketVersion(0, 5).GetEncodedValue(), |
Matteo Martincigh | 994b534 | 2019-10-11 17:19:56 +0100 | [diff] [blame] | 111 | m_StateMachine) |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 112 | , m_ActivateTimelineReportingCommandHandler(0, |
| 113 | 6, |
| 114 | m_PacketVersionResolver.ResolvePacketVersion(0, 6) |
| 115 | .GetEncodedValue(), |
| 116 | m_SendTimelinePacket, |
| 117 | m_StateMachine, |
| 118 | reportStructure, |
| 119 | m_TimelineReporting, |
| 120 | *this) |
| 121 | , m_DeactivateTimelineReportingCommandHandler(0, |
| 122 | 7, |
| 123 | m_PacketVersionResolver.ResolvePacketVersion(0, 7) |
| 124 | .GetEncodedValue(), |
| 125 | m_TimelineReporting, |
| 126 | m_StateMachine, |
| 127 | *this) |
Jim Flynn | 8b20065 | 2019-10-24 18:07:44 +0100 | [diff] [blame] | 128 | , m_TimelinePacketWriterFactory(m_BufferManager) |
David Monahan | c1536d6 | 2020-02-12 15:52:35 +0000 | [diff] [blame] | 129 | , m_MaxGlobalCounterId(armnn::profiling::INFERENCES_RUN) |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 130 | , m_ServiceActive(false) |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 131 | { |
| 132 | // Register the "Connection Acknowledged" command handler |
| 133 | m_CommandHandlerRegistry.RegisterFunctor(&m_ConnectionAcknowledgedCommandHandler); |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 134 | |
| 135 | // Register the "Request Counter Directory" command handler |
| 136 | m_CommandHandlerRegistry.RegisterFunctor(&m_RequestCounterDirectoryCommandHandler); |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 137 | |
| 138 | // Register the "Periodic Counter Selection" command handler |
| 139 | m_CommandHandlerRegistry.RegisterFunctor(&m_PeriodicCounterSelectionCommandHandler); |
Matteo Martincigh | 994b534 | 2019-10-11 17:19:56 +0100 | [diff] [blame] | 140 | |
| 141 | // Register the "Per-Job Counter Selection" command handler |
| 142 | m_CommandHandlerRegistry.RegisterFunctor(&m_PerJobCounterSelectionCommandHandler); |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 143 | |
| 144 | m_CommandHandlerRegistry.RegisterFunctor(&m_ActivateTimelineReportingCommandHandler); |
| 145 | |
| 146 | m_CommandHandlerRegistry.RegisterFunctor(&m_DeactivateTimelineReportingCommandHandler); |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 147 | } |
Sadik Armagan | 3184c90 | 2020-03-18 10:57:30 +0000 | [diff] [blame] | 148 | |
janeil01 | 811ca55 | 2019-12-03 17:01:32 +0000 | [diff] [blame] | 149 | ~ProfilingService(); |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 150 | |
Sadik Armagan | 3184c90 | 2020-03-18 10:57:30 +0000 | [diff] [blame] | 151 | // Resets the profiling options, optionally clears the profiling service entirely |
| 152 | void ResetExternalProfilingOptions(const ExternalProfilingOptions& options, bool resetProfilingService = false); |
| 153 | ProfilingState ConfigureProfilingService(const ExternalProfilingOptions& options, |
| 154 | bool resetProfilingService = false); |
| 155 | |
| 156 | |
| 157 | // Updates the profiling service, making it transition to a new state if necessary |
| 158 | void Update(); |
| 159 | |
| 160 | // Disconnects the profiling service from the external server |
| 161 | void Disconnect(); |
| 162 | |
| 163 | // Store a profiling context returned from a backend that support profiling. |
| 164 | void AddBackendProfilingContext(const BackendId backendId, |
| 165 | std::shared_ptr<armnn::profiling::IBackendProfilingContext> profilingContext); |
| 166 | |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 167 | // Enable the recording of timeline events and entities |
| 168 | void NotifyBackendsForTimelineReporting() override; |
| 169 | |
Sadik Armagan | 3184c90 | 2020-03-18 10:57:30 +0000 | [diff] [blame] | 170 | const ICounterDirectory& GetCounterDirectory() const; |
| 171 | ICounterRegistry& GetCounterRegistry(); |
| 172 | ProfilingState GetCurrentState() const; |
| 173 | bool IsCounterRegistered(uint16_t counterUid) const override; |
Finn Williams | f3fcf32 | 2020-05-11 14:38:02 +0100 | [diff] [blame] | 174 | uint32_t GetAbsoluteCounterValue(uint16_t counterUid) const override; |
| 175 | uint32_t GetDeltaCounterValue(uint16_t counterUid) override; |
Sadik Armagan | 3184c90 | 2020-03-18 10:57:30 +0000 | [diff] [blame] | 176 | uint16_t GetCounterCount() const override; |
| 177 | // counter global/backend mapping functions |
| 178 | const ICounterMappings& GetCounterMappings() const override; |
| 179 | IRegisterCounterMapping& GetCounterMappingRegistry(); |
| 180 | |
| 181 | // Getters for the profiling service state |
| 182 | bool IsProfilingEnabled() const override; |
| 183 | |
| 184 | CaptureData GetCaptureData() override; |
| 185 | void SetCaptureData(uint32_t capturePeriod, |
| 186 | const std::vector<uint16_t>& counterIds, |
| 187 | const std::set<BackendId>& activeBackends); |
| 188 | |
| 189 | // Setters for the profiling service state |
| 190 | void SetCounterValue(uint16_t counterUid, uint32_t value) override; |
| 191 | uint32_t AddCounterValue(uint16_t counterUid, uint32_t value) override; |
| 192 | uint32_t SubtractCounterValue(uint16_t counterUid, uint32_t value) override; |
| 193 | uint32_t IncrementCounterValue(uint16_t counterUid) override; |
| 194 | |
| 195 | // IProfilingGuidGenerator functions |
| 196 | /// Return the next random Guid in the sequence |
| 197 | ProfilingDynamicGuid NextGuid() override; |
| 198 | /// Create a ProfilingStaticGuid based on a hash of the string |
| 199 | ProfilingStaticGuid GenerateStaticId(const std::string& str) override; |
| 200 | |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 201 | |
Sadik Armagan | 3184c90 | 2020-03-18 10:57:30 +0000 | [diff] [blame] | 202 | std::unique_ptr<ISendTimelinePacket> GetSendTimelinePacket() const override; |
| 203 | |
| 204 | ISendCounterPacket& GetSendCounterPacket() override |
| 205 | { |
| 206 | return m_SendCounterPacket; |
| 207 | } |
| 208 | |
Sadik Armagan | 3184c90 | 2020-03-18 10:57:30 +0000 | [diff] [blame] | 209 | static ProfilingDynamicGuid GetNextGuid(); |
| 210 | |
| 211 | static ProfilingStaticGuid GetStaticId(const std::string& str); |
| 212 | |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 213 | void ResetGuidGenerator(); |
| 214 | |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 215 | bool IsTimelineReportingEnabled() |
| 216 | { |
| 217 | return m_TimelineReporting; |
| 218 | } |
| 219 | |
Jim Flynn | 4e755a5 | 2020-03-29 17:48:26 +0100 | [diff] [blame] | 220 | void AddLocalPacketHandler(ILocalPacketHandlerSharedPtr localPacketHandler); |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 221 | |
| 222 | void NotifyProfilingServiceActive() override; // IProfilingServiceStatus |
| 223 | void WaitForProfilingServiceActivation(unsigned int timeout) override; // IProfilingServiceStatus |
| 224 | |
Sadik Armagan | 3184c90 | 2020-03-18 10:57:30 +0000 | [diff] [blame] | 225 | private: |
| 226 | //Copy/move constructors/destructors and copy/move assignment operators are deleted |
| 227 | ProfilingService(const ProfilingService&) = delete; |
| 228 | ProfilingService(ProfilingService&&) = delete; |
| 229 | ProfilingService& operator=(const ProfilingService&) = delete; |
| 230 | ProfilingService& operator=(ProfilingService&&) = delete; |
| 231 | |
| 232 | // Initialization/reset functions |
| 233 | void Initialize(); |
| 234 | void InitializeCounterValue(uint16_t counterUid); |
| 235 | void Reset(); |
| 236 | void Stop(); |
| 237 | |
| 238 | // Helper function |
| 239 | void CheckCounterUid(uint16_t counterUid) const; |
| 240 | |
| 241 | // Profiling service components |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 242 | ExternalProfilingOptions m_Options; |
| 243 | std::atomic<bool> m_TimelineReporting; |
| 244 | CounterDirectory m_CounterDirectory; |
| 245 | CounterIdMap m_CounterIdMap; |
| 246 | IProfilingConnectionFactoryPtr m_ProfilingConnectionFactory; |
| 247 | IProfilingConnectionPtr m_ProfilingConnection; |
| 248 | ProfilingStateMachine m_StateMachine; |
| 249 | CounterIndices m_CounterIndex; |
| 250 | CounterValues m_CounterValues; |
| 251 | arm::pipe::CommandHandlerRegistry m_CommandHandlerRegistry; |
| 252 | arm::pipe::PacketVersionResolver m_PacketVersionResolver; |
| 253 | CommandHandler m_CommandHandler; |
| 254 | BufferManager m_BufferManager; |
| 255 | SendCounterPacket m_SendCounterPacket; |
| 256 | SendThread m_SendThread; |
| 257 | SendTimelinePacket m_SendTimelinePacket; |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 258 | |
Sadik Armagan | 3184c90 | 2020-03-18 10:57:30 +0000 | [diff] [blame] | 259 | Holder m_Holder; |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 260 | |
Sadik Armagan | 3184c90 | 2020-03-18 10:57:30 +0000 | [diff] [blame] | 261 | PeriodicCounterCapture m_PeriodicCounterCapture; |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 262 | |
| 263 | ConnectionAcknowledgedCommandHandler m_ConnectionAcknowledgedCommandHandler; |
| 264 | RequestCounterDirectoryCommandHandler m_RequestCounterDirectoryCommandHandler; |
| 265 | PeriodicCounterSelectionCommandHandler m_PeriodicCounterSelectionCommandHandler; |
| 266 | PerJobCounterSelectionCommandHandler m_PerJobCounterSelectionCommandHandler; |
| 267 | ActivateTimelineReportingCommandHandler m_ActivateTimelineReportingCommandHandler; |
| 268 | DeactivateTimelineReportingCommandHandler m_DeactivateTimelineReportingCommandHandler; |
Sadik Armagan | 3184c90 | 2020-03-18 10:57:30 +0000 | [diff] [blame] | 269 | |
| 270 | TimelinePacketWriterFactory m_TimelinePacketWriterFactory; |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 271 | BackendProfilingContext m_BackendProfilingContexts; |
| 272 | uint16_t m_MaxGlobalCounterId; |
Sadik Armagan | 3184c90 | 2020-03-18 10:57:30 +0000 | [diff] [blame] | 273 | |
| 274 | static ProfilingGuidGenerator m_GuidGenerator; |
| 275 | |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 276 | // Signalling to let external actors know when service is active or not |
| 277 | std::mutex m_ServiceActiveMutex; |
| 278 | std::condition_variable m_ServiceActiveConditionVariable; |
| 279 | bool m_ServiceActive; |
| 280 | |
Sadik Armagan | 3184c90 | 2020-03-18 10:57:30 +0000 | [diff] [blame] | 281 | protected: |
| 282 | |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame] | 283 | // Protected methods for testing |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 284 | void SwapProfilingConnectionFactory(ProfilingService& instance, |
| 285 | IProfilingConnectionFactory* other, |
| 286 | IProfilingConnectionFactory*& backup) |
| 287 | { |
Narumol Prangnawarat | ac2770a | 2020-04-01 16:51:23 +0100 | [diff] [blame] | 288 | ARMNN_ASSERT(instance.m_ProfilingConnectionFactory); |
| 289 | ARMNN_ASSERT(other); |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 290 | |
| 291 | backup = instance.m_ProfilingConnectionFactory.release(); |
| 292 | instance.m_ProfilingConnectionFactory.reset(other); |
| 293 | } |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame] | 294 | IProfilingConnection* GetProfilingConnection(ProfilingService& instance) |
| 295 | { |
| 296 | return instance.m_ProfilingConnection.get(); |
| 297 | } |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 298 | void TransitionToState(ProfilingService& instance, ProfilingState newState) |
| 299 | { |
| 300 | instance.m_StateMachine.TransitionToState(newState); |
| 301 | } |
Finn Williams | 09ad6f9 | 2019-12-19 17:05:18 +0000 | [diff] [blame] | 302 | bool WaitForPacketSent(ProfilingService& instance, uint32_t timeout = 1000) |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 303 | { |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 304 | return instance.m_SendThread.WaitForPacketSent(timeout); |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 305 | } |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 306 | |
| 307 | BufferManager& GetBufferManager(ProfilingService& instance) |
| 308 | { |
| 309 | return instance.m_BufferManager; |
| 310 | } |
Keith Davis | 02356de | 2019-08-26 18:28:17 +0100 | [diff] [blame] | 311 | }; |
| 312 | |
| 313 | } // namespace profiling |
| 314 | |
Matteo Martincigh | a84edee | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 315 | } // namespace armnn |