• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright © 2019 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #pragma once
7 
8 #include "IProfilingConnection.hpp"
9 #include <common/include/PacketVersionResolver.hpp>
10 
11 #include <common/include/CommandHandlerRegistry.hpp>
12 
13 #include <atomic>
14 #include <thread>
15 
16 namespace armnn
17 {
18 
19 namespace profiling
20 {
21 
22 class CommandHandler
23 {
24 public:
CommandHandler(uint32_t timeout,bool stopAfterTimeout,arm::pipe::CommandHandlerRegistry & commandHandlerRegistry,arm::pipe::PacketVersionResolver & packetVersionResolver)25     CommandHandler(uint32_t timeout,
26                    bool stopAfterTimeout,
27                    arm::pipe::CommandHandlerRegistry& commandHandlerRegistry,
28                    arm::pipe::PacketVersionResolver& packetVersionResolver)
29         : m_Timeout(timeout),
30           m_StopAfterTimeout(stopAfterTimeout),
31           m_IsRunning(false),
32           m_KeepRunning(false),
33           m_CommandThread(),
34           m_CommandHandlerRegistry(commandHandlerRegistry),
35           m_PacketVersionResolver(packetVersionResolver)
36     {}
~CommandHandler()37     ~CommandHandler() { Stop(); }
38 
SetTimeout(uint32_t timeout)39     void SetTimeout(uint32_t timeout) { m_Timeout.store(timeout); }
SetStopAfterTimeout(bool stopAfterTimeout)40     void SetStopAfterTimeout(bool stopAfterTimeout) { m_StopAfterTimeout.store(stopAfterTimeout); }
41 
42     void Start(IProfilingConnection& profilingConnection);
43     void Stop();
IsRunning() const44     bool IsRunning() const { return m_IsRunning.load(); }
45 
46 private:
47     void HandleCommands(IProfilingConnection& profilingConnection);
48 
49     std::atomic<uint32_t> m_Timeout;
50     std::atomic<bool>     m_StopAfterTimeout;
51     std::atomic<bool>     m_IsRunning;
52     std::atomic<bool>     m_KeepRunning;
53     std::thread           m_CommandThread;
54 
55     arm::pipe::CommandHandlerRegistry& m_CommandHandlerRegistry;
56     arm::pipe::PacketVersionResolver&  m_PacketVersionResolver;
57 };
58 
59 } // namespace profiling
60 
61 } // namespace armnn
62