HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PDG_LogUtils.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * COMMENTS:
7  */
8 
9 #ifndef PDG_LOG_UTILS_H
10 #define PDG_LOG_UTILS_H
11 
12 #include "PDG_API.h"
13 #include "PDG_Types.h"
14 
15 #include <PDGT/PDGT_Types.h>
16 
17 #include <UT/UT_Error.h>
18 #include <UT/UT_TBBSpinLock.h>
19 #include <UT/UT_WorkBuffer.h>
20 
21 class PDG_Node;
22 class PDG_Scheduler;
23 class PDG_WorkItem;
24 
25 class UT_StringHolder;
26 
27 /*
28  * Utility methods for logging debug information
29  */
31 {
32 public:
33  /**
34  * Enumeration of log types
35  */
36  enum LogType
37  {
38  /// Cache and handler logging
40 
41  /// Expression evaluation logging
43 
44  /// Node status/debug logging
46 
47  /// Scheduler status/debug logging
49 
50  /// Service client status/debug logging
52 
53  /// Work item status/debug logging
55 
56  /// File transer debug logging
58 
59  /// Type registration errors and warnings
61 
62  /// Total number of log types, should always be last
63  eLogTypeCount
64  };
65 
66  /**
67  * Enumeration of node debug log levels
68  */
69  enum NodeDebug
70  {
71  /// No debug logging
73 
74  /// Log node status updates, e.g. generated or cooked
76 
77  /// Log node status + errors
79 
80  /// Log node status + errors + warnings
82 
83  /// Log node status + errors + warning + callback invocations
84  eNodeDebugCallback
85  };
86 
87  /**
88  * Enumeration of scheduler debug log levels
89  */
91  {
92  /// No debug logging
94 
95  /// Log messages for events that occur at the scheduler level
97 
98  /// Log messages for events that occur at both the scheduler and
99  /// work item level
101  };
102 
103  /**
104  * Enumeration of service debug log levels
105  */
107  {
108  /// No debug logging
110 
111  /// Log messages for when a service client is acquired/released
113 
114  /// Log messages for when a service client isn't found, in addition
115  /// to the above
117 
118  /// Log messages for when a service starts up or is shutdown, in
119  /// addition to the above
121 
122  /// Logs messages for each time a job is a sent to a service client,
123  /// addition to the above
124  eServiceDebugJob
125  };
126 
127  /**
128  * Enumeration of work item log levels
129  */
131  {
132  /// No work item logging
134 
135  /// Work item status updates for scheduled work items
137 
138  /// Work item status updates for all work items
139  eWorkItemDebugAll
140  };
141 
142  /**
143  * Enumeration of cache debug log levels
144  */
146  {
147  /// No cache logging
149 
150  /// Log cache misses
152 
153  /// Log cache misses + hits
155 
156  /// Log cache misses + hits + cache id changes
158 
159  /// Log cache misses + hits + cache ids + custom handlers
160  eCacheDebugHandler
161  };
162 
163  /**
164  * Enumeration of expression debug log levels
165  */
167  {
168  /// No expression logging
170 
171  /// Log expressions that are marked as time dependent becaused of
172  /// attribute references
174 
175  /// Log all attribute reference evaluations
177  };
178 
179  /**
180  * Emumeration of file trasfer debug log levels
181  */
183  {
184  /// No file transfer debug logging
186 
187  /// Log only failed file transfers
189 
190  /// Log failed and successful file transfers, but skip logging for
191  /// transfers that were cached/not performed
193 
194  /// Log failed, successful, and skipped transfers
196 
197  /// Log all transfer outcomes, as well as custom handler results
198  eTransferDebugHandler
199  };
200 
201 public:
202  /// Returns the current time stamp as a floating point value. This is
203  /// different than calling SYStime() because it's adjusted to be relative
204  /// to the unix epoch, rather than an aribtrary value that isn't cross
205  /// platform. It's also different than just calling time(nullptr) because
206  /// it still includes milliseconds like SYStime().
207  static fpreal currentTime();
208 
209 
210  /// Returns the current verbosity
211  static int verbosity()
212  { return theLogVerbosity; }
213 
214  /// Sets the verbosity
215  static void setVerbosity(int verbosity)
216  {
217  theLogVerbosity = verbosity;
218  theLogHasCustomVerbosity = true;
219  }
220 
221  /// Sets the log level variables from the environment. If custom log
222  /// levels have been set using setLogLevel(..), then this method only
223  /// makes change if force=true. Returns true if the log levels were
224  /// updated, else false.
225  static bool configureFromEnvironment(bool force);
226 
227  /// Enables all logging with the maximum log level for each log type
228  static void enableAll();
229 
230  /// Disables all logging across all log types
231  static void disableAll();
232 
233  /// Writes a typed logged message to stdout, assuming the log level is
234  /// set appropriately
235  template <LogType Type, typename Level, typename... Args>
236  static void debugLog(Level level,
237  const char* fmt,
238  Args&&... args)
239  {
240 
241  if (int(level) > theLogLevels[Type])
242  return;
243 
245  log.format(fmt, std::forward<Args>(args)...);
246 
247  lockedLog(
248  stdout, log.buffer(), currentTime());
249  }
250 
251  /// Returns the log level for the specified log type
252  template <typename Level>
254  {
255  return static_cast<Level>(
256  theLogLevels[type]);
257  }
258 
259  /// Sets the log level for the specified log type
260  template <typename Level>
262  {
263  theLogLevels[type] = int(level);
264  theLogHasCustomLevels = true;
265  }
266 
267  /// Writes a work item output message to stdout
268  static void workItemLog(
269  WorkItemDebug level,
271  const PDG_WorkItem* work_item,
272  const UT_StringHolder& tag,
273  fpreal time_stamp);
274 
275  /// Writes a verbose node output message to stdout
276  static void nodeLog(
277  NodeDebug level,
278  const PDG_Node* node,
279  const UT_StringHolder& tag,
280  const UT_StringHolder& message);
281 
282  /// Writes a verbose scheduler output message to stdout
283  static void schedulerLog(
284  SchedulerDebug level,
285  const PDG_Scheduler* scheduler,
286  const PDG_WorkItem* work_item,
287  const UT_StringHolder& tag,
288  const UT_StringHolder& message);
289 
290  /// Writes a verbose scheduler output message to stdout, including a
291  /// work item ID
292  static void schedulerLog(
293  SchedulerDebug level,
294  const PDG_Scheduler* scheduler,
295  PDG_WorkItemID work_item,
296  const UT_StringHolder& tag,
297  const UT_StringHolder& message);
298 
299  /// Writes a service log message to stdout
300  static void serviceLog(
301  ServiceDebug level,
302  PDG_WorkItemID work_item_id,
303  const UT_StringHolder& service_name,
304  const UT_StringHolder& client_name,
305  const UT_StringHolder& tag);
306 
307  /// Writes a type registration log message to stdout
308  static void typeLog(
310  const UT_StringHolder& message,
311  const UT_StringHolder& tag);
312 
313  /// Writes a generic log message to stdout
314  static void writeLog(
315  const UT_StringHolder& source,
316  const UT_StringHolder& message);
317 
318 private:
319  static void lockedLog(
320  FILE* file,
321  const char* message,
322  time_t time_stamp);
323 private:
324  friend class pdg_UniversalLogWorkItemStatusSource;
325 
326  static const fpreal theStartTime;
327  static const fpreal theSystemStartTime;
328 
329  static int theLogLevels[eLogTypeCount];
330  static int theLogVerbosity;
331  static bool theLogHasCustomLevels;
332  static bool theLogHasCustomVerbosity;
333  static UT_TBBSpinLock theLogLock;
334 };
335 
336 #endif
GLuint GLsizei const GLchar * message
Definition: glcorearb.h:2543
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
Log node status updates, e.g. generated or cooked.
Definition: PDG_LogUtils.h:75
static void setVerbosity(int verbosity)
Sets the verbosity.
Definition: PDG_LogUtils.h:215
Log failed, successful, and skipped transfers.
Definition: PDG_LogUtils.h:195
No expression logging.
Definition: PDG_LogUtils.h:169
#define PDG_API
Definition: PDG_API.h:23
Node status/debug logging.
Definition: PDG_LogUtils.h:45
GLint level
Definition: glcorearb.h:108
SYS_FORCE_INLINE const char * buffer() const
UT_ErrorSeverity
Definition: UT_Error.h:25
Work item status/debug logging.
Definition: PDG_LogUtils.h:54
Log messages for events that occur at the scheduler level.
Definition: PDG_LogUtils.h:96
PDGT_TypeErrorLevel
Error level typedef.
Definition: PDGT_Types.h:13
static void debugLog(Level level, const char *fmt, Args &&...args)
Definition: PDG_LogUtils.h:236
Scheduler status/debug logging.
Definition: PDG_LogUtils.h:48
Type registration errors and warnings.
Definition: PDG_LogUtils.h:60
Log cache misses + hits.
Definition: PDG_LogUtils.h:154
Log node status + errors.
Definition: PDG_LogUtils.h:78
File transer debug logging.
Definition: PDG_LogUtils.h:57
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:803
No work item logging.
Definition: PDG_LogUtils.h:133
GLenum GLenum severity
Definition: glcorearb.h:2539
Cache and handler logging.
Definition: PDG_LogUtils.h:39
Log messages for when a service client is acquired/released.
Definition: PDG_LogUtils.h:112
size_t format(const char *fmt, const Args &...args)
SIM_API const UT_StringHolder force
Log cache misses + hits + cache id changes.
Definition: PDG_LogUtils.h:157
fpreal64 fpreal
Definition: SYS_Types.h:277
static void setLogLevel(LogType type, Level level)
Sets the log level for the specified log type.
Definition: PDG_LogUtils.h:261
No file transfer debug logging.
Definition: PDG_LogUtils.h:185
Log only failed file transfers.
Definition: PDG_LogUtils.h:188
**If you just want to fire and args
Definition: thread.h:609
Log node status + errors + warnings.
Definition: PDG_LogUtils.h:81
static int verbosity()
Returns the current verbosity.
Definition: PDG_LogUtils.h:211
exint PDG_WorkItemID
Type defs for unique work item IDs.
Definition: PDG_Types.h:48
Service client status/debug logging.
Definition: PDG_LogUtils.h:51
OIIO_FORCEINLINE T log(const T &v)
Definition: simd.h:7688
Expression evaluation logging.
Definition: PDG_LogUtils.h:42
type
Definition: core.h:1059
static Level logLevel(LogType type)
Returns the log level for the specified log type.
Definition: PDG_LogUtils.h:253
Log all attribute reference evaluations.
Definition: PDG_LogUtils.h:176
No debug logging.
Definition: PDG_LogUtils.h:72
Work item status updates for scheduled work items.
Definition: PDG_LogUtils.h:136