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