AJA NTV2 SDK  17.1.1.1245
NTV2 SDK 17.1.1.1245
log.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MIT */
8 #ifndef AJA_LOG_H
9 #define AJA_LOG_H
10 
11 #include <stdio.h>
12 #include "ajabase/common/public.h"
13 #include "debug.h"
14 
15 #if defined(AJA_WINDOWS)
16 extern void __cdecl log_odprintf(const char *format, ...);
17 #elif defined (AJA_MAC)
18 #pragma GCC diagnostic ignored "-Wformat-security"
19 #endif
20 
21 // use this the select alternate platform specific loggers, 0 is used for no-log
22 #ifndef AJA_LOGTYPE
23 #define AJA_LOGTYPE 2
24 #endif
25 
26 // define AJA_LOG here
27 
28 #if defined(AJA_WINDOWS)
29 
30  #if defined(AJA_DEBUG)
31 
32  #if (AJA_LOGTYPE==0)
33  // no log
34  #define AJA_LOG(...)
35  #define AJA_ULOG(_unit_,...)
36 
37  #elif (AJA_LOGTYPE==1)
38  #define AJA_LOG(...) log_odprintf(__VA_ARGS__)
39  #define AJA_ULOG(_unit_,...) \
40  do {if (AJADebug::IsActive(_unit_)) log_odprintf(__VA_ARGS__);} while(0);
41 
42  #elif (AJA_LOGTYPE==2)
43  #define AJA_LOG(...) AJA_REPORT(AJA_DebugUnit_Critical, AJA_DebugSeverity_Info, __VA_ARGS__)
44  #define AJA_ULOG(_unit_,...) \
45  do {if (AJADebug::IsActive(_unit_)) AJA_REPORT(_unit_, AJA_DebugSeverity_Info, __VA_ARGS__);} while(0);
46 
47  #else
48  //catch all, so builds won't break
49  #define AJA_LOG(...)
50  #define AJA_ULOG(_unit_,...)
51  #endif
52 
53  #else
54  // no log
55  #define AJA_LOG(...)
56  #define AJA_ULOG(_unit_,...)
57  #endif
58 
59 #elif defined(AJA_LINUX) || defined(AJA_MAC)
60 
61  #if defined(AJA_DEBUG)
62 
63  #if (AJA_LOGTYPE==0)
64  // no log
65  #define AJA_LOG(_format_...)
66  #define AJA_ULOG(_unit_, _format_...)
67 
68  #elif (AJA_LOGTYPE==1)
69  // printf
70  #include <stdio.h>
71  #define AJA_LOG(_format_...) printf(_format_)
72  #define AJA_ULOG(_unit_, _format_...) \
73  do {if (AJADebug::IsActive(_unit_)) printf(_format_);} while(0);
74 
75  #elif (AJA_LOGTYPE==2)
76  #define AJA_LOG(_format_...) AJA_REPORT(AJA_DebugUnit_Critical, AJA_DebugSeverity_Info, _format_)
77  #define AJA_ULOG(_unit_, _format_...) \
78  do {if (AJADebug::IsActive(_unit_)) AJA_REPORT(_unit_, AJA_DebugSeverity_Info, _format_);} while(0);
79 
80  #endif
81 
82  #else
83  // no log
84  #define AJA_LOG(_format_...)
85  #define AJA_ULOG(_unit_, _format_...)
86  #endif
87 
88 #endif
89 
90 #ifndef Make4CC
91 #define Make4CC(my4CC) ((my4CC < 0x40) ? ' ' : ((char*)(&my4CC))[3]), \
92  ((my4CC < 0x40) ? ' ' : ((char*)(&my4CC))[2]), \
93  ((my4CC < 0x40) ? ('0' + (char)(my4CC / 10)) : ((char*)(&my4CC))[1]), \
94  ((my4CC < 0x40) ? ('0' + (char)(my4CC % 10)) : ((char*)(&my4CC))[0])
95 #endif
96 
102 {
103 public:
104 
108  AJALog();
109 
113  virtual ~AJALog();
114 
115 private:
116  static bool bInitialized;
117 };
118 
119 
120 extern AJALog gLogInit;
121 
122 
128 #define TAG_SIZE 64
129 
130 
131 
132 //---------------------------------------------------------------------------------------------------------------------
133 // class AJARunAverage
134 // calculates a running average of input values
135 //---------------------------------------------------------------------------------------------------------------------
137 {
138 protected:
139  explicit AJARunAverage() {}
140  uint64_t _samplesTotal;
141  uint64_t _sampleSize;
142  std::vector<int64_t> _samples;
143 
144 public:
145  AJARunAverage(uint64_t sampleSize)
146  { Resize(sampleSize); }
147  virtual ~AJARunAverage()
148  {}
149 
150  virtual void Resize(uint64_t sampleSize);
151  virtual void Reset();
152 
153  void Mark(int64_t val);
154  int64_t LastValue();
155  int64_t MarkAverage(int64_t val);
156  int64_t Average();
157  uint64_t Total() { return _samplesTotal; }
158  uint64_t SampleSize() { return _sampleSize; }
159 };
160 
161 
162 //---------------------------------------------------------------------------------------------------------------------
163 // class AJARunTimeAverage
164 // calculates a running average of time deltas
165 //---------------------------------------------------------------------------------------------------------------------
167 {
168 protected:
169  explicit AJARunTimeAverage() {}
170  int64_t _lastTime;
171 
172 public:
173  AJARunTimeAverage(int sampleSize);
175  {}
176 
177  virtual void Resize(uint64_t sampleSize);
178  virtual void Reset();
179  virtual void ResetTime();
180 
181  int64_t MarkDeltaTime();
182  int64_t MarkDeltaAverage();
183 };
184 
185 
186 //---------------------------------------------------------------------------------------------------------------------
187 // class AJARunAverage
188 // caculates timelogs
189 //---------------------------------------------------------------------------------------------------------------------
191 {
192 public:
193  AJATimeLog();
194  AJATimeLog(const char* tag, int unit=AJA_DebugUnit_Critical);
195  AJATimeLog(const std::string& tag, int unit=AJA_DebugUnit_Critical);
196  virtual ~AJATimeLog();
197 
201  void Reset();
202 
206  void PrintReset();
207  inline void PrintResetIf(bool bEnable=true)
208  { if (bEnable) PrintReset(); }
209 
214  void PrintDelta(bool bReset=true);
215  void PrintDelta(const char* addedTag, bool bReset=true);
216  void PrintDelta(uint64_t threashold, const char* addedTag, bool bReset);
217 
218  inline void PrintDelta(const std::string& addedTag, bool bReset=true)
219  { PrintDelta(addedTag.c_str(), bReset); }
220 
226  inline void PrintDeltaIf(bool bEnable, bool bReset=true)
227  { if (bEnable) PrintDelta(bReset); }
228  inline void PrintDeltaIf(bool bEnable, const char* addedTag, bool bReset=true)
229  { if (bEnable) PrintDelta(addedTag, bReset); }
230  inline void PrintDeltaIf(bool bEnable, const std::string& addedTag, bool bReset=true)
231  { PrintDeltaIf(bEnable, addedTag.c_str(), bReset); }
232 
237  int32_t GetDelta(bool bReset=true);
238  inline int32_t GetLastDelta()
239  { return (int32_t)_lastDelta; }
240  inline int32_t GetLastDeltaMs()
241  { return (int32_t)(_lastDelta/1000); }
242 
247  void PrintValue(int64_t val);
248  void PrintValue(int64_t val, const char* addedTag);
249  inline void PrintValue(int64_t val, const std::string& addedTag)
250  { PrintValue(val, addedTag.c_str()); }
251 
252  void Print(const char* str);
253  void Print(const std::string& str)
254  { Print(str.c_str()); }
255 
256  inline int GetUnit()
257  { return _unit; }
258  inline void SetUnit(int unit)
259  { _unit = unit; }
260 
261  inline std::string GetTag()
262  {return _tag;}
263  inline void SetTag(const char* tag)
264  { _tag = tag; }
265 
266 protected:
267  std::string _tag;
268  int _unit;
269  uint64_t _time;
270  uint64_t _lastDelta;
271 };
272 
273 
274 #endif // AJA_LOG_H
AJATimeLog::PrintDelta
void PrintDelta(const std::string &addedTag, bool bReset=true)
Definition: log.h:218
AJARunAverage::~AJARunAverage
virtual ~AJARunAverage()
Definition: log.h:147
AJATimeLog::GetLastDeltaMs
int32_t GetLastDeltaMs()
Definition: log.h:240
AJATimeLog
Definition: log.h:190
AJATimeLog::SetTag
void SetTag(const char *tag)
Definition: log.h:263
gLogInit
AJALog gLogInit
AJARunAverage::AJARunAverage
AJARunAverage()
Definition: log.h:139
AJA_EXPORT
#define AJA_EXPORT
Definition: export.h:34
AJARunAverage::Reset
virtual void Reset()
Definition: log.cpp:118
AJATimeLog::SetUnit
void SetUnit(int unit)
Definition: log.h:258
public.h
Master header for the ajabase library.
AJATimeLog::PrintResetIf
void PrintResetIf(bool bEnable=true)
Definition: log.h:207
AJARunAverage
Definition: log.h:136
AJATimeLog::_lastDelta
uint64_t _lastDelta
Definition: log.h:270
AJARunAverage::_sampleSize
uint64_t _sampleSize
Definition: log.h:141
AJATimeLog::Print
void Print(const std::string &str)
Definition: log.h:253
AJATimeLog::_tag
std::string _tag
Definition: log.h:267
AJATimeLog::_unit
int _unit
Definition: log.h:268
AJATimeLog::PrintDeltaIf
void PrintDeltaIf(bool bEnable, const char *addedTag, bool bReset=true)
Definition: log.h:228
AJARunTimeAverage::_lastTime
int64_t _lastTime
Definition: log.h:170
AJARunAverage::Resize
virtual void Resize(uint64_t sampleSize)
Definition: log.cpp:124
AJARunTimeAverage::~AJARunTimeAverage
virtual ~AJARunTimeAverage()
Definition: log.h:174
AJARunTimeAverage::AJARunTimeAverage
AJARunTimeAverage()
Definition: log.h:169
AJA_DebugUnit_Critical
@ AJA_DebugUnit_Critical
Definition: debugshare.h:47
AJALog
Definition: log.h:101
AJARunAverage::Total
uint64_t Total()
Definition: log.h:157
AJATimeLog::_time
uint64_t _time
Definition: log.h:269
AJATimeLog::PrintDeltaIf
void PrintDeltaIf(bool bEnable, bool bReset=true)
Definition: log.h:226
AJARunAverage::AJARunAverage
AJARunAverage(uint64_t sampleSize)
Definition: log.h:145
AJATimeLog::GetLastDelta
int32_t GetLastDelta()
Definition: log.h:238
AJATimeLog::PrintDeltaIf
void PrintDeltaIf(bool bEnable, const std::string &addedTag, bool bReset=true)
Definition: log.h:230
AJATimeLog::GetTag
std::string GetTag()
Definition: log.h:261
AJARunAverage::_samplesTotal
uint64_t _samplesTotal
Definition: log.h:140
AJARunTimeAverage
Definition: log.h:166
AJARunAverage::_samples
std::vector< int64_t > _samples
Definition: log.h:142
AJATimeLog::PrintValue
void PrintValue(int64_t val, const std::string &addedTag)
Definition: log.h:249
AJARunAverage::SampleSize
uint64_t SampleSize()
Definition: log.h:158
debug.h
Declares the AJADebug class.
AJATimeLog::GetUnit
int GetUnit()
Definition: log.h:256