PLCnext API Documentation  22.9.0.33
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 
56 
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 
This class implements the singleton pattern.
Definition: Singleton.hxx:25
High resolution timer for interval based executions.
Definition: Timer.hpp:54
The TraceController provides an Interface to manage and control the LTTng Tracing on the Control
Definition: TraceController.hpp:31
bool IsSessionInSnapshotMode(const Arp::String &session)
Checks if a trace session is in Snapshot Mode
bool StopSession(const Arp::String &session)
Stops an LTTnG Trace Session
bool IsSessionDaemonAlive(void) const
Checks if the session daemon for tracing is alive.
bool IsSessionLoaded(const Arp::String &session)
Checks if a trace session is already loaded
void SetTracesSavingConfigs(const Arp::String &triggerSession, const Arp::String &outPath, const Arp::uint32 &maxDirectorySize, const Arp::uint32 &savingDelayTimeout)
Sets the configuration of the trigger saving function
bool IsSessionEnabled(const Arp::String &session)
Checks if a trace session is already enabled/started
void UnloadTracepointLibrary(void)
Unoads the userspace Trace-Point-Library
SessionList ListSessions(void)
Queries a list of loaded LTTng Sessions
bool TriggerSavingTraceOutputs(const bool &stopTriggerSession)
Records/Saves all outputs of a configured session after an internal timeout delay Session in Snapshot...
bool DestroySession(const Arp::String &session)
Destroys/Unloads an LTTnG Trace Session
bool LoadSessionConfiguration(const Arp::String &session, const Arp::String &config)
Tries to loads a configuration file.
void LoadTracepointLibrary(void)
Loads the userspace Trace-Point-Library
bool StartSession(const Arp::String &session)
Starts an LTTnG Trace Session
High level API to enable work with dynamically loadable shared libraries.
Definition: SharedLibrary.hpp:20
std::uint32_t uint32
The Arp unsigned integer type of 4 byte size.
Definition: PrimitiveTypes.hpp:35
@ System
System components used by the System, Device, Plc or Io domains.
Namespace for time related classes
Definition: Duration.hpp:13
Root namespace for the PLCnext API