PLCnext API Documentation  20.6.0.30321
TraceController.hpp
1 //
3 // Copyright PHOENIX CONTACT Electronics GmbH
4 //
6 #pragma once
7 #include "Arp/System/Core/Arp.h"
8 #include "Arp/System/Commons/Logging.h"
9 #include "Arp/System/Core/Singleton.hxx"
10 #include "Arp/System/Commons/Logging.h"
11 #include "Arp/System/Commons/Runtime/SharedLibrary.hpp"
12 #include "Arp/System/Commons/Chrono/Timer.hpp"
13 
14 #include <list>
15 
16 namespace Arp { namespace System { namespace Ve
17 {
18 class ITraceControllerService;
19 }}};
20 
21 namespace Arp { namespace System { namespace Commons { namespace Diagnostics
22 {
23 
25 using namespace Arp::System::Commons::Chrono;
26 
30 class TraceController : public Singleton<TraceController>, private Loggable<TraceController>
31 {
32 
33  friend class Singleton<TraceController>;
34 
35 public: // typedefs
36 
37  typedef std::list<Arp::String> SessionList;
38 
39 public: // operations
40 
45  bool IsSessionDaemonAlive(void) const;
46 
55  void LoadTracepointLibrary(void);
56 
65  void UnloadTracepointLibrary(void);
66 
74  bool LoadSessionConfiguration(const Arp::String& session, const Arp::String& config);
75 
81  SessionList ListSessions(void);
82 
89  bool StartSession(const Arp::String& session);
90 
97  bool StopSession(const Arp::String& session);
98 
105  bool DestroySession(const Arp::String& session);
106 
114  bool TriggerSavingTraceOutputs(const bool& stopTriggerSession);
115 
122  bool IsSessionInSnapshotMode(const Arp::String& session);
123 
130  bool IsSessionEnabled(const Arp::String& session);
131 
138  bool IsSessionLoaded(const Arp::String& session);
139 
140 public: // getter/setter operations
141 
149  void SetTracesSavingConfigs(const Arp::String& triggerSession, const Arp::String& outPath, const Arp::uint32& maxDirectorySize, const Arp::uint32& savingDelayTimeout);
150 
151 private: // construction/destruction
152 
154  TraceController(void);
155 
157  TraceController(const TraceController& arg) = delete;
158 
160  TraceController& operator=(const TraceController& arg) = delete;
161 
163  ~TraceController(void);
164 
165 private: // methods
166  void RunTraceSavingTimer(void);
167 
168  bool RecordSessionSnapshot(const Arp::String& session);
169 
170 private: // typedefs/usings
171 
172  using ITraceControllerService = Arp::System::Ve::ITraceControllerService;
173 
174 private: // fields
175 
176  ITraceControllerService *pInstance;
177 
178  SharedLibrary pTracingLibrary;
179 
180  // Traces Saving Configs
181  Arp::uint32 savingDelayTimeout;
182  Arp::String triggerSession;
183  Arp::String savingOutputPath;
184  Arp::uint32 maxDirectorySize;
185 
186  // Saving Delay Timer
187  Timer savingDelayTimer;
188 
189  bool stopSession;
190  std::atomic_flag triggerSavingWorking = ATOMIC_FLAG_INIT;
191 
192  bool tracepointLibLoaded;
193 };
194 
196 // inline methods of class TraceController
197 
198 }}}} // end of namespace Arp::System::Commons::Diagnostics
199 
High resolution timer for interval based executions.
Definition: Timer.hpp:53
std::uint32_t uint32
The Arp unsigned integer type of 4 byte size.
Definition: PrimitiveTypes.hpp:35
The TraceController provides an Interface to manage and control the LTTng Tracing on the Control ...
Definition: TraceController.hpp:30
This class implements the singleton pattern.
Definition: Singleton.hxx:24
High level API to enable work with dynamically loadable shared libraries.
Definition: SharedLibrary.hpp:19
Root namespace for the PLCnext API
System components used by the System, Device, Plc or Io domains.
Namespace for time related classes