AJA NTV2 SDK  18.0.0.2122
NTV2 SDK 18.0.0.2122
debugshare.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MIT */
10 #ifndef AJA_DEBUGSHARE_H
11 #define AJA_DEBUGSHARE_H
12 #include "ajabase/common/export.h"
13 #include <stddef.h>
14 #include <stdint.h>
15 #include <string>
16 #include <vector>
17 
22 typedef enum _AJADebugSeverity
24 {
37 
38 
43 typedef enum _AJADebugUnit
45 {
107 
108  // to add a new unit:
109  //
110  // if there is an unused unit below:
111  //
112  // * rename the next available unused and move above this comment block
113  // * make sure the enum starts with "AJA_DebugUnit_"
114  // * update the value of AJA_DebugUnit_FirstUnused with the value of the new next available unused
115  //
116  // else if there are not any unused units below:
117  //
118  // * add the new unit above this message block with the next available index
119  // * make sure the enum starts with "AJA_DebugUnit_"
120  // * increment AJA_DebugUnit_Size by 1
121  //
122  // if no more unused units
123  // * set AJA_DebugUnit_FirstUnused to the same value as AJA_DebugUnit_Size
124  //
150 
152 
153 } AJADebugUnit;
155 
156 
164 #define AJA_DEBUG_DESTINATION_NONE 0
166 #define AJA_DEBUG_DESTINATION_DEBUG 0x00000001
167 #define AJA_DEBUG_DESTINATION_CONSOLE 0x00000002
168 #define AJA_DEBUG_DESTINATION_LOG 0x00000004
169 #define AJA_DEBUG_DESTINATION_DRIVER 0x00000008
170 
172 
178 #define AJA_DEBUG_MAGIC_ID AJA_FOURCC('D','B','U','G')
180 #define AJA_DEBUG_VERSION 110
181 #define AJA_DEBUG_UNIT_ARRAY_SIZE 65536
182 #define AJA_DEBUG_SEVERITY_ARRAY_SIZE 64
183 #define AJA_DEBUG_MAX_NUM_STATS 256
184 #define AJA_DEBUG_STAT_DEQUE_SIZE 11
185 #define AJA_DEBUG_MESSAGE_MAX_SIZE 512
186 #define AJA_DEBUG_MESSAGE_RING_SIZE 4096
187 #define AJA_DEBUG_FILE_NAME_MAX_SIZE 512
188 #define AJA_DEBUG_SHARE_NAME "aja-shm-debug"
189 #define AJA_DEBUG_TICK_RATE 1000000
190 #define AJA_DEBUG_STATE_FILE_VERSION 510
191 
193 
198 // using a 16 byte alignment for arm64 atomic operations to work properly
199 #pragma pack(push, 16)
200 
201 typedef struct _AJADebugMessage
202 {
203  uint64_t sequenceNumber;
204  int64_t time;
205  int64_t wallTime;
206  int32_t groupIndex;
207  uint32_t destinationMask;
208  int32_t severity;
209  int32_t lineNumber;
210  uint64_t pid;
211  uint64_t tid;
215 
216 
221 typedef enum _AJADebugStats
223 {
251 } AJADebugStats;
253 
254 
263 {
264  public:
265  uint32_t fMin;
266  uint32_t fMax;
267  uint32_t volatile fCount;
268  uint64_t fLastTimeStamp;
269  uint32_t fValues[AJA_DEBUG_STAT_DEQUE_SIZE];
271  // Instance Methods
272  public:
273  inline AJADebugStat() {Reset();}
274 
275  inline void Reset (void)
276  {
277  fMin = 0xFFFFFFFF;
278  fMax = fCount = 0;
279  fLastTimeStamp = 0;
280  for (size_t n(0); n < AJA_DEBUG_STAT_DEQUE_SIZE; n++)
281  fValues[n] = 0;
282  }
283  bool operator == (const AJADebugStat & inRHS) const;
284  inline bool operator != (const AJADebugStat & inRHS) const {return !(*this == inRHS);}
286  double Average(void) const;
287  uint64_t Sum (size_t inNum = AJA_DEBUG_STAT_DEQUE_SIZE) const;
288  uint32_t Minimum (size_t inNum = AJA_DEBUG_STAT_DEQUE_SIZE) const;
289  uint32_t Maximum (size_t inNum = AJA_DEBUG_STAT_DEQUE_SIZE) const;
290  void Start (void);
291  bool Stop (void);
298  bool IncrementCount (const uint32_t inIncrement = 1, const bool inRollOver = true);
299 
305  bool DecrementCount (const uint32_t inDecrement = 1, const bool inRollUnder = true);
306 
307  inline bool IsSimpleCounter (void) const {return fMin == 0xFFFFFFFF && !fMax;}
308  void SetValue (const uint32_t inValue);
309  inline uint32_t GetCurrentValue (void) const {return fCount ? fValues[CurrentValueIndex()] : 0;}
310  inline int CurrentValueIndex (void) const {return fCount ? int((fCount - 1) % AJA_DEBUG_STAT_DEQUE_SIZE) : 9999;}
311  inline uint32_t GetValue (void) const {return IsSimpleCounter() ? fCount : GetCurrentValue();}
313  // Class Methods
314  public:
315  static std::string StatKeyName (const int inKey);
316  static inline bool StatKeyHasName (const int inKey) {return !StatKeyName(inKey).empty();}
317  static bool SetStatKeyName (const int inKey, const std::string & inName);
318  static std::vector<int> NamedStatKeys (void);
319 }; // AJADebugStat
320 
321 
326 typedef struct _AJADebugShare
327 {
328  uint32_t magicId;
329  uint32_t version;
330  uint64_t volatile writeIndex;
331  int32_t volatile clientRefCount;
336  uint32_t unitArraySize;
338  uint64_t volatile statsMessagesAccepted;
339  uint64_t volatile statsMessagesIgnored;
341  uint32_t statCapacity;
342  uint32_t volatile statAllocChanges;
344  uint32_t reserved[128 - 1 - 1 - 2*AJA_DEBUG_MAX_NUM_STATS/64];
348 } AJADebugShare;
349 
350 #pragma pack(pop)
351 
352 #endif // AJA_DEBUGSHARE_H
struct _AJADebugShare AJADebugShare
void Reset(void)
Definition: debugshare.h:275
uint32_t unitArraySize
Definition: debugshare.h:336
int CurrentValueIndex(void) const
Definition: debugshare.h:310
enum _AJADebugSeverity AJADebugSeverity
uint64_t fLastTimeStamp
Definition: debugshare.h:268
enum _AJADebugStats AJADebugStats
#define AJA_DEBUG_MESSAGE_MAX_SIZE
Definition: debugshare.h:185
#define AJA_EXPORT
Definition: export.h:34
uint32_t magicId
Definition: debugshare.h:328
Declares system-dependent import/export macros and libraries.
#define AJA_DEBUG_MAX_NUM_STATS
Definition: debugshare.h:183
uint32_t fMin
Definition: debugshare.h:265
bool operator!=(const json_pointer< RefStringTypeLhs > &lhs, const json_pointer< RefStringTypeRhs > &rhs) noexcept
Definition: json.hpp:14762
int32_t volatile clientRefCount
Definition: debugshare.h:331
unsigned int n
Definition: pstream.cpp:148
struct _AJADebugMessage AJADebugMessage
int32_t severity
Definition: debugshare.h:208
uint32_t volatile statAllocChanges
Definition: debugshare.h:342
uint32_t messageTextCapacity
Definition: debugshare.h:334
int64_t wallTime
Definition: debugshare.h:205
AJADebugStat stats[256]
Definition: debugshare.h:347
uint32_t volatile fCount
Definition: debugshare.h:267
uint64_t volatile statsMessagesIgnored
Definition: debugshare.h:339
uint32_t unitArray[65536]
Definition: debugshare.h:345
uint32_t version
Definition: debugshare.h:329
#define AJA_DEBUG_STAT_DEQUE_SIZE
Definition: debugshare.h:184
#define AJA_DEBUG_UNIT_ARRAY_SIZE
Definition: debugshare.h:181
enum _AJADebugUnit AJADebugUnit
char fileName[512]
Definition: debugshare.h:212
uint64_t statAllocMask[256/64]
Definition: debugshare.h:343
bool operator==(const json_pointer< RefStringTypeLhs > &lhs, const json_pointer< RefStringTypeRhs > &rhs) noexcept
Definition: json.hpp:14737
_AJADebugUnit
Definition: debugshare.h:44
uint32_t statCapacity
Definition: debugshare.h:341
uint64_t volatile writeIndex
Definition: debugshare.h:330
uint64_t volatile statsMessagesAccepted
Definition: debugshare.h:338
uint64_t sequenceNumber
Definition: debugshare.h:203
char messageText[512]
Definition: debugshare.h:213
bool IsSimpleCounter(void) const
Definition: debugshare.h:307
uint32_t GetCurrentValue(void) const
Definition: debugshare.h:309
uint32_t messageFileNameCapacity
Definition: debugshare.h:335
AJADebugMessage messageRing[4096]
Definition: debugshare.h:346
#define AJA_DEBUG_MESSAGE_RING_SIZE
Definition: debugshare.h:186
uint32_t GetValue(void) const
Definition: debugshare.h:311
_AJADebugSeverity
Definition: debugshare.h:23
int32_t lineNumber
Definition: debugshare.h:209
uint32_t fMax
Definition: debugshare.h:266
uint32_t destinationMask
Definition: debugshare.h:207
int32_t groupIndex
Definition: debugshare.h:206
static bool StatKeyHasName(const int inKey)
Definition: debugshare.h:316
#define AJA_DEBUG_FILE_NAME_MAX_SIZE
Definition: debugshare.h:187
uint32_t messageRingCapacity
Definition: debugshare.h:333
uint32_t reserved[128 - 1 - 1 - 2 *256/64]
Definition: debugshare.h:344
_AJADebugStats
Definition: debugshare.h:222