Keith Davis | 02356de | 2019-08-26 18:28:17 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #pragma once |
| 7 | |
| 8 | #include "ProfilingStateMachine.hpp" |
| 9 | #include "ProfilingConnectionFactory.hpp" |
FinnWilliamsArm | ce2d9d1 | 2019-09-18 10:28:16 +0100 | [diff] [blame] | 10 | #include "CounterDirectory.hpp" |
Matteo Martincigh | e0e6efc | 2019-10-04 17:17:42 +0100 | [diff] [blame^] | 11 | #include "ICounterValues.hpp" |
Keith Davis | 02356de | 2019-08-26 18:28:17 +0100 | [diff] [blame] | 12 | |
| 13 | namespace armnn |
| 14 | { |
| 15 | |
| 16 | namespace profiling |
| 17 | { |
| 18 | |
Matteo Martincigh | a84edee | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 19 | class ProfilingService final : public IReadWriteCounterValues |
Keith Davis | 02356de | 2019-08-26 18:28:17 +0100 | [diff] [blame] | 20 | { |
| 21 | public: |
Matteo Martincigh | a84edee | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 22 | using ExternalProfilingOptions = Runtime::CreationOptions::ExternalProfilingOptions; |
| 23 | using IProfilingConnectionPtr = std::unique_ptr<IProfilingConnection>; |
| 24 | using CounterIndices = std::vector<std::atomic<uint32_t>*>; |
| 25 | using CounterValues = std::list<std::atomic<uint32_t>>; |
Keith Davis | 02356de | 2019-08-26 18:28:17 +0100 | [diff] [blame] | 26 | |
Matteo Martincigh | a84edee | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 27 | // Getter for the singleton instance |
| 28 | static ProfilingService& Instance() |
| 29 | { |
| 30 | static ProfilingService instance; |
| 31 | return instance; |
| 32 | } |
| 33 | |
| 34 | // Resets the profiling options, optionally clears the profiling service entirely |
| 35 | void ResetExternalProfilingOptions(const ExternalProfilingOptions& options, bool resetProfilingService = false); |
| 36 | |
| 37 | // Runs the profiling service |
Keith Davis | 02356de | 2019-08-26 18:28:17 +0100 | [diff] [blame] | 38 | void Run(); |
| 39 | |
Matteo Martincigh | a84edee | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 40 | // Getters for the profiling service state |
FinnWilliamsArm | ce2d9d1 | 2019-09-18 10:28:16 +0100 | [diff] [blame] | 41 | const ICounterDirectory& GetCounterDirectory() const; |
Keith Davis | 02356de | 2019-08-26 18:28:17 +0100 | [diff] [blame] | 42 | ProfilingState GetCurrentState() const; |
Matteo Martincigh | a84edee | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 43 | uint16_t GetCounterCount() const override; |
| 44 | uint32_t GetCounterValue(uint16_t counterUid) const override; |
Keith Davis | 02356de | 2019-08-26 18:28:17 +0100 | [diff] [blame] | 45 | |
Matteo Martincigh | a84edee | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 46 | // Setters for the profiling service state |
| 47 | void SetCounterValue(uint16_t counterUid, uint32_t value) override; |
| 48 | uint32_t AddCounterValue(uint16_t counterUid, uint32_t value) override; |
| 49 | uint32_t SubtractCounterValue(uint16_t counterUid, uint32_t value) override; |
| 50 | uint32_t IncrementCounterValue(uint16_t counterUid) override; |
| 51 | uint32_t DecrementCounterValue(uint16_t counterUid) override; |
FinnWilliamsArm | f6e534a | 2019-09-16 15:45:42 +0100 | [diff] [blame] | 52 | |
Keith Davis | 02356de | 2019-08-26 18:28:17 +0100 | [diff] [blame] | 53 | private: |
Matteo Martincigh | a84edee | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 54 | // Default/copy/move constructors/destructors and copy/move assignment operators are kept private |
| 55 | ProfilingService() = default; |
| 56 | ProfilingService(const ProfilingService&) = delete; |
| 57 | ProfilingService(ProfilingService&&) = delete; |
| 58 | ProfilingService& operator=(const ProfilingService&) = delete; |
| 59 | ProfilingService& operator=(ProfilingService&&) = delete; |
| 60 | ~ProfilingService() = default; |
Keith Davis | 02356de | 2019-08-26 18:28:17 +0100 | [diff] [blame] | 61 | |
Matteo Martincigh | a84edee | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 62 | // Initialization functions |
| 63 | void Initialize(); |
| 64 | void InitializeCounterValue(uint16_t counterUid); |
| 65 | |
| 66 | // Profiling service state variables |
| 67 | ExternalProfilingOptions m_Options; |
FinnWilliamsArm | ce2d9d1 | 2019-09-18 10:28:16 +0100 | [diff] [blame] | 68 | CounterDirectory m_CounterDirectory; |
Matteo Martincigh | a84edee | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 69 | ProfilingConnectionFactory m_ProfilingConnectionFactory; |
| 70 | IProfilingConnectionPtr m_ProfilingConnection; |
| 71 | ProfilingStateMachine m_StateMachine; |
| 72 | CounterIndices m_CounterIndex; |
| 73 | CounterValues m_CounterValues; |
Keith Davis | 02356de | 2019-08-26 18:28:17 +0100 | [diff] [blame] | 74 | }; |
| 75 | |
| 76 | } // namespace profiling |
| 77 | |
Matteo Martincigh | a84edee | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 78 | } // namespace armnn |