blob: b4cdcac76ec5a28923b6a2ddfa331de3f94eb522 [file] [log] [blame]
Keith Davis02356de2019-08-26 18:28:17 +01001//
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"
FinnWilliamsArmce2d9d12019-09-18 10:28:16 +010010#include "CounterDirectory.hpp"
Matteo Martincighe0e6efc2019-10-04 17:17:42 +010011#include "ICounterValues.hpp"
Keith Davis02356de2019-08-26 18:28:17 +010012
13namespace armnn
14{
15
16namespace profiling
17{
18
Matteo Martincigha84edee2019-10-02 12:50:57 +010019class ProfilingService final : public IReadWriteCounterValues
Keith Davis02356de2019-08-26 18:28:17 +010020{
21public:
Matteo Martincigha84edee2019-10-02 12:50:57 +010022 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 Davis02356de2019-08-26 18:28:17 +010026
Matteo Martincigha84edee2019-10-02 12:50:57 +010027 // 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 Davis02356de2019-08-26 18:28:17 +010038 void Run();
39
Matteo Martincigha84edee2019-10-02 12:50:57 +010040 // Getters for the profiling service state
FinnWilliamsArmce2d9d12019-09-18 10:28:16 +010041 const ICounterDirectory& GetCounterDirectory() const;
Keith Davis02356de2019-08-26 18:28:17 +010042 ProfilingState GetCurrentState() const;
Matteo Martincigha84edee2019-10-02 12:50:57 +010043 uint16_t GetCounterCount() const override;
44 uint32_t GetCounterValue(uint16_t counterUid) const override;
Keith Davis02356de2019-08-26 18:28:17 +010045
Matteo Martincigha84edee2019-10-02 12:50:57 +010046 // 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;
FinnWilliamsArmf6e534a2019-09-16 15:45:42 +010052
Keith Davis02356de2019-08-26 18:28:17 +010053private:
Matteo Martincigha84edee2019-10-02 12:50:57 +010054 // 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 Davis02356de2019-08-26 18:28:17 +010061
Matteo Martincigha84edee2019-10-02 12:50:57 +010062 // Initialization functions
63 void Initialize();
64 void InitializeCounterValue(uint16_t counterUid);
65
66 // Profiling service state variables
67 ExternalProfilingOptions m_Options;
FinnWilliamsArmce2d9d12019-09-18 10:28:16 +010068 CounterDirectory m_CounterDirectory;
Matteo Martincigha84edee2019-10-02 12:50:57 +010069 ProfilingConnectionFactory m_ProfilingConnectionFactory;
70 IProfilingConnectionPtr m_ProfilingConnection;
71 ProfilingStateMachine m_StateMachine;
72 CounterIndices m_CounterIndex;
73 CounterValues m_CounterValues;
Keith Davis02356de2019-08-26 18:28:17 +010074};
75
76} // namespace profiling
77
Matteo Martincigha84edee2019-10-02 12:50:57 +010078} // namespace armnn